Dump with select stmt

Hi All,
Do you see anything wrong with this select stmt, it is giving me short dump.
DATA: BEGIN OF it_output OCCURS 0,
      check TYPE c,
      vbeln LIKE likp-vbeln,
      lfdat LIKE likp-lfdat,
      kunnr LIKE likp-kunnr,
      knkli LIKE likp-knkli,
      netwr LIKE vbak-netwr,
      END OF it_output.
SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
          FROM LIKP
          INNER JOIN VBAK ON LIKPVBELN = VBAKVBELN
          INTO TABLE IT_OUTPUT
          WHERE LIKP~LFDAT IN S_LFDAT
          AND LIKP~KUNNR IN S_KUNNR
          AND LIKP~LIFSK = P_LIFSK.
Thanks
Veni.

Hi
DATA: BEGIN OF it_output OCCURS 0,
One error is here:
<b>*check TYPE c,</b>
vbeln LIKE likp-vbeln,
lfdat LIKE likp-lfdat,
kunnr LIKE likp-kunnr,
knkli LIKE likp-knkli,
netwr LIKE vbak-netwr,
<b>check type c,</b>
END OF it_output.
SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
FROM LIKP
Another error is here
<b>*INNER JOIN VBAK ON LIKPVBELN = VBAKVBELN</b>
INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
INTO TABLE IT_OUTPUT
WHERE LIKP~LFDAT IN S_LFDAT
AND LIKP~KUNNR IN S_KUNNR
AND LIKP~LIFSK = P_LIFSK.
The link between sales order and delivery is in the item data, field is LIPS-VGBEL
Max

Similar Messages

  • Error  with select stmt.

    Hi All,
    I am getting this error , can you please tell me what I am doing wrong with the select stmt.
    SELECT AFKDAT ANETWR B~KZWI1
                         FROM VBRK AS A INNER JOIN VBRP AS B ON
                              AVBELN = BVBELN
                              INTO (IOUT-FKDAT, IOUT-NETWR, IOUT-KZWI1)
                              WHERE B~VBELN = IOUT-VBELV
                              AND   B~POSNR = ISDOC-POSNR.
    Incorrect nesting: Before the statement "ENDIF", the structure          
    introduced by "SELECT" must be concluded by "ENDSELECT". -
    Thanks
    Veni.

    Hi All,
    I tried INTO CORRESPONDING FIELDS OF IOUT
    but with this also same error is comming. I am sending part of code.
    Please help me.
    Thanks
    Veni.
    TABLES: VBAK, VBAP, KNA1, VBRK, VBRP, VBFA.
    DATA: BEGIN OF ISDOC OCCURS 0,
            VBELN LIKE VBAK-VBELN,
            POSNR LIKE VBAP-POSNR,
            KUNNR LIKE VBAK-KUNNR,
            ERDAT LIKE VBAK-ERDAT,
            BSTNK LIKE VBAK-BSTNK,
            MATNR LIKE VBAP-MATNR,
            ARKTX LIKE VBAP-ARKTX.
    DATA: END OF ISDOC.
    DATA: BEGIN OF IOUT OCCURS 0,
            VBELN LIKE VBAK-VBELN,
            POSNR LIKE VBAP-POSNR,
            KUNNR LIKE VBAK-KUNNR,
            NAME1 LIKE KNA1-NAME1,
            ERDAT LIKE VBAK-ERDAT,
            BSTNK LIKE VBAK-BSTNK,       
            MATNR LIKE VBAP-MATNR,
            ARKTX LIKE VBAP-ARKTX,
            VBELV LIKE VBRP-VBELN,
            FKDAT LIKE VBRK-FKDAT,
            NETWR LIKE VBRK-NETWR,
            KZWI1 LIKE VBRP-KZWI1.
    DATA: END OF IOUT.
    FORM getdata.
      SELECT A~VBELN B~POSNR A~KUNNR A~ERDAT A~BSTNK B~MATNR B~ARKTX
             FROM VBAK AS A INNER JOIN VBAP AS B ON A~VBELN = B~VBELN
             INTO TABLE ISDOC
             WHERE A~AUART IN SAUART
             AND A~ERDAT IN SERDAT
             AND A~KUNNR IN SKUNNR.
               SORT ISDOC BY VBELN POSNR.
      LOOP AT ISDOC.
        MOVE-CORRESPONDING ISDOC TO IOUT.
        CLEAR: KNA1.
        SELECT SINGLE * FROM KNA1 WHERE KUNNR = ISDOC-KUNNR.
        IF SY-SUBRC = 0.
          MOVE KNA1-NAME1 TO IOUT-NAME1.
        ENDIF.
        SELECT VBELN INTO IOUT-VBELV FROM VBFA WHERE VBELV = ISDOC-VBELN
                                               AND   POSNV = ISDOC-POSNR
                                               AND   VBTYP_N = 'O'.
          IF SY-SUBRC = 0.
            SELECT A~FKDAT A~NETWR B~KZWI1
                   FROM VBRK AS A INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
                   INTO CORRESPONDING FIELDS OF IOUT
    *               (IOUT-FKDAT, IOUT-NETWR, IOUT-KZWI1)
                         WHERE B~VBELN = IOUT-VBELV
                         AND   B~POSNR = ISDOC-POSNR.
              APPEND IOUT.
              CLEAR IOUT.
            ENDIF.
          ENDLOOP.
        ENDFORM.                    " getdata

  • Dump at select stmt

    the program is dumping at the below stmt.
    *--  Check whether any entry is present in the the table BSIP
      SELECT * INTO LS_BSIP FROM BSIP
              WHERE (LT_SEL_DATA).
    LT_SEL_DATA is declared as
      TYPES : BEGIN OF T_SEL_DATA,
                FIELD(72) TYPE C,
              END   OF T_SEL_DATA.
      DATA : LT_SEL_DATA TYPE STANDARD TABLE OF T_SEL_DATA WITH HEADER LINE.
    . So the dump is because of the no data in LT_SEL_DATA ?
    Shall I put below code to solve the dump ?
    IF NOT LT_SEL_DATA[] IS INITIAL.
      SELECT * INTO LS_BSIP FROM BSIP
              WHERE (LT_SEL_DATA).
    ENDIF .
    Thanks IN ADV

    The below is dump analysis...
    Can any body  also explain how it selects from bsip table id  LT_SEL_DATA is declared as FIELD(72) TYPE C, ?
    SELECT * INTO LS_BSIP FROM BSIP
    WHERE (LT_SEL_DATA).
    ====================================
    Error analysis
    The current ABAP/4 program attempted to execute an ABAP/4 Open SQL
    statement containing a WHERE condition of the form WHERE (itab) or
    WHERE ... AND (itab). The part of the WHERE condition specified at
    runtime in the internal table itab is incorrectly parenthesized.
    How to correct the error
    If the error occurred in a non-modified SAP program, you may be
    able to find a solution in the SAP note system.
    If you have access to the note system yourself, use the following
    search criteria:
    "SAPSQL_WHERE_PARENTHESES"
    "SAPLZADI_F_DUPLICATE_INV_CHECK " or "LZADI_F_DUPLICATE_INV_CHECKU01 "
    "Z_ADI_F_DUPLICATE_INVOICE_CHK"
    If you cannot solve the problem yourself, please send the
    following documents to SAP:
    1. A hard copy print describing the problem.
       To obtain this, select the "Print" function on the current screen.
    Source code extract
    001310              INTO LT_SEL_DATA-FIELD.
    001320       APPEND LT_SEL_DATA.
    001330     ENDIF.
    001340
    001350     CLEAR LT_SEL_DATA.
    001360     CONCATENATE 'AND SHKZG NE '''
    001370                  LV_SHKZG
    001380                  ''''
    001390            INTO LT_SEL_DATA-FIELD.
    001400     APPEND LT_SEL_DATA.
    001410
    001420
    001430     IF I_XBLNR IS INITIAL.
    001440
    001450   *    Include the field for Amount in local currency in the selection
    001460   *    criteria on BSIP table
    001470       LV_WRBTR = I_WRBTR.
    001480       CONDENSE LV_WRBTR.
    001490
    001500       CLEAR LT_SEL_DATA.
    001510       CONCATENATE 'AND WRBTR = '''
    001520                   LV_WRBTR
    001530                   ''''
    001540              INTO LT_SEL_DATA-FIELD.
    001550       APPEND LT_SEL_DATA.
    001560
    001570     ENDIF.
    001580
    001590   *    Check whether any entry is present in the the table BSIP
    001600     SELECT * INTO LS_BSIP FROM BSIP
         >             WHERE (LT_SEL_DATA).
    001620
    001630   *    Check credit memos or not
    001640       CHECK NOT ( I_SHKZG = LC_DB_IND AND LS_BSIP-SHKZG EQ SPACE ).
    001650
    001660   *    Check if BSIP entry refers to the same document or not
    001670       CHECK NOT ( I_BELNR = LS_BSIP-BELNR AND
    001680                   I_BUKRS = LS_BSIP-BUKRS AND
    001690                   I_GJAHR = LS_BSIP-GJAHR ).
    001700
    001710   *    Get the reverse document number for the document selected
    001720       CLEAR LV_STBLG.
    001730       SELECT SINGLE STBLG
    001740         INTO LV_STBLG
    001750         FROM BKPF
    001760        WHERE BELNR = LS_BSIP-BELNR
    001770          AND BUKRS = LS_BSIP-BUKRS
    001780          AND GJAHR = LS_BSIP-GJAHR.
    001790
    001800   *     Only if NO Vendor Invoice reversal has taken place, throw

  • Nested looping with select stmt

    Hi Gurus,
                  I need to create an abap program that takes i/p a database table(dbtable contains list of table names).The expected o/p is a DB table with tablename,co_code,total amt in local curr,amount in doc curr.
    the following is my logic:
    Select * from zmatlist into table it_tablist where zmatlist~tflag like ''.  "condition to get list of table names from DB table
       Loop at it_tablist into wa_tablist.
         Select [distinct]co_code from (wa_tablist-tabname) into table it_cocode.
             Loop at it_cocode into wa_cocode.
                select amount curtype from (wa_tablist-tabname) into table it_amount where co_code = wa_cocode-cocode.
                  loop at it_amount into wa_amount.
                    if curtype eq '00'.
                      sum = sum + wa_amount-amount.
                    else.
                      total = total + wa_amount-amount.
                   endloop.
                  wa_result-tabname = wa_tablist-tabname.
                  wa_result-cocode = wa_cocode-cocode.
                  wa_result-AMTLC = sum.
                  wa_result-AMTDC = total.
                 Append wa_result to it_result.
                 Clear: sum,
                       total.
                 refresh: it_amount.
             endloop.
             refresh it_cocode.
         Endloop.
    when i am executing it,it is not able to recognise amount field.How to refer amount ,cocode here?
    Am i writing it so complex?Is there any easy way to do it.Plz let me know if there is any.
    Thanks,
    Vijay.

    Hi Vijay,
    Welcome to SDN
    Have you tried using field symbols for your requirement.
    regards,
    Atish

  • Use of Select stmts with Update stmts

    Hi,
    I want to execute the following update stmt...
    UPDATE Test1_tab a
    SET a.invpln_seq_no = (SELECT b.seq_no
    FROM Test2_tab b
    WHERE b.contract_id = a.contract_id
    AND b.date_from = a.period_from_date)
    WHERE a.invpln_seq_no != (SELECT b.seq_no
    FROM Test2_tab b
    WHERE b.contract_id = a.contract_id
    AND b.date_from = a.period_from_date)
    Here the problem is I have used 'SELECT b.seq_no FROM Test2_tab b WHERE b.contract_id = a.contract_id AND b.date_from = a.period_from_date' twice, one in the SET clause and the other one in WHERE clause...But it is the same SELECT stmt...So this same Select stmt runs twice when I run the whole update stmt I guess. Is there a way to do the above update, where it runs the SELECT stmt only once...
    Any input is highly appreciated...
    Thanks And Best Regards,
    /Dinesh...

    Then you can use Merge statement instead.
    try this
    merge into test1_tab t1
    using
    (SELECT a.rowid,b.seq_no SEQ_DEST
    FROM test1_tab a,test2_tab b
    WHERE b.contract_id = a.contract_id
    AND  b.date_from = a.period_from_date
    AND a.invpln_seq_no != b.seq_no) t2
    ON (t1.rowid=t2.rowid)
    WHEN MATCHED THEN
    UPDATE SET t1.invpln_seq_no=t2.seq_destor if you are sure that sno is a unique key with out any duplicates and if you are going to perform one time manual update then you can use an undocumented hint /*+ bypass_ujvc */ to do this.
    *DO NOT include this code if you are about to add it in a production procedure or a function
    UPDATE /*+ bypass_ujvc */ (SELECT a.invpln_seq_no SEQ_SRC,b.seq_no SEQ_DEST FROM test1_tab a,test2_tab  b
    WHERE b.contract_id = a.contract_id
    AND  b.date_from = a.period_from_date
    AND a.invpln_seq_no != b.seq_no)
    SET SEQ_SRC = SEQ_DESTRegards,
    Prazy

  • Short Dump with ALV Report

    Hi
    I have one Zreport which gives the result in ALV form.
    After getting the result(1 row with 33 columns) when I tried to export the ALV results to spread sheet using the option : List-> Export-> Spread Sheet OR by click on Excel icon in the display screen,I'm getting the short dump with the description "No more storage space available for extending an internal table" .
    After analysis ,find that dump is raising in the FM : F4_GET_RESULT of Include Program : LSDH3U03.
    Can anyone provide us some clue .
    Thanks & Regards,
    Sreeram

    Hi,
    If the display is in ALV grid format, then you can try another approach to save the data in a spreadsheet.
    - Right-click on any output cell.
    - Select 'Spreadsheet' from the drop down list
    - radio-button 'All available formats'
    - Excel (In existing XXL format)
    Thanks!
    VS.

  • Performance issue with select query and for all entries.

    hi,
    i have a report to be performance tuned.
    the database table has around 20 million entries and 25 fields.
    so, the report fetches the distinct values of two fields using one select query.
    so, the first select query fetches around 150 entries from the table for 2 fields.
    then it applies some logic and eliminates some entries and makes entries around 80-90...
    and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
    in short,
    it accesses the same database table twice.
    so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    is around 80-90 entries too much for using "for all entries"?
    the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    i really cant find the way out...
    please help.

    chinmay kulkarni wrote:Chinmay,
    Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
    It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
    >
    > so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    >
    It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
    > the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    >
    That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database.

  • Getting dump with message  CALL_FUNCTION_GET_NAME_FAILED

    Hi,
    My requirement is to write a report which will be run in background every Monday and the result will be sent to a user as email with excel as attachment.
    I tried it by giving the email in 'Spool list recipient' in SM36. ut since the length of the output is more than 255 chars, so i thought of writing the email code as shown below.
    DATA: l_message_content LIKE soli OCCURS 10 WITH HEADER LINE,
            l_receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
            l_packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
            l_listobject LIKE abaplist OCCURS 10,
            l_compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
            lw_object_hd_change LIKE sood1,
            l_compressed_size LIKE sy-index.
      l_receiver_list-recnam = sy-uname .
      l_receiver_list-esc_des = 'B'.
      APPEND l_receiver_list.
      lw_object_hd_change-objla = sy-langu.
      lw_object_hd_change-objnam = 'Selection'.
      lw_object_hd_change-objsns = 'P'.
    Mail subject
      lw_object_hd_change-objdes = 'KRB SAP Inconsistency Report'.
    Mail body
      APPEND 'Consisteny report between KRB and SAP' TO l_message_content.
      CALL FUNCTION 'TABLE_COMPRESS'
        IMPORTING
          compressed_size = l_compressed_size
        TABLES
          in              = <fs_table>
          out             = l_compressed_attachment.
      DESCRIBE TABLE l_compressed_attachment.
      CLEAR l_packing_list.
      l_packing_list-transf_bin = 'X'.
      l_packing_list-head_start = 0.
      l_packing_list-head_num = 0.
      l_packing_list-body_start = 1.
      l_packing_list-body_num = sy-tfill.
      l_packing_list-objtp = 'ALI'.
      l_packing_list-objnam = 'Selection'.
      l_packing_list-objdes = 'SAP KRB Consistency Report'.
      l_packing_list-objlen = l_compressed_size.
      APPEND l_packing_list.
      CALL FUNCTION 'SO_OBJECT_SEND'
        EXPORTING
          object_hd_change = lw_object_hd_change
          object_type      = 'RAW'
          owner            = sy-uname
        TABLES
          objcont          = l_message_content
          receivers        = l_receiver_list
          packing_list     = l_packing_list
          att_cont         = l_compressed_attachment.
    I am getting the mail which i checked in SBWP but when i clicked on the attachment i am getting  dump with message CALL_FUNCTION_GET_NAME_FAILED.
    Short text
        Error when starting a Remote Function Call.
    What happened?
        "CPIC-CALL: 'ThSAPCMRCV' : cmRc=20 thRc=223#CPIC program connection ended (read
         error) "
        An error occurred when executing a Remote Function Call.
    Error analysis
        An error occurred when executing a Remote Function Call.
        "CPIC-CALL: 'ThSAPCMRCV' : cmRc=20 thRc=223#CPIC program connection ended (read
         error) "
        Status of connection.... "RFC DRV=??? ???"
        Internal error code.... "RFC_IO4"
        Internal error: Invalid RFC handle.
    Trigger Location of Runtime Error
        Program                                 SAPMSSY1
        Include                                 SAPMSSY1
        Row                                     266
        Module type                             (FORM)
        Module Name                             XAB_RUN_DRIVER
    Please help in this.
    <removed by moderator>
    Edited by: Thomas Zloch on Sep 14, 2011 11:57 AM

    Hi,
    Check your RFC Connection Configuration. Also, check the used username & password.
    Reward points if the asnwer is helpful.
    Regards,

  • Reg different kinds of select stmts

    Hi All,
    Hope all are doing gud,
    cud any tell me different kinds of select stmts ????
    regards,
    abc xyz

    hi,
    SELECT
    Basic form
    SELECT result [target] FROM source [where] [GROUP BY fields] [ORDER BY order].
    Effect
    Retrieves an extract and/or a set of data from a database table or view (see Relational database ). SELECT belongs to the OPEN SQL command set.
    Each SELECT command consists of a series of clauses specifying different tasks:
    The SELECT result clause specifies
    whether the result of the selection is a table or a single record,
    which columns the result is meant to have and
    whether the result is allowed to include identical lines.
    The INTO target clause specifies the target area into which the selected data is to be read. If the target area is an internal table, the INTO clause specifies
    whether the selected data is to overwrite the contents of the internal table or
    whether the selected data is to be appended to the contents and
    whether the selected data is to be placed in the internal table all at once or in several packets.
    The INTO clause can also follow the FROM clause.
    You can omit the INTO clause. The system then makes the data available in the table work area (see TABLES ) dbtab . If the SELECT clause includes a "*", the command is processed like the identical SELECT * INTO dbtab FROM dbtab statement. If the SELECT clause contains a list a1 ... an , the command is executed like SELECT a1 ... an INTO CORRESPONDING FIELDS OF dbtab FROM dbtab .
    If the result of the selection is meant to be a table, the data is usually (for further information, see INTO -Klausel ) read line by line within a processing loop introduced by SELECT and concluded by ENDSELECT . For each line read, the processing passes through the loop once. If the result of the selection is meant to be a single record, the closing ENDSELECT is omitted.
    The FROM source clause the source (database table or view ) from which the data is to be selected. It also determines
    the type of client handling,
    the behavior for buffered tables and
    the maximum number of lines to be read.
    The WHERE where clause specifies the conditions which the result of the selection must satisfy. It thus determines the lines of the result table. Normally - i.e. unless a client field is specified in the WHERE clause - only data of the current client is selected. If you want to select across other clients, the FROM clause must include the addition ... CLIENT SPECIFIED .
    The GROUP-BY fields clause combines groups of lines together into single lines. A group is a set of lines which contain the same value for every database field in the GROUP BY clause.
    The ORDER-BY order clause stipulates how the lines of the result table are to be ordered.
    Each time the SELECT statement is executed, the system field SY-DBCNT contains the number of lines read so far. After ENDSELECT , SY-DBCNT contains the total number of lines read.
    The return code value is set as follows:
    SY-SUBRC = 0 At least one line was read.
    SY_SUBRC = 4 No lines were read.
    SY-SUBRC = 8 The search key was not fully qualified.
    (nur bei SELECT SINGLE ). The returned single record is any line of the solution set.
    Example
    Output the passenger list for the Lufthansa flight 0400 on 28.02.1995:
    TABLES SBOOK.
    SELECT * FROM SBOOK
      WHERE
        CARRID   = 'LH '      AND
        CONNID   = '0400'     AND
        FLDATE   = '19950228'
      ORDER BY PRIMARY KEY.
      WRITE: / SBOOK-BOOKID, SBOOK-CUSTOMID,   SBOOK-CUSTTYPE,
               SBOOK-SMOKER, SBOOK-LUGGWEIGHT, SBOOK-WUNIT,
               SBOOK-INVOICE.
    ENDSELECT.
    Performance
    In client/server environments, storing database tables in local buffers (see SAP buffering ) can save considerable amounts of time because the time required to make an access via the network is much more than that needed to access a locally buffered table.
    Notes
    A SELECT command on a table for which SAP buffering is defined in the ABAP/4 Dictionary is normally satisfied from the SAP buffer by bypassing the database. This does not apply with
    - <b>SELECT SINGLE FOR UPDATE
    - SELECT DISTINCT in the SELECT clause ,
    - BYPASSING BUFFER in the FROM clause ,
    - ORDER BY f1 ... fn in the ORDER-BY clause ,
    - aggregate functions in the SELECT clause ,
    - when using IS [NOT] NULL WHERE condition ,</b>
    or if the generic key part is not qualified in the WHERE-Bedingung for a generically buffered table.
    Authorization checks are not supported by the SELECT statement, so you must program these yourself.
    In dialog systems, the database system locking mechanism cannot always guarantee to synchronize the simultaneous access of several users to the same dataset. In many cases, it is therefore advisable to use the SAP locking mechanism .
    Changes to data in a database are only finalized after a database commit (see LUW ). Prior to this, any database update can be reversed by a database rollback (see Programming transactions ). At the lowest isolation level (see the section on the "uncommitted read" under Locking mechanism ), this can result in the dataset selected by the SELECT command not really being written to the database. While a program is selecting data, a second program can add, change or delete lines at the same time. Then, the changes made by the second program are reversed by rolling back the database system. The selection of the first program thus reflects only a very temporary state of the database. If such "phantom data" is not acceptable for a program, you must either use the SAP locking mechanism or at least set the isolation level of the database system to "committed read" (see Locking mechanism ).
    In a SELECT-ENDSELECT loop, the CONTINUE statement terminates the current loop pass prematurely and starts the next.
    If one of the statements in a SELECT ... ENDSELECT loop results in a database commit, the cursor belonging to the SELECT ... ENDSELECT loop is lost and the processing terminates with a runtime error. Since each screen change automatically generates a database commit, statements such as CALL SCREEN , CALL DIALOG , CALL TRANSACTION or MESSAGE are not allowed within a SELECT ... ENDSELECT loop.
    Related OPEN CURSOR , FETCH und CLOSE CURSOR
    SELECT clause
    Variants
    1. <b>SELECT [SINGLE [FOR UPDATE] | DISTINCT] *
    2. SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn
    3. SELECT [SINGLE [FOR UPDATE] | DISTINCT] (itab)</b> Effect
    The result of a SELECT statement is itself a table . The SELECT clause describes which columns this table is supposed to have.
    In addition, you can use the optional addition SINGLE or DISTINCT if you want only certain lines of the solution set to be visible for the calling program:
    SINGLE The result of the selection is a single record . If this record cannot be uniquely identified, the first line of the solution set is selected. The addition FOR UPDATE protects the selected record against parallel changes by other transactions until the next database commit occurs (see LUW and Database locking ). If the database system detects a deadlock, the result is a runtime error.
    DISTINCT Any lines which occur more than once are automatically removed from the selected dataset.
    Note
    To ensure that a record is uniquely determined, you can fully qualify all fields of the primary key by linking them together with AND in the WHERE condition.
    Note
    Performance
    The additions SINGLE FOR UPDATE and DISTINCT exclude the use of SAP buffering .
    The addition DISTINCT requires sorting on the database server and should therefore only be specified if duplicates are likely to occur.
    Variant 1
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] *
    Effect
    In the result set, the columns correspond exactly in terms of order, ABAP/4 Dictionary type and length to the fields of the database table (or view ) specified in the FROM clause .
    Example
    Output all flight connections from Frankfurt to New York:
    TABLES SPFLI.
    SELECT * FROM SPFLI
             WHERE
               CITYFROM = 'FRANKFURT' AND
               CITYTO   = 'NEW YORK'.
      WRITE: / SPFLI-CARRID, SPFLI-CONNID.
    ENDSELECT.
    Example
    Output all free seats on the Lufthansa flight 0400 on 28.02.1995:
    TABLES SFLIGHT.
    DATA   SEATSFREE TYPE I.
    SELECT SINGLE * FROM SFLIGHT
                    WHERE
                      CARRID   = 'LH '      AND
                      CONNID   = '0400'     AND
                      FLDATE   = '19950228'.
    SEATSFREE = SFLIGHT-SEATSMAX - SFLIGHT-SEATSOCC.
    WRITE: / SFLIGHT-CARRID, SFLIGHT-CONNID,
             SFLIGHT-FLDATE, SEATSFREE.
    Variant 2
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn
    Effect
    The order, ABAP/4 Dictionary type and length of the columns of the result set are explicitly defined by the list s1 ... sn . Each si has the form
    ai or ai AS bi .
    Here, ai stands either for
    a field f of the database table or
    a aggregate print.
    bi is an alternative name for the i-th column of the result set.
    When using INTO CORRESPONDING FIELDS OF wa in the INTO clause , you can specify an alternative column name to assign a column of the result set uniquely to a column of the target area.
    An aggregate print uses an aggregate function to group together data from one or all columns of the database table. Aggregate prints consist of three or four components:
    An aggregate function immediately followed by an opening parenthesis DISTINCT (optional) The database field f A closing parenthesis
    All components of a print must be separated by at least one blank.
    The following aggregate functions are available:
    MAX Returns the greatest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    MIN Returns the smallest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    AVG Returns the average value in the column determined by the database field f for the selected lines. AVG can only apply to a numeric field. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    SUM Returns the sum of all values in the column determined by the database field f for the selected lines. SUM can only apply to a numeric field. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    COUNT Returns the number of different values in the column determined by the database field f for the selected lines. Specifying DISTINCT is obligatory here. NULL values are ignored unless all values in a column are NULL values. In this case, the result is 0
    COUNT( * ) Returns the number of selected lines. If the SELECT command contains a GROUP BY clause , it returns the number of lines for each group. The form COUNT(*) is also allowed.
    If ai is a field f , MAX( f ) , MIN( f ) or SUM( f ) , the corresponding column of the result set has the same ABAP/4 Dictionary format as f . With COUNT( f ) or COUNT( * ) , the column has the type INT4 , with AVG( f ) the type FLTP .
    If you specify aggregate functions together with one or more database fields in a SELECT clause, all database fields not used in one of the aggregate functions must be listed in the GROUP-BY clause . Here, the result of the selection is a table.
    If only aggregate functions occur in the SELECT clause, the result of the selection is a single record. Here, the SELECT command is not followed later by an ENDSELECT .
    Notes
    This variant is not available for pooled tables and cluster tables .
    If the SELECT clause contains a database field of type LCHAR or LRAW , you must specify the appropriate length field immediately before.
    Notes
    Performance
    Specifying aggregate functions excludes the use of SAP buffering .
    Since many database systems do not manage the number of table lines and therefore have to retrieve this at some cost, the function COUNT( * ) is not suitable for checking whether a table contains a line or not. To do this, it is best to use SELECT SINGLE f ... for any table field f .
    If you only want to select certain columns of a database table, you are recommended to specify a list of fields in the SELECT clause or to use a View .
    Examples
    Output all flight destinations for Lufthansa flights from Frankfurt:
    TABLES SPFLI.
    DATA   TARGET LIKE SPFLI-CITYTO.
    SELECT DISTINCT CITYTO
           INTO TARGET FROM SPFLI
           WHERE
             CARRID   = 'LH '       AND
             CITYFROM = 'FRANKFURT'.
      WRITE: / TARGET.
    ENDSELECT.
    Output the number of airline carriers which fly to New York:
    TABLES SPFLI.
    DATA   COUNT TYPE I.
    SELECT COUNT( DISTINCT CARRID )
           INTO COUNT FROM SPFLI
           WHERE
             CITYTO = 'NEW YORK'.
    WRITE: / COUNT.
    Output the number of passengers, the total weight and the average weight of luggage for all Lufthansa flights on 28.02.1995:
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Variant 3
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] (itab)
    Effect
    Works like SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn if the internal table itab contains the list s1 ... sn as ABAP/4 source code, and like SELECT [SINGLE [FOR UPDATE] | DISTINCT] * , if itab is empty. The internal table itab can only have one field which must be of type C and cannot be more than 72 characters long. itab must appear in parentheses and there should be no blanks between the parentheses and the table name.
    Note
    With this variant, the same restrictions apply as for SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn .
    Example
    Output all Lufthansa flight routes:
    TABLES: SPFLI.
    DATA:   FTAB(72) OCCURS 5 WITH HEADER LINE.
    REFRESH FTAB.
    FTAB = 'CITYFROM'. APPEND FTAB.
    FTAB = 'CITYTO'.   APPEND FTAB.
    SELECT DISTINCT (FTAB)
           INTO CORRESPONDING FIELDS OF SPFLI
           FROM SPFLI
           WHERE
             CARRID   = 'LH'.
      WRITE: / SPFLI-CITYFROM, SPFLI-CITYTO.
    ENDSELECT.
    check this one:
    http://www.sts.tu-burg.de/teaching/sap_r3/ABAP4/select.htm

  • Select stmt taking long time.

    Hi,
    This select stmt is taking very long time to execute. Can you please guide me to improve it.
    SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
              FROM LIKP
              INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
              INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
              INTO CORRESPONDING FIELDS OF TABLE IT_OUTPUT
              WHERE LIKP~LFDAT IN S_LFDAT
                    AND LIKP~KUNNR IN S_KUNNR
                    AND LIKP~LIFSK = P_LIFSK.
    Thanks
    Veni.

    >> SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
    >> FROM LIKP
    >> INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
    >> INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
    >> INTO CORRESPONDING FIELDS OF TABLE IT_OUTPUT
    >> WHERE LIKP~LFDAT IN S_LFDAT
    >> AND LIKP~KUNNR IN S_KUNNR
    >> AND LIKP~LIFSK = P_LIFSK.
    Based on the select that you have in your post, this is what I see.
    As output, you only need fields from LIKP and only one field from VBAK.
    All your fields on the WHERE clause is on LIKP data.
    You only need LIPS for the Sales document number.
    Can you please make a copy of your program and try this below code?
    It would be interesting to see if the extra vgbel sort would help.
    TYPES:
      BEGIN OF TY_LIKP,
        VBELN TYPE LIKP-VBELN,
        LFDAT TYPE LIKP-LFDAT,
        KUNNR TYPE LIKP-KUNNR,
        KNKLI TYPE LIKP-KNKLI,
        NETWR TYPE VBAK-NETWR,
        VGBEL TYPE LIPS-VGBEL,
      END OF TY_LIKP.
    DATA:
      I_LIKP TYPE STANDARD TABLE OF TY_LIKP
        INITIAL SIZE 0
        WITH HEADER LINE,
      BEGIN OF I_VGBEL OCCURS 0,
        VGBEL TYPE LIPS-VGBEL,
      END OF I_VGBEL,
      BEGIN OF I_VBAK OCCURS 0,
        VBELN TYPE VBAK-VBELN,
        NETWR TYPE VBAK-NETWR,
      END OF I_VBAK.
    FIELD-SYMBOLS:
      <FS_LIKP> TYPE TY_LIKP.
    SELECT LIKP~VBELN LIKP~LFDAT LIKP~KUNNR LIKP~KNKLI LIPS~VGBEL
      INTO CORRESPONDING FIELDS OF TABLE I_LIKP
      FROM LIKP
      JOIN LIPS ON LIPS~VBELN EQ LIKP~VBELN
      WHERE LIKP~LFDAT IN S_LFDAT
      AND   LIKP~KUNNR IN S_KUNNR
      AND   LIKP~LIFSK EQ P_LIFSK.
    IF I_LIKP[] IS NOT INITIAL.
      LOOP AT I_LIKP ASSIGNING <FS_LIKP>.
        CLEAR I_VGBEL.
        I_VGBEL-VGBEL = <FS_LIKP>-VGBEL.
        APPEND I_VGBEL.
      ENDLOOP.
      SORT I_VGBEL.
      DELETE ADJACENT DUPLICATES FROM I_VGBEL.
      IF I_VGBEL[] IS NOT INITIAL.
        SELECT VBELN NETWR INTO TABLE I_VBAK
          FROM VBAK
          FOR ALL ENTRIES IN I_VGBEL
          WHERE VBELN EQ I_VGBEL-VGBEL.
        SORT I_VBAK BY VBELN.
        FREE I_VGBEL.
        LOOP AT I_LIKP ASSIGNING <FS_LIKP>.
            CLEAR I_VBAK.
            READ TABLE I_VBAK WITH KEY VBELN = <FS_LIKP>-VGBEL
                                       BINARY SEARCH.
            IF SY-SUBRC EQ 0.
              <FS_LIKP>-NETWR = I_VBAK-NETWR.
    * Note that you don't need to do the Modify statement here
    * because of the field symbol
            ENDIF.
          ENDIF.
        ENDLOOP.
    * Just ignore I_LIKP-VGBEL from all your reporting needs
      ENDIF.
    ENDIF.

  • Select stmt offset - how can I use select stmt to fetch data.

    kna1-name2 contains store#XXXXXXX where XXXXXXX is a store number.  example : store#3564261.
    I must fetch this.  how can i fetch this ?
    Can I use
    WHERE substr(name2,7,10) CS gt_soldto1-store_no
    or can I use
    WHERE name2+7(10) CS gt_soldto1-store_no
    along with for all entries IN gt_soldto1
    in the below select stmt.
        *SELECT *               
          FROM kna1
          INTO corresponding fields of TABLE gt_kna1
         FOR ALL ENTRIES IN gt_soldto1
          WHERE substr(name2,7,10) as gt_soldto1-store_no
          OR      j_3astcu    = gt_soldto1-store_no
    THANKS IN ADV

    Easiest way would be to create another field in your table gt_soldto1 as NAME2.
    update all entries in gt_SOLD2-NAME2 as  cocatenation of  'store#' + gt_SOLD2-STORE_no
    then use your select statment
    SELECT *
    FROM kna1
    INTO corresponding fields of TABLE gt_kna1
    FOR ALL ENTRIES IN gt_soldto1
    WHERE  NAME2 =   gt_soldto1-name2

  • Issue with Select Options

    Dear Experts,
    I used component wdr_select_options to achieve select options functionality, But it displaying only one field as per my requirement user expecting both low & high fields.
    Can you guide for 5 select options whether i have use t times the component at my component level.
    And also could please guide me how to use select options at code level.
    Thanks & Regards,
    Siva Mandapudi.
    Edited by: SIVAMANDAPUDI on Jul 18, 2011 6:39 PM

    Hi Saravan,
    Please find below details.
    The exception is:
    The exception, which is assigned to class 'CX_SY_REF_IS_INITIAL', was not
    caught in
    procedure "ONACTIONSEARCH_SUPPLIER" "(METHOD)", nor was it propagated by a
    RAISING clause.
    code:
    DATA FOR WORKING WITH SELECT OPTIONS
      data: rt_SUPPLIERNO type ref to data.
      data: rt_SUPPLIERNAME type ref to data.
    field-symbols: <fs_SUPPLIERNO> type table,
                    <fs_SUPPLIERNAME> type table.
      TYPES: BEGIN OF T_SUPPLIERNO,
             SIGN(1),
             OPTION(2),
             LOW TYPE /SAPAPO/LOC,
             HIGH TYPE /SAPAPO/LOC,
            END OF T_SUPPLIERNO.
      TYPES: BEGIN OF T_SUPPLIERNAME,
             SIGN(1),
             OPTION(2),
             LOW TYPE /SAPAPO/LOC_DESCR40,
             HIGH TYPE /SAPAPO/LOC_DESCR40,
            END OF T_SUPPLIERNAME.
      DATA: WA_SUPPLIERNO TYPE T_SUPPLIERNO, IT_SUPPLIERNO TYPE TABLE OF T_SUPPLIERNO,
            WA_SUPPLIERNAME TYPE T_SUPPLIERNAME, IT_SUPPLIERNAME TYPE TABLE OF T_SUPPLIERNAME.
    Retrieve the data from the select option
      rt_SUPPLIERNO = wd_this->m_handler->get_range_table_of_sel_field(
                               i_id = 'ID_SNO' ).
    dump raising when get_range_table_of_sel_field is called.
    Thanks a lot.
    Regards
    Siva Mandapudi.

  • RE: Using BAPI in place of select stmt..

    Hi Experts,
    We alway use Select stmt to fetch the datas and display it, so is there any way to use available BAPI's  to select data and display the resultant output?if so can you given one simple example...

    1. Did you ever re-visited your queries
    Total Questions:  32 (30 unresolved) 
    I will suggest to close them by rewarding/answering with your solutions, if they are solved.
    2. Seeing your queries I dont think, you try to search the forum before posting a query. Start using it from today.
    3. Read rules of engagements before posting queries.
    Now for this one, if you search for BAPIs, their usage and their documentation you can understand this one by yourself.

  • How to improve select stmt performance without going for secondary index

    Hi friends,
    I have a select statement which does not contains key fields(Primary index) in where condition. And I have to improve that select stmt performance without going for the secondary indexes.
    Can you plese suggest the alternative way for this?.
    Thanks in advance,
    Ramesh.

    Hi,
    If , possible create a secondary index opf your own But if you have restriction on this, try to arrange the fields in where clause in the same order as they appear in the very table.
    This will help the performance a bit.
    Another issue, If your table doesn't contain any critical data or data in them are not updated frequently, you may go for Bufferring . it is a good alternate of Indexing with above limitations.
    For details in bufferring , check, and all the sublinks.
    [concept of buffering|http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f244446011d189700000e8322d00/content.htm]
    Regards,
    Anirban

  • OVS - getting dump with the message Subnode/attribute INPUT already exists

    Hi All,
    I am using OVS for the field Shopping cart number.whenever i click on F4 help, icon i am getting the dump with the following message  'Subnode or attribute INPUT already exists ' .. Any idea / clue regarding this dump.please advise me.
    Thanks & Regards,
    Lakshmi.

    Also check this link:-
    Regarding select options
    It also talks about the same problem.

Maybe you are looking for

  • My mac has small gray lines under the screen.

    They're only very visible under certain colors, especially grays and on the sign-in screen. I took a screenshot and they did not appear in the photo, so I took a photo with my phone so you can see what it looks like. The part I took a photo of is the

  • Satellite Pro A10: No sound after upgrade to Win XP Home SP2

    Hi, Just used the recovery discs on my Sat Pro A10, no problem with sound, and then upgraded XP Home to SP2, no sound. From what I have read elsewhere, this is a problem, and there doesn't appear to be an answer. I have spent hours searching for upda

  • Round movie frame but can't get rid of white corners

    I've used a rounded-rectangle as a mask so the corners of the movie are rounded. That works, but the corners (background?) are white still: basically I have a rounded movie playing in a square white box. How can I get the background to be transparent

  • Use Labview 5.0 on Wondows2000

    Hi. I have used your Labview 5.0 on my PC(win95). My question is as follows; is it possible to use this Labview v5.0 on Windows 2000, now ? If not, how to do for that is possible? Please tell me. Thank you.

  • I can't eject DVD

    I edited a project on Final Cut Express. I used iDVD to burn the project. I inserted the DVD into another iMac. The DVD did not start. I did not even get an icon on the desktop. And I cannot eject the DVD. I tried the solutions listed below which I f