Join Internal Table for all entries

Hi,
   I have put the LIKP data in the internal table and then use the for all entries statement to join the table with LIPS.  Besides, i specifiy an additional condition to filter empty batch.
But, i found that the empty batch record still exist in the result.  Any idea??
    SELECT *
    FROM LIPS INTO  TABLE I_DELIVERY_INFO
    FOR ALL ENTRIES IN I_DELIVERY
    WHERE
    VBELN = I_DELIVERY-VBELN.
    AND
    CHARG IS NOT NULL.
Regards,
Kit

Hi Kit,
If you are using LIKP and LIPS then you can directly join them since these tables are HEADER & ITEM table.
regd ur query you can use CHARG NE ' '.
Regards
Gopi

Similar Messages

  • Inner join and select for all entries with respect to performance

    Hi Friends,
    I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient? and how? can you explain me in detail ?
    Regards,
    Dinesh

    INNER JOIN->
    The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ec77446011d189700000e8322d00/content.htm
    FOR ALL ENTRIES->
    Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below
    Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
    If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
    If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.
    Not Recommended
    Loop at int_cntry.
    Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    Recommended
    Select * from zfligh appending table int_fligh
    For all entries in int_cntry
    Where cntry = int_cntry-cntry.

  • Inner join and select for all entries with respect to performance in SAP

    Hi Friends,
    I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient?
    Regards,
    Dinesh

    I did some testing a while ago and found that a JOIN is usually a bit more efficient than FOR ALL ENTRIES. This wasn't always the case though, so the best thing to do is to write it both ways and see which is faster.
    Rob

  • Join statement with for all entries

    Hi
    Can I write a Inner join with for all entires of some X itab?
    Thanks
    Kiran

    My Local Kunnr itab structure:
      TYPES: BEGIN OF l_t_kunnr,
              kunnr TYPE kna1-kunnr,
             END   OF l_t_kunnr,
    My normal kunnr tab structure:
    TYPES: BEGIN OF t_kna1,                  " Customer Master data
            kunnr   TYPE kna1-kunnr,
            adrnr   TYPE kna1-adrnr,
            ktokd   TYPE kna1-ktokd,
            loevm   TYPE kna1-loevm,
            cstat   TYPE knkk-crblb,
           END   OF t_kna1,
    My Join Stmt:
          SELECT a~kunnr                         " Customer no
                 a~adrnr                         " Address no
                 a~ktokd                         " Customer type
                 a~loevm                         " deletion key
               FROM kna1 as a inner join knvv as b
               on akunnr eq bkunnr
               INTO TABLE i_kna1
               for all entries in l_i_kunnr[]
              WHERE a~kunnr IN l_i_kunnr
                and b~vkorg in s_vkorg.
    It gives me an error that line structure of my local kunnr itab is incorrect.
    Pl lemme know
    Thanks
    Kiran

  • Joins and use FOR ALL ENTRIES

    Two questions :
    <b>(1) I use join with for all entries: the performance will go down?:</b>
    SELECT t1~MBLNR t1~MJAHR ZEILE BUDAT
    INTO TABLE gt_mseg
    FROM MSEG as T1 INNER JOIN MKPF AS T2
    ON T1~MBLNR = T2~MBLNR and
       T2~MJAHR = T2~MJAHR
    FOR ALL ENTRIES IN gt_coss
    WHERE  T1~MJAHR = gt_coss-GJAHR AND
           T1~AUFNR = gt_coss-aufnr AND
           ( BWART = '261' OR
             BWART = '262' ) AND
           T2~BUDAT IN r_budat.
    <b>(2)  With "For all entries", if itab is too long, performance will go down?. In affirmative case. What  can I do?</b>

    Hi Jose,
    You'll have to make sure your global table gt_coss isn't empty.
    A nasty little habit of the IN statement (for all entries is a kind of IN statement)
    is that when it is empty, the system selekts all records.
    You might know this when u use Select-Options in your statement (like r_budat).
    Also there is an OSS note on he for all entries (531337) problems on i-series database.
    Greetings Fred.

  • Select fom table for all entries where field starts with value

    Hello
    I want to write a select like this
    select * from bsis
    into lt_bsis
    for all entries in lt_itab
    where xblnr like lt_itab-belnr%
    I want to select all the entries from bsis where the field xblnr starts with the values found in lt_itab-belnr.
    for example
    ls_itab-belnr = 5100000028
    bsis-xblnr = 510000002810001
                        510000002810002
                        510000002810003
                        520000002810001
    and i want to select only the entries that start with 5100000028 in this case
    Can anybody help?
    Thanks

    Hi,
    I hope below example code will help you to fix your issue,
    REPORT  ytest.
    TYPES : BEGIN OF ty_typ1,
              val TYPE i,
            END OF ty_typ1.
    TYPES : BEGIN OF ty_typ2,
              val1 TYPE hrobjid,
              val2 TYPE hrobjid,
            END OF ty_typ2.
    DATA : int_typ1 TYPE TABLE OF ty_typ1,
           int_typ2 TYPE TABLE OF ty_typ2,
           wa_typ1  TYPE ty_typ1,
           wa_typ2  TYPE ty_typ2,
           int_1001 TYPE TABLE OF hrp1001,
           wa_1001  TYPE hrp1001.
    REFRESH : int_typ1, int_typ2, int_1001.
    CLEAR : wa_typ1, wa_typ2, wa_1001.
    wa_typ1-val = 500001.
    APPEND wa_typ1 TO int_typ1.
    wa_typ1-val = 500002.
    APPEND wa_typ1 TO int_typ1.
    wa_typ1-val = 500003.
    APPEND wa_typ1 TO int_typ1.
    wa_typ1-val = 500001.
    APPEND wa_typ1 TO int_typ1.
    SORT int_typ1 ASCENDING BY val.
    DELETE ADJACENT DUPLICATES FROM int_typ1 COMPARING val.
    LOOP AT int_typ1 INTO wa_typ1.
      wa_typ2-val1 = ( wa_typ1-val * 100 ) + 1.
      wa_typ2-val2 = wa_typ2-val1 + 98.
      APPEND wa_typ2 TO int_typ2.
      CLEAR : wa_typ1, wa_typ2.
    ENDLOOP.
    SELECT * FROM hrp1001 INTO TABLE int_1001
             FOR ALL ENTRIES IN int_typ2 WHERE
                 plvar EQ '01'          AND
                 otype EQ 'S'           AND
                 sclas EQ 'O'           AND
                 begda LE sy-datum      AND
                 endda GE sy-datum      AND
                 objid GE int_typ2-val1 AND
                 objid LE int_typ2-val2.
    LOOP AT int_1001 INTO wa_1001.
      WRITE : / wa_1001-objid.
    ENDLOOP.
    Thanks & Regards,
    Harish Kumar N

  • Problem in using for all entries

    Hi,
    I am populating one field of an internal table for all entries existing in that internal table.That field is getting populated but rest of the fields changed to its default values. 
    Please check the code
    SELECT amatnr awerk almenge01 almenge02 almenge03 almenge04 almenge05 almenge06 a~lmenge07
           almenge08 aprueflos aart acharg bvcode bvdatum
        INTO CORRESPONDING FIELDS OF TABLE i_out
        FROM qals AS a INNER JOIN qave AS b
               ON aprueflos = bprueflos
        WHERE a~matnr IN s_matnr
          AND a~werk IN s_werk
          AND a~art IN s_art
         AND a~stat33 = 'X'
          AND b~vcodegrp IN s_vcdgrp
          AND b~vcode IN s_vcode
          AND b~vdatum IN s_vdatum.
    I am getting error here i_out is getting populated in teh first select statement
      SELECT mncod
             INTO CORRESPONDING FIELDS OF TABLE i_out
             FROM qmsm
             FOR ALL ENTRIES IN i_out
             WHERE qmnum = i_out-qmnum.

    Try changing your query in the following way....
    SELECT a~matnr a~werk a~lmenge01 a~lmenge02 a~lmenge03 a~lmenge04
    a~lmenge05 a~lmenge06 a~lmenge07
    a~lmenge08 a~prueflos a~art a~charg b~vcode b~vdatum
    <b>c~mncod</b>
    FROM qals AS a INNER JOIN qave AS b
    ON a~prueflos = b~prueflos
    <b>join qmsm as c
    ON a~prueflos = c~qmnum</b>
    INTO CORRESPONDING FIELDS OF TABLE i_out
    WHERE a~matnr IN s_matnr
    AND a~werk IN s_werk
    AND a~art IN s_art
    * AND a~stat33 = 'X'
    AND b~vcodegrp IN s_vcdgrp
    AND b~vcode IN s_vcode
    AND b~vdatum IN s_vdatum.
    with the above you can do the two steps only once .
    you need not to go for for all entries .
    Regards
    vijay

  • Question about statement for all entries

    Hi Abap experts,
    I have a question concerning the ABAP statement for all entries.
    Explanations:
    Let’s say that my source package (Source table) contains 2 types of data:
    -type1
    -type2
    I would like to use the statement select from table into internal table
    For all entries in source package
    But the where statement changes depending on the data type (2 keys when data type is 1 and only 1 key when data type is 2) .
    So that would be:
    Type1:
    Select fields
    From table into internal table
    Where field1 = source_package-field1
    And field2 = source_package-field2.
    Type2:
    Select fields
    From table into internal table
    Where field1 = source_package-field1
    How can I merge them assming that the field od data type is ftype?
    Thanks.
    Amine

    Hi amine,
    i think this is helpful for you.
    there are 2 ways  to use the for all entries...
    1. with header line:  this method is old one. in this method the internal table (ITAB) is automatically create workarea (WA) with same name, this method 1 drawback is there where we can use WA and ITAB confused that's why this is come difficult.
    2. without header line : this is nowadays we can use this method. in this method we create separate ITAb and WA. very clear this method.
    EXAMPLES:
    1.WITH HEADER LINE METHOD:
    PARAMETERS p_kunnr TYPE kna1-kunnr.
    DATA:it_kna1 LIKE kna1 OCCURS 0 WITH HEADER LINE,
          it_adrc LIKE adrc OCCURS 0 WITH HEADER LINE,
          it_adr2 LIKE adr2 OCCURS 0 WITH HEADER LINE,
          it_adr6 LIKE adr6 OCCURS 0 WITH HEADER LINE.
    START-OF-SELECTION.
       SELECT * FROM kna1 INTO TABLE it_kna1
          UP TO 100 ROWS.
       IF NOT it_kna1[] IS INITIAL.
         SELECT * FROM adrc INTO TABLE it_adrc
         FOR ALL ENTRIES IN it_kna1
         WHERE addrnumber = it_kna1-adrnr.
       ENDIF.
       IF NOT it_adrc[] IS INITIAL.
         SELECT * FROM adr2 INTO TABLE it_adr2
         FOR ALL ENTRIES IN it_adrc
         WHERE  addrnumber = it_adrc-addrnumber.
       ENDIF.
       IF NOT it_adr2[] IS INITIAL.
         SELECT * FROM adr6 INTO TABLE it_adr6
         FOR ALL ENTRIES IN it_adr2
         WHERE  addrnumber = it_adr2-addrnumber.
       ENDIF.
       LOOP AT it_kna1.
         READ TABLE it_adrc WITH KEY addrnumber = it_kna1-adrnr.
         IF sy-subrc = 0.
         ENDIF.
         READ TABLE it_adr2 WITH KEY addrnumber = it_kna1-adrnr.
         IF sy-subrc = 0.
         ENDIF.
         READ TABLE it_adr6 WITH KEY addrnumber = it_kna1-adrnr.
         IF sy-subrc = 0.
         ENDIF.
         WRITE : it_kna1-kunnr, it_kna1-name1, it_adrc-city1, it_adrc-street, it_adrc-po_box_reg,
                      it_adr2-telnr_long, it_adr6-smtp_addr.
       ENDLOOP.
    2. WITH OUT HEADER LINE:
    TABLES: KNA1 , ADRC.
    DATA : IT_KNA1 TYPE STANDARD TABLE OF KNA1,
            IT_ADRC TYPE STANDARD TABLE OF ADRC,
            WA_KNA1 TYPE KNA1,
            WA_ADRC TYPE ADRC.
    DATA: BEGIN OF STRTYPE ,
           CUSTMERNO LIKE KNA1-KUNNR,
           FIRSTNAME LIKE KNA1-NAME1,
           LASTNAME  TYPE NAME2,
           CITY TYPE ORT01,
           STATE TYPE REGIO,
           COUNTRY TYPE LAND1,
           ADDRESS LIKE ADRC-ADDRNUMBER,
           END OF STRTYPE.
    DATA : IT_1 LIKE TABLE OF STRTYPE.
    SELECT-OPTIONS  K_kunnr FOR kna1-kunnr NO-EXTENSION.
    SELECT * FROM KNA1 INTO TABLE IT_KNA1 WHERE KUNNR IN K_KUNNR.
    IF NOT IT_KNA1[] IS INITIAL.
    SELECT * FROM ADRC INTO WA_ADRC FOR ALL ENTRIES IN IT_KNA1 WHERE ADDRNUMBER = IT_KNA1-ADRNR.
    ENDSELECT.
    ENDIF.
    LOOP AT IT_KNA1 INTO WA_KNA1.
       READ TABLE IT_ADRC INTO WA_ADRC WITH KEY ADDRNUMBER = WA_KNA1-ADRNR.
       IF SY-SUBRC = 0.
           STRTYPE-ADDRESS = WA_ADRC-ADDRNUMBER.
       ENDIF.
    APPEND  STRTYPE TO IT_1.
       WRITE : / WA_KNA1-KUNNR, WA_KNA1-NAME1, WA_KNA1-NAME2, WA_KNA1-ORT01, WA_KNA1-REGIO, WA_KNA1-LAND1, WA_ADRC-ADDRNUMBER.
    ENDLOOP.
    regards,
    roopa.k

  • For all entries in source package merge

    Hi experts,
    I have one question regarding statement for all entries in source package where …..
    Explanations:
    Let’s say that my source package contains 2 types of data:
    -type1
    -type2
    I would like to use the statement select from table into internal table
    For all entries in source package
    But the where statement changes depending on the data type (2 keys when data type is 1 and only 1 key when data type is 2) .
    So that would be:
    Type1:
    Select fields
    From table into internal table
    Where field1 = source_package-field1
    And field2 = source_package-field2.
    Type2:
    Select fields
    From table into internal table
    Where field1 = source_package-field1
    How can I merge them?
    Thanks.
    Amine

    Hi Amine,
    Didn't try that before but there are some idea for you to reference.
    I assume source_packet have a field which indicate the data type which call source_packet-dtype
    1) Write SQL like this... (Notes: never try that, not sure if it will work)
    Select fields
    From table into internal table
    Where ( source_packet-dtype = 1 and field1 = source_package-field1 and field2 = source_package-field2 )
    OR ( source_packet-dtype = 2 and field1 = source_package-field1 ).
    2) Try to split the source_packet into 2 itab, one contain type 1 and another contain type 2 data and then read with 2 sql and merge with appending key word, but this idea assume the record will be difference
    Select fields
    From table into internal table
    Where field1 = itab_type1-field1
    And field2 = itab_type1-field2.
    Select fields
    From table APPENDING internal table
    Where field1 = itab_type2-field1
    BTW, you may have better luck in the ABAP space.
    Regards
    Bill
    Message was edited by: Chie Bill

  • Populating Empty Fields for Existing Internal Table Using For All Entries

    I have an internal table called itab_extract that populates without any issues in SELECT A and SELECT B below. Trying to avoid looping, I am using select DB table 'for all entries' in itab_extract. I want the empty fields in itab_extract to populate from the values in the database. However, about 200,000 entries are being appended to the table, and, the values that existed for the already populated fields in itab_extract are gone, and the new fields are populated.
    I've played with the syntax and cannot seem to get it to work. My next option is a time consuming loop.
    How should the for all entries syntax look to accomplish filling the empty fields in the itab?   Thank-You
    *read ekko
        select ebeln lifnr aedat bsart from ekko                                                     *SELECT A*
               into  CORRESPONDING FIELDS OF TABLE me->itab_extract
               where aedat in r_aedat.
        select ebeln lifnr aedat BSART from ekko                                                  *SELECT B*
               appending CORRESPONDING FIELDS OF TABLE me->itab_extract
               where aedat in S_DATE2 AND
                     BSART IN S_BSART.
          select ebelp werks matnr                                                                           *SELECT C*
            into CORRESPONDING FIELDS OF TABLE itab_extract
            from ekpo
            FOR ALL ENTRIES IN itab_extract
            where ebeln = itab_extract-ebeln.

    Hi Tom,
               This SQL statement will be time consuming, Do not use a loop.
    There are two options.
    1. Select EKKO and EKPO details based on standard SAP view. (You can type EKKO in se11 view to find the correct view).
        also use one range table populate r_aedat and s_date2 in the same. So you where condition will have r_newrange and   
        s_bsart. Also do not use into corresponding fields, it is not a good idea. It will increase your performance. Maintain the proper 
        sequence (Based on database structure of EKKO and EKPO)
    2. If you are keen to use for all entries, then first select ekko then after your sy-subrc check get the data from EKPO.
    Should be like this.
    select ebeln bsart aedat lifnr from ekko into table gt_ekko where aedat in r_newrange and bsart in s_bsart.
    if sy-subrc eq 0.
    sort gt_ekko by ebeln ascending.
    select ebeln ebelp werks matnr  into table gt_ekpo for all entries in gt_ekko where ebeln eq gt_ekko-ebeln.
    endif.
    Hope it helps,
    Best Regards,
    Tapodipta Khan.

  • How to use dynamic internal table with FOR ALL ENTRIES

    Hello SDNers,
    I am having a dynamic internal table & want to use FOR ALL ENTRIES(FAE) using this dyn. table.
    This works fine for me:
    IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
            SELECT field1 field2
              FROM TABLE ztable
              INTO TABLE itab "Itab is a static table
              FOR ALL ENTRIES IN <lt_tmp>
              WHERE (lv_dynwhere). "lv_dynwhere -> dynamic where clause
          ENDIF.
    SAP documentation says:
    "The logical expression sql_cond of the WHERE condition can be comprised of several logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically. "
    How do we specify the column of the internal table dynamically ? Can we do something like this:
    IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
            SELECT field1 field2
              FROM TABLE
              INTO TABLE itab "Itab is a static table
              FOR ALL ENTRIES IN <lt_tmp>
              WHERE key_field1 = (dynamic token for column1 of <lt_tmp>)
                           key_field2 = (dynamic token for column2 of <lt_tmp>)
          ENDIF.
          ENDIF.
    Let me know if i am not clear about my requirement.
    BR,
    Suhas

    Hello Thomas,
    What i meant was something like this:
    WHERE key_field1 = ('<LT_TMP-COL1>') AND
          key_field2 = ('<LT_TMP-COL2>')
    I am confused by what SAP means with "dynamic representation of internal table columns" in FAE ?
    @Rob: I was referring to SAPNW 7.0 documentation & the phrase (release 6.40 & higher) is missing. Anyways fyi i am on ECC5.0 ABAP release 6.40.
    @Subhankar: This is what Marcin had proposed in For all entries and dynamic table.
    Thanks,
    Suhas
    Edited by: Suhas Saha on Apr 6, 2010 11:53 AM

  • INNER JOIN with FOR ALL ENTRIES IN Performance ?

    I am using following the following <b>Select using Inner join with For All Entries in.</b>
          SELECT kebeln kebelp kvbeln kvbelp
            FROM ekkn AS k INNER JOIN ekbe AS b ON kebeln = bebeln
                                               AND kebelp = bebelp
            INTO TABLE gi_purchase
             FOR ALL ENTRIES
             IN gi_sales
          WHERE k~mandt EQ sy-mandt
            AND k~vbeln EQ gi_sales-vbeln
            AND k~vbelp EQ gi_sales-posnr
            AND b~budat EQ p_date.
    If i am not doing inner join then I will have to do 2 select with for all entries in on ekkn and ekbe tables and then compare them.
    <b>I want to know which one has better performance
    Inner join with for all entries in
                    or
    2 Selects with for all entries in</b>

    the join is almost aways faster:
    <a href="/people/rob.burbank/blog/2007/03/19/joins-vs-for-all-entries--which-performs-better">JOINS vs. FOR ALL ENTRIES - Which Performs Better?</a>
    <a href="http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912">FOR ALL ENTRIES vs DB2 JOIN</a>
    Rob

  • Is "Joins & For all entries" in same SQL Query Possible?

    Hi all Professional,
    Can we use "Inner Joins" and "For All Entries In" in the same SQL Query. if possible then pls clarify this query.
    Here I am using three Transparent Table and fetching data from them.
    SELECT abukrs abelnr ahkont axref2 ashkzg awrbtr agsber azfbdt azterm amwskz asgtxt axref1 agjahr abuzei
               bkunnr bwerks bmenge bmeins bmatnr bkoart
               cbukrs cbelnr cblart cbldat cbudat cxblnr cgjahr cstgrd cstblg cstblg c~xreversal
               INTO CORRESPONDING FIELDS OF TABLE it_bsid FROM ( ( bsid AS a
               INNER JOIN acctit AS b ON abukrs = bbukrs )
               INNER JOIN bkpf AS c ON cbukrs = abukrs
                                   AND cbelnr = abelnr
                                   AND cgjahr = agjahr )
               FOR ALL ENTRIES IN it_bkpf
                  WHERE
                    a~belnr EQ it_bkpf-belnr
                AND a~gjahr EQ it_bkpf-gjahr
                AND a~bukrs EQ it_bkpf-bukrs
                AND a~gsber IN so_bus.
    After executing this query, I'm getting Dump Error.
    Error analysis
        When the program was running, it was established that more
        memory was needed than the operating system is able to provide savely.
        To avoid a system crash, you must prevent this
        situation.
                   Last error logged in SAP kernel
        Component............ "EM"
        Place................ "SAP-Server Development_DVL_01 on host Development (wp
         2)"
        Version.............. 37
        Error code........... 7
        Error text........... "Warning: EM-Memory exhausted: Workprocess gets PRIV "
        Description.......... " "
        System call.......... " "
        Module............... "emxx.c"
        Line................. 1886
    Pls resolve, if anybody knows.
    Thanks
    Devinder

    Hi,
    During testing i notice that splitting into multiple selects does improve performance. But the best performance I achieved using DB Hints instead of splitting the select statements.
    Generally performance of joins together with for all entries is bad.
    However if you will look into SAP note 1662726 you will notice that this issue (bad performance in using join and for all entries together) has been addressed.
    Even though the note is for HANA DB, FM RSDU_CREATE_HINT_FAE can be used independent of DB.
    On HANA DB performance improvement is huge (i achieved 62 seconds using DB Hints compared to 1656 seconds using for all entries). On Oracle DB the same code initially run in 99 seconds with for all entries and with DB Hints in 82 seconds for ~ 1.000.000 records and ~660 seconds compared to 1349 seconds for ~8.000.000 records..
    Sample code from SAP Note below:
    Original statement:
    SELECT COL1 COL2 COL3 COL4 COL5
      FROM TAB1
      INTO CORRESPONDING FIELDS OF TABLE LT_RESULT
      FOR ALL ENTRIES IN LT_SOURCE_TMP
      WHERE COL3 = LT_SOURCE_TMP-COL3
      AND   COL4 = LT_SOURCE_TMP-COL4
      AND   COL5 = LT_SOURCE_TMP-COL5
    Revision:
    DATA: L_T_TABLNM TYPE RSDU_T_TABLNM,
          L_LINES TYPE I,
          L_HINT TYPE RSDU_HINT.
    APPEND 'TAB1' TO L_T_TABLNM.
    L_LINES = LINES( LT_SOURCE_TMP ).
    CALL FUNCTION 'RSDU_CREATE_HINT_FAE'
      EXPORTING
        I_T_TABLNM   = L_T_TABLNM
        I_FAE_FIELDS = 3
        I_FAE_LINES  = L_LINES
        I_EQUI_JOIN  = RS_C_TRUE
      IMPORTING
        E_HINT       = L_HINT
      EXCEPTIONS
        OTHERS       = 0.
    SELECT COL1 COL2 COL3 COL4 COL5
      FROM TAB1
      INTO CORRESPONDING FIELDS OF TABLE LT_RESULT
      FOR ALL ENTRIES IN LT_SOURCE_TMP
      WHERE COL3 = LT_SOURCE_TMP-COL3
      AND   COL4 = LT_SOURCE_TMP-COL4
      AND   COL5 = LT_SOURCE_TMP-COL5
              %_HINTS ADABAS  L_HINT.
    Best regards,
    Octavian

  • Coupling  INNER  JOIN   with   FOR  ALL  ENTRIES  statement

    Hi  All,
         I   am  coupling   INNER  JOIN  with  FOR  ALL  ENTRIES  statement  .....
         Would   you  please  highlight  its  implications ??   Is  it  a  best  practise ? 
         Is  it  advicable  to  use  MULTIPLE   INNER  JOINs  with  a  FOR  ALL  ENTRIES ???
        SORT itab BY matnr.
        IF NOT itab[] IS INITIAL.
          SELECT       epmatnr epebeln ep~ebelp
                       epwerks epmenge ep~netpr
                       ekps_psp_pnr ebbelnr eb~menge
                       INTO TABLE iekpo
                       FROM ekpo AS ep
                       INNER JOIN ekkn AS ek
                       ON  ekebeln = epebeln
                       AND ekebelp = epebelp
                       INNER JOIN ekbe AS eb
                       ON     ebebeln = epebeln
                       AND    ebebelp = epebelp
                       AND    eb~bwart = '101'
                       FOR ALL  ENTRIES IN itab
                       WHERE   ep~matnr = itab-matnr.
          IF sy-subrc EQ 0.
            SORT iekpo BY matnr werks.
            LOOP  AT  itab ASSIGNING  <itab>.
              READ TABLE iekpo WITH KEY matnr = <itab>-matnr
                                        werks = <itab>-werks
                                        BINARY SEARCH.
              IF sy-subrc EQ 0.
                MOVE iekpo-matnr      TO   itab1-matnr.
                MOVE iekpo-ebeln      TO   itab1-ebeln.
                MOVE iekpo-ebelp      TO   itab1-ebelp.
                MOVE iekpo-netpr      TO   itab1-poprice.
                MOVE iekpo-werks      TO   itab1-werks.
                MOVE iekpo-menge      TO   itab1-menge1.
                MOVE iekpo-menge1     TO   itab1-menge2.
                MOVE iekpo-belnr      TO   itab1-belnr.
                MOVE iekpo-ps_psp_pnr TO   itab1-pspel.
                MOVE <itab>-pspel     TO   itab1-tpspel.
                MOVE <itab>-sobkz     TO   itab1-sobkz.
                MOVE <itab>-fo_qty    TO   itab1-fo_qty.
                MOVE <itab>-schgt     TO   itab1-schgt.
                MOVE <itab>-postp     TO   itab1-postp.
                MOVE <itab>-beskz     TO   itab1-beskz.
                pend_qty = iekpo-menge1 - iekpo-menge2.
                MOVE pend_qty         TO   itab1-pending.
                APPEND itab1.
                pend_qty = 0.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
      ENDIF.
    Regards
    Jaman
    Edited by: ABAP Techie on Sep 15, 2008 12:39 PM
    Edited by: ABAP Techie on Sep 15, 2008 12:41 PM

    best practise ... don't know ... it is allowed and o.k.
    If possible you should of coourse to have no FOR ALL ENTRIES at all !
    Joins, there is no general rule, check indexes etc.
    The first SORT, I don't that it help for anything, use it together with the delete adjacent duplicates if you expect duplicates in the driver table.
    o.k., it can help, if there is a loop afterwards and an append inside, because the new table itab1 is then sorted.
    Siegfried

  • For all entries

    I was under the impression that, while getting data from database table 'for all entries' always imporves performance. Since we are not getting whole database table data. I was doing a select statement and I have used for all entries. I have only 20,000 records in the internal table. While selecting data from database table, it took more than one hour and timed out.
    Latter, I hard coded some values and query worked and it just took few minutes.
    So, do we need to avoid for all entries? What the best practice?
    For more details Please check the code:
    Source package has only 20,000 records and while getting data it timed out. So I commented for all entries and hardcoded the values. This time it took only few minutes. Can any one suggest the best practice for handling such things?
        IF SOURCE_PACKAGE[] IS NOT INITIAL.
          SELECT
            CALMONTH
            CALYEAR
            COMPANY
            /BIC/XPROF_CTR
            PCOMPANY
            /BIC/ZPRODASGN
            /BIC/ZSLSRPTCD
            CURKEY_TC
            UNIT
            GL_ACCOUNT
            MATERIAL
            FUNC_AREA
            COSTCENTER
            WBS_ELEMT
            CURKEY_LC
            /BIC/ZTEMPKEY
            QUANTITY
            /BIC/ZAMT_REP
            /BIC/ZSALETYP
          FROM
          /BIC/AZGMROA1400
          INTO TABLE IT_SOURCE_TMP
         FOR ALL ENTRIES IN SOURCE_PACKAGE
          WHERE
                CALMONTH       BETWEEN CMONTH1 AND CMONTH2 AND
                CALYEAR        = CURR_YEAR AND
               COMPANY        = SOURCE_PACKAGE-COMPANY AND
               /BIC/XPROF_CTR = SOURCE_PACKAGE-/BIC/XPROF_CTR AND
               PCOMPANY       = SOURCE_PACKAGE-PCOMPANY AND
               /BIC/ZPRODASGN = SOURCE_PACKAGE-/BIC/ZPRODASGN AND
               /BIC/ZSLSRPTCD = SOURCE_PACKAGE-/BIC/ZSLSRPTCD AND
               CURKEY_TC      = SOURCE_PACKAGE-CURKEY_TC AND
               UNIT           = SOURCE_PACKAGE-UNIT AND
               GL_ACCOUNT     = SOURCE_PACKAGE-GL_ACCOUNT AND
                MATERIAL       = SOURCE_PACKAGE-MATERIAL AND
                /BIC/ZSALETYP  in ('TS', 'CG', 'IS', 'IC',
                                   'TO', 'FG', 'OD', 'SS',
                                   'RD', 'I3', 'D1', 'D2',
                                   'D3', 'MS', 'PF', 'RA') .
               FUNC_AREA      = SOURCE_PACKAGE-FUNC_AREA AND
               COSTCENTER     = SOURCE_PACKAGE-COSTCENTER AND
               WBS_ELEMT      = SOURCE_PACKAGE-WBS_ELEMT AND
               CURKEY_LC      = SOURCE_PACKAGE-CURKEY_LC and
               /BIC/ZACCOUNT       = SOURCE_PACKAGE-/BIC/ZACCOUNT .
        ENDIF.

    Hi,
    if you have a statement like
    SELECT ... FOR ALL ENTRIES IN FAE_itab WHERE f = FAE_itab-f.
    SAP sends it to the database depending how the parameter rsdb/prefer_union_all is set:
    rsdb/prefer_union_all = 0 =>
    SELECT ... WHERE f = FAE_itab[1]-f
              OR    f = FAE_itab[2]-f
              OR    f = FAE_itab[N]-f
    You have some small influence of the number of generated statements in the case of  OR'ed  taht an IN list should be used  by
    rsdb/prefer_in_itab_opt parameter:
    SELECT ... WHERE f IN (itab[1]-f, itab[2]-f, ..., itab[N]-f)
    rsdb/prefer_union_all = 1 =>
    SELECT ... WHERE f = FAE_itab[1]-f
    UNION ALL SELECT ... WHERE f = FAE_itab[2]-f
    UNION ALL SELECT ... WHERE f = FAE_itab[N]-f
    see: Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement
    As you can see that the last setting generates several statements and combine them with a UNION ALL,
    the first setting generates a statement with OR's (or uses IN list) for the entries in FAE_itab.
    I give you a little example here (my parameters are set in a way that the OR's are translated to IN lists; i traced the execution in  ST05)
    Select myid into table t_tabcount from mydbtable
      for all entries in t_table    " 484 entries
        where myid = t_table-myid
        and myid = 72.
    ST05 trace:
    |Transaction SEU_INT|Work process no 0|Proc.type  DIA|Client  200|User     |
    |Duration |Obj. name |Op.    |Recs.|RC    |Statement                                                                                |
    |      640|mydbtable |PREPARE|     |     0|SELECT WHERE "myid" IN ( :A0 , :A1 , :A2 , :A3 , :A4 ) AND "myid" = :A5                                                                                |
    |        2|mydbtable |OPEN   |     |     0|SELECT WHERE "myid" IN ( 1 , 2 , 3 , 4 , 5 ) AND "myid" = 72                                                                                |
    |    2.536|mydbtable |FETCH  |    0|  1403|                                                                                |
    |        3|mydbtable |REOPEN |     |     0|SELECT WHERE "myid" IN ( 6 , 7 , 8 , 9 , 10 ) AND "myid" = 72                                                                                |
    |      118|mydbtable |FETCH  |    0|  1403|                                                                                |
    |        2|mydbtable |REOPEN |     |     0|SELECT WHERE "myid" IN ( 11 , 12 , 13 , 14 , 15 ) AND "myid" = 72                                                                                |
    |        3|mydbtable |REOPEN |     |     0|SELECT WHERE "myid" IN ( 475 , 476 , 477 , 478 , 479 ) AND "myid" = 72                                                                                |
    |       94|mydbtable |FETCH  |    0|  1403|                                                                                |
    |        2|mydbtable |REOPEN |     |     0|SELECT WHERE "myid" IN ( 480 , 481 , 482 , 483 , 484 ) AND "myid" = 72                                                                                |
    You see the IN list contained 5 entries each  , wich made up about 97 statements for all 484 entries.
    From database point of view these settings kill performance when you have a lot of entries and/or
    a lot of columns in your FAE_itab.
    Said that, FAE i.e. can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table like you had)
    If you say now that you completly threw away the FAE table of 20.000 entries it is no wonder
    that it performs better. 20.000 records is not a small number if you create a lot of UNION's or OR's / IN lists  that way!
    Your original statement is a good example for the abuse of a FAE. In the SAP Notes this is the core problem with FAE besides empty FAE tables.
    It's safe to use a FAE_itab table if the expected entries count is small (i.e. << 100).
    What you have to decide is if it's more advantagous to
    retrieve the FAE_tabs data once and executing other statements with the SAME FAE table in the same program to reuse it
    or having additional roundtrips to the database if you don't use FAE tables at all
    Bye
    yk

Maybe you are looking for