For all entries or join

Hi,
please which should be used between for all entries or join????

All abap programers and most of the dba's that support abap programmers are familiar with the abap clause "for all entries". Most of the web pages I visited recently, discuss 3 major drawbacks of the "for all entries" clause:
1. duplicate rows are automatically removed
2. if the itab used in the clause is empty , all the rows in the source table will be selected .
3. performance degradation when using the clause on big tables.
In this post I'd like to shed some light on the third issue. Specifically i'll discuss the use of the "for all entries" clause as a means to join tables in the abap code instead of in db2.
Say for example you have the following abap code:
Select * from mara
For all entries in itab
Where matnr = itab-matnr.
If the actual source of the material list (represented here by itab) is actually another database table, like:
select matnr from mseg
into corresponding fields of table itab
where �.
Then you could have used one sql statement that joins both tables.
Select t1.*
From mara t1, mseg t2
Where t1.matnr = t2.matnr
And T2�..
So what are the drawbacks of using the "for all entires" instead of a join ?
At run time , in order to fulfill the "for all entries " request, the abap engine will generate several sql statements (for detailed information on this refer to note 48230). Regardless of which method the engine uses (union all, "or" or "in" predicates) If the itab is bigger then a few records, the abap engine will break the itab into parts, and rerun an sql statement several times in a loop. This rerun of the same sql statement , each time with different host values, is a source of resource waste because it may lead to re-reading of data pages.
returing to the above example , lets say that our itab contains 500 records and that the abap engine will be forced to run the following sql statement 50 times with a list of 10 values each time.
Select * from mara
Where matnr in ( ...)
Db2 will be able to perform this sql statement cheaply all 50 times, using one of sap standard indexes that contain the matnr column. But in actuality, if you consider the wider picture (all 50 executions of the statement), you will see that some of the data pages, especially the root and middle-tire index pages have been re-read each execution.
Even though db2 has mechanisms like buffer pools and sequential detection to try to minimize the i/o cost of such cases, those mechanisms can only minimize the actual i/o operations , not the cpu cost of re-reading them once they are in memory. Had you coded the join, db2 would have known that you actually need 500 rows from mara, it would have been able to use other access methods, and potentially consume less getpages i/o and cpu.
In other words , when you use the "for all entries " clause instead of coding a join , you are depriving the database of important information needed to select the best access path for your application. Moreover, you are depriving your DBA of the same vital information. When the DBA monitors & tunes the system, he (or she) is less likely to recognize this kind of resource waste. The DBA will see a simple statement that uses an index , he is less likely to realize that this statement is executed in a loop unnecessarily.
In conclusion I suggest to "think twice" before using the "for all entries" clause and to evaluate the use of database views as a means to:
a. simplify sql
b. simplify abap code
c. get around open sql limitations.

Similar Messages

  • Select inside loop into for all entries or joins

    Experts please help in making it into for all entries or joins.
    suppose assume this
    zuser table has 2 fields usage and kunnr.
    in i_table i always have 2 fields.
    type
    number
    type will store user or nonuser
    and number can store customer number or sales order number.
    if the type is user then the numer will be customer number and
    if the type is nonuser then the number will be sales order number.
    and values in this table is like this
    type number
    user 100001210
    nonuser 123200000
    user 124573930
    user 294839039
    user 138393903
    nonuser 382749239
    type always have user or nonuser and corresponding to them we have customer numbers.
    and now based on this we need to fine tune this code.
    parameters :p_usage(20) type char
    LOOP AT i_table.
    IF i_table-type = 'NONUSER'.
    SELECT single kunnr INTO skunnr FROM vbak WHERE
    vbeln = i_table-value.
    ENDIF.
    ENDIF.
    IF i_table-type = 'USER'.
    skunnr = i_table-value.
    ENDIF.
    IF skunnr is not initial.
    SELECT single usage FROM zuser
    INTO v_usage
    WHERE usage = p_usage
    AND kunnr = skunnr.
    IF v_usage IS NOT INITIAL.
    i_export-kunnr = i_table-type.
    i_export-auart = i_table-name.
    i_export-flag = 'X'.
    ELSE.
    i_export-NAME = i_table-type.
    i_export-age = i_table-name.
    i_export-flag = ''.
    ENDIF.
    Append i_export to itab_final.
    ENDIF.
    ENDLOOP.
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on Jul 2, 2009 2:53 PM

    U can have this as a solution to avoid ur loop.
    declare to itabs as below:
    data: i_table_user type standard table of i_table,
            i_table_nonuser type standard table of i_table.
    i_table_user[] = i_table[].
    i_table_nonuser[] = i_table[].
    delete i_table_user where user eq 'NONUSER' .   (BY THIS YOU WILL HAVE ONLY USERS IN THIS ITAB)
    delete i_table_NONuser where user eq 'USER' . (BY THIS YOU WILL HAVE ONLY NONUSERS IN THIS ITAB)
    NOW AVOID LOOP AT ITAB AND WRITE YOUR 2 SELECT STATEMENT BY USING FOR ALL ENTRIES OF
    IF YOU DONT NEED any of THESE ITABS FURTHER , refresh them to improve ur memory and performance.
    HOPE THIS HELPS.
    THANKS
    KIRAN

  • For all entries in join conditions

    Hi All,
                  Can we use for all entries statement in the selection of  joining 4 tables.
    If so, please give me an example.
    Thanks

    Hello,
    U can use it.
    Check this:
    * Get the material classification details
      SELECT A~CUOBJ A~OBJEK A~KLART B~ATINN B~ATZHL B~ATWRT B~ATFLV
             B~ATAWE B~ATFLB B~ATAW1 C~CLINT D~CLASS
        INTO CORRESPONDING FIELDS OF TABLE G_T_OBJECTS
        FROM INOB AS A INNER JOIN AUSP AS B
          ON A~CUOBJ = B~OBJEK AND
             A~KLART = B~KLART
             INNER JOIN KSSK AS C
             ON B~OBJEK = C~OBJEK AND
                B~KLART = C~KLART
             INNER JOIN KLAH AS D
             ON C~CLINT = D~CLINT
         FOR ALL ENTRIES IN L_T_OBJECT
       WHERE A~OBJEK EQ L_T_OBJECT-OBJEK AND
             A~OBTAB EQ 'MARA'  AND
             A~KLART IN S_KLART AND
             B~ADZHL EQ '0000'  AND
             C~LKENZ EQ ' '     AND
             D~CLASS IN S_CLASS.
    If useful reward.
    Vasanth

  • For All Entries is NOT better than INNER JOIN in most cases

    I quote from Siegfried Boes' excellent post here: Will writing an inner join be better or creating a view?
    For all the FOR ALL ENTRIES lovers ... there is no proof for these reappearing recommendation.
    There is nearly nobody who receives forum points, who recommends FOR ALL ENTRIES instead of Joins. What is the reason ???
    It is easier to prove the opposite. A Join is a nested loop inside the database, a FOR ALL ENTRIES is partly outside of the database. FOR ALL ENTRIES works in blocks, joins on totals.
    FOR ALL ENTRIES are not recommded on really large tables, because the chances are too high that
    too many records are transferred.
    People prefer FOR ALL ENTRIES, because JOINs are not so easy to understand. Joins can go wrong, but with a bit of understanding they can be fixed.
    Some Joins are slow and can not be fixed, but then the FOR ALL ENTRIES would be extremely slow.
    There are several kinds of views:
    - projection views, i.e. only one table involved just fields reduced
    - join views, several tables, joins conditions stored in dictionary
    - materialized views, here the joined data are actually stored in the database. Storing and synchronisation has to be done manually.
    Only the last one creates real overhead. It should be the exception.
    Join Views and Joins are nearly identical. The view is better for reuse. The join is better in complicated, becuase if the access goes wrong, it can often be fixed by adding a hint. Hints can not be added to views.
    Abraham Bukit  points out:
    If it is cluster table, (you can't use join). If it is buffered table, I would also say avoid join.
    If they all are transaction table which are not buffered and are not cluster tables.  
    He further supports Siegfried's statement that FAE is easier to undestand than INNER JOINs.
    Thomas Zloch says, regarding buffered tables:
    At least think twice, maybe compare runtimes if in doubt. 
    So, unless someone has some EVIDENCE that FOR ALL ENTRIES is better, I don't think we want to see this discussed further.
    Kind regards
    Matt

    To give food for thought here's an example I  gave in a thread:
    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 influence  of the generated statement type: Instead of OR'ed fields an IN list can be used
    if you have only a single coulmn N to compare:
    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 for the 2nd parameter several statements are generated and combined with a UNION ALL,
    the first setting generates statements with OR's (or uses IN  if possible) 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 .
    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|  |
    | 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.
    For every statment you have a single fetch operation wich means a separate access to the database.
    If you would replace the FAE with a join you would only have one fetch to the database.
    With the example above we can derive these observations:
    1. From database point of view these settings kill performance when you access a big table and/or have a lot of entries or columns in your FAE_itab. Furthermore, you hide information what data you will access
    at all and thus you block the database from creating a more efficient execution plan because it DOESN'T KNOW wich data you will select in the next step. I.e. it may be more efficient to scan the table in one shot instead of having many index accesses - but the database can make this decision only if it can examine ONE statement that has ALL the information of what data to retrieve.
    2. A second impact is that with every statement execution you trigger the allocation of database resources
    wich will contribute to the overhead described above.
    Said that, FAE  can never be a replacement for joining big tables (think of having a table with thousands of records in a FAE table )
    Edited by: kishan P on Nov 2, 2010 2:16 PM - Format Fixed

  • 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 joins  Vs  for all entries

    Hi All,
    Pls let me know
    the differences b/w innerjoins and for all entries,,,,which is the best option and  Y??
    Thanks in Advance,
    Bye

    Hi!
    INNER JOIN is used if we want to retrieve some data from more than one table.
    FOR ALL ENTRIES is used if we want some data from a table based on some conditions of some other table.
    Using several nested INNER JOIN statements can be inefficient and cause time out if the tables become too big in the future."
    In ABAP, these joins are first split by the ABAP processor and then sent to the database, with the increase in DATA in production system, these joins tend to give way if your database keeps growing larger and larger.
    You should rather use "FOR ALL ENTRIES IN" (Tabular conditions), which is a much efficient way as far as performance is concerned.
    Check these links:
    inner joins and for all entries
    inner join and for all entries
    Reward points if it helps.
    Regards
    Sudheer

  • What is the usage of for all entries ?

    What is the Usage of read table  after using for all entries ?
    In the following example what exactly it is doing ?
      Usage of 'for all entries' in Select Statement
    FORM data_retrieval.
      DATA: ld_color(1) TYPE c.
      DATA: BEGIN OF T_VBAP OCCURS 0,
            VBELN  LIKE VBAP-VBELN,
            MATNR  LIKE VBAP-MATNR,
            POSNR  LIKE VBAP-POSNR,
            END OF T_VBAP.
      DATA: BEGIN OF T_VBFA OCCURS 0,
            VBELV  LIKE VBFA-VBELV,
            VBELN  LIKE VBFA-VBELN,
            VBTYP_N  LIKE VBFA-VBTYP_N,
            END OF T_VBFA.
      DATA: BEGIN OF T_VBAK OCCURS 0,
            VBELN  LIKE VBAK-VBELN,
            IHREZ  LIKE VBAK-IHREZ,
            END OF T_VBAK.
      DATA: BEGIN OF T_KNA1 OCCURS 0,
            KUNNR  LIKE KNA1-KUNNR,
            NAME1  LIKE KNA1-NAME1,
            END OF T_KNA1.
       DATA: BEGIN OF T_MAKT OCCURS 0,
            MATNR  LIKE MAKT-MATNR,
            MAKTX  LIKE MAKT-MAKTX,
            END OF T_MAKT.
      SELECT likpvbeln likplifex likpbldat likpwadat likpwadat_ist likpkodat likp~lfart
             likpkunnr likpvstel lipsposnv lipslfimg lipsvrkme lipslgmng lips~meins
             lipswerks lipslgort lipscharg lipsvbelv lipsposnr lipsmatnr
             lipsvbeln LIPSVGBEL LIPSVGPOS vbupkosta vbupwbsta vbupposnr vbup~vbeln
              VBAKIHREZ VBAKVBELN VBAP~VBELN
         INTO CORRESPONDING FIELDS OF TABLE  it_itab
        FROM ( likp
               INNER JOIN lips
               ON  lipsvbeln = likpvbeln
               INNER JOIN vbup
               ON  vbupposnr = lipsposnr
               and VBUPVBELN = LIPSVBELN )
              left outer join VBAK
              on  VBAKVBELN = LIPSVGBEL
              inner join VBAP
              on  VBAPVBELN = VBAKVBELN )
             WHERE likp~vbeln IN so_vbeln
               AND likp~lifex IN so_lifex
               AND likp~lfart IN so_lfart
               AND likp~kunnr IN so_kunnr
               AND likp~vstel IN so_vstel
               AND likp~bldat IN so_bldat
               AND likp~wadat_ist IN so_wadat
               AND vbup~kosta IN so_kosta
               AND vbup~wbsta IN so_wbsta
               AND LIPS~LFIMG NE 0.
      SELECT VBELN IHREZ INTO TABLE T_VBAK
      FROM VBAK
      FOR ALL ENTRIES IN  IT_ITAB
      WHERE VBELN = IT_ITAB-VGBEL.
    APPEND T_VBAK.
    ENDSELECT.
      SELECT VBELN MATNR POSNR INTO TABLE T_VBAP
      FROM VBAP
      FOR ALL ENTRIES IN  IT_ITAB
      WHERE VBELN = IT_ITAB-VGBEL AND
            MATNR = IT_ITAB-MATNR AND
            POSNR = IT_ITAB-VGPOS.
    APPEND T_VBAP.
    ENDSELECT.
      SELECT VBELV VBELN VBTYP_N INTO TABLE T_VBFA
      FROM VBFA
      FOR ALL ENTRIES IN  IT_ITAB
      WHERE VBELV = IT_ITAB-VBELN AND
            VBTYP_N = 'M' .
      SELECT KUNNR NAME1 INTO TABLE T_KNA1
      FROM KNA1
      FOR ALL ENTRIES IN IT_ITAB
      WHERE KUNNR = IT_ITAB-KUNNR.
    APPEND T_KNA1.
    ENDSELECT.
      SELECT MATNR MAKTX INTO TABLE T_MAKT
      FROM MAKT
      FOR ALL ENTRIES IN IT_ITAB
      WHERE MATNR = IT_ITAB-MATNR.
    APPEND T_MAKT.
    ENDSELECT.
    *Populate field with color attributes
      LOOP AT it_itab INTO wa_ITAB.
    Populate color variable with colour properties
    Char 1 = C (This is a color property)
    Char 2 = 3 (Color codes: 1 - 7)
    Char 3 = Intensified on/off ( 1 or 0 )
    Char 4 = Inverse display on/off ( 1 or 0 )
    i.e. wa_ekko-line_color = 'C410'
        REFRESH color.
        colourize 'VBELN' 0. " .
        WA_ITAB-farbe = color[].
        ld_color = ld_color + 1.
    Only 7 colours so need to reset color value
        IF ld_color = 3. "8
          ld_color = 1.
        ENDIF.
        CONCATENATE 'C' ld_color '10' INTO wa_ITAB-line_color.
        WA_ITAB-NAME1 = ''.
        WA_ITAB-MAKTX = ''.
        WA_ITAB-IHREZ = ''.
        WA_ITAB-VBELV = ''.
        READ TABLE T_KNA1 WITH KEY KUNNR = WA_ITAB-KUNNR.
        IF SY-SUBRC = 0.
           WA_ITAB-NAME1 = T_KNA1-NAME1.
        ENDIF.
        READ TABLE T_MAKT WITH KEY MATNR = WA_ITAB-MATNR.
        IF SY-SUBRC = 0.
        WA_ITAB-MAKTX = T_MAKT-MAKTX.
        ENDIF.
        READ TABLE T_VBAK WITH KEY VBELN = WA_ITAB-VGBEL.
        IF SY-SUBRC = 0.
        WA_ITAB-IHREZ = T_VBAK-IHREZ.
        ENDIF.
        READ TABLE T_VBFA WITH KEY VBELV = WA_ITAB-VBELN.
        IF SY-SUBRC = 0.
        WA_ITAB-VBELVA = T_VBFA-VBELN.
        ENDIF.
       READ TABLE T_VBAP WITH KEY VBELN = WA_ITAB-VGBEL
                                  POSNR = WA_ITAB-VGPOS
                                  MATNR = WA_ITAB-MATNR.
       IF SY-SUBRC = 0.
       WA_ITAB-IHREZ = T_VBAK-IHREZ.
       ENDIF.
    wa_ekko-line_color = 'C410'.
        MODIFY it_itab FROM wa_itab.
      ENDLOOP.
    ENDFORM. " data_retrieval

    hi Jyotirmoy,
    The explanation below can give u an idea of wat is going in ur code..
    Use of 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.
    Thankyou,
    Regards.

  • About for all entries

    can u give the information abt the FOR ALL ENTRIES and the conditions.

    HI
    GOOD
    Use of 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.
    GO THROUGH THESE LINKS
    http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ForAllEntries.asp
    CODE
    Code to demonstrate Select FOR ALL ENTRIES command
    The FOR ALL ENTRIES comand only retrieves data which matches  
    entries within a particular internal table.
    TYPES: begin of t_bkpf,
    include structure bkpf.
      bukrs like bkpf-bukrs,
      belnr like bkpf-belnr,
      gjahr like bkpf-gjahr,
      BLDAT like bkpf-BLDAT,
      monat like bkpf-monat,
      budat like bkpf-budat,
      xblnr like bkpf-xblnr,
      awtyp like bkpf-awtyp,
      awkey like bkpf-awkey,
    end of t_bkpf.
    data: it_bkpf type standard table of t_bkpf initial size 0,
          wa_bkpf type t_bkpf.
    TYPES: begin of t_bseg,
    *include structure bseg.
      bukrs     like bseg-bukrs,
      belnr     like bseg-belnr,
      gjahr     like bseg-gjahr,
      buzei     like bseg-buzei,
      mwskz     LIKE bseg-mwskz,         "Tax code
      umsks     LIKE bseg-umsks,         "Special G/L transaction type
      prctr     LIKE bseg-prctr,         "Profit Centre       
      hkont     LIKE bseg-hkont,         "G/L account
      xauto     like bseg-xauto,
      koart     like bseg-koart,
      dmbtr     like bseg-dmbtr,
      mwart     like bseg-mwart,
      hwbas     like bseg-hwbas,
      aufnr     like bseg-aufnr,
      projk     like bseg-projk,
      shkzg     like bseg-shkzg,
      kokrs     like bseg-kokrs,
    end of t_bseg.
    data: it_bseg type standard table of t_bseg initial size 0,
          wa_bseg type t_bseg.
    select bukrs belnr gjahr BLDAT monat budat xblnr awtyp awkey
      up to 100 rows
      from bkpf
      into table it_bkpf.
    if sy-subrc EQ 0.
      select bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
             dmbtr mwart hwbas aufnr projk shkzg kokrs
        from bseg
        into table it_bseg
        FOR ALL ENTRIES in it_bkpf
        where bukrs eq it_bkpf-bukrs and
              belnr eq it_bkpf-belnr and
              gjahr eq it_bkpf-gjahr.
    endif.
    CODE
    You can only use FOR ALL ENTRIES IN ...WHERE ...in a SELECT statement. 
        SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT
        statements that would result if you wrote a separate statement for each line of the internal table replacing the symbol
        itab-f with the corresponding value of component f in the WHERE condition.Duplicates are discarded from the result 
        set. If the internal table itab does not contain any entries, the system treats the statement as though there were 
        no WHERE cond condition, and selects all records (in the current client). 
        for example: 
           SELECT * FROM sflight INTO wa_sflight 
                     FOR ALL ENTRIES IN ftab 
                     WHERE CARRID = ftab-carrid AND 
                      CONNID = ftab-connid AND 
                             fldate = '20010228'. 
        this condition, return all entries of the sflight 
    THANKS
    MRUTYUN

  • Innerjoin & for all entries

    what is innerjoin & for all entries?
    which one is used in which position,explain plzzzzzzzzzzzzzzzzz.
    explain advantages & disadvantages?

    hi,
    follow these links for knowing the difference between For all entries and joins.
    http://www.erpgenie.com/abap/performance.htm#For%20all%20entries
    http://blogs.ittoolbox.com/sap/db2/archives/for-all-entries-vs-db2-join-8912
    1. INNER JOIN
    DBTAB1 <----
    > DBTAB2
    It is used to JOIN two DATABASE tables
    having some COMMON fields.
    To Impove the perfomance of program you can use for all entries instead of your inner join...This is always preferable..But before make a check and make sure that your internal table is not empty.
    2. Whereas
    For All Entries,
    DBTAB1 <----
    > ITAB1
    is not at all related to two DATABASE tables.
    It is related to INTERNAL table.
    3. If we want to fetch data
    from some DBTABLE1
    but we want to fetch
    for only some records
    which are contained in some internal table,
    then we use for alll entries.
    1. simple example of for all entries.
    2. NOTE THAT
    In for all entries,
    it is NOT necessary to use TWO DBTABLES.
    (as against JOIN)
    3. use this program (just copy paste)
    it will fetch data
    from T001
    FOR ONLY TWO COMPANIES (as mentioned in itab)
    FOR ALL ENTRIES is an effective way of doing away with using JOIN on two tables.
    You can check the below code -
    SELECT BUKRS BELNR GJAHR AUGDT
    FROM BSEG
    INTO TABLE I_BSEG
    WHERE BUKRS = ....
    SELECT BUKRS BELNR BLART BLDAT
    FROM BKPF
    INTO TABLE I_BKPF
    FOR ALL ENTRIES IN I_BSEG
    WHERE BUKRS = I_BSEG-BUKRS
    AND BELNR = I_BSEG-BELNR
    AND BLDAT IN SO_BLDAT
    Advantages:
    1) For all entries avoids inner join & so the performance increases.
    2) For specified values in 1 itab, if you to fetch values from other table you can use it.
    3) Use of select stmt in loop is gets avoided, as u can use read statement on the the new itab.
    http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ForAllEntries.asp

  • FOR ALL ENTRIES IN A JOIN

    Hi Guyz,
    My requirement is to get data from 2 tables ..i wrote  select statement  but i wanna know if there is any otherway to do it for better peformance..
    SELECT vbfa~vbeln
               vbfa~vbelv
               vbfa~rfmng
               vbfa~vbtyp_n
               ltap~pquit
               INTO TABLE gt_del
               FROM vbfa
               LEFT OUTER JOIN
               ltap  ON
               vbfavbeln = ltaptanum
               AND vbfalgnum = ltaplgnum
               FOR ALL entries IN gt_ltap
               WHERE  vbelv = gt_data
               AND vbfa~vbeln = gt_ltap-tanum
               AND vbfa~lgnum = gt_ltap-lgnum
               AND vbfa~vbtyp_n = 'Q'.
    gt_data  having delvery numbers from the file.
    plz advise..
    regds

    Hi
    Use FOR ALL ENTRIES
      select lgnum       " Warehouse Number / Warehouse Complex
             lgtyp       " Storage Type
             lgpla       " Storage Bin
             skzua       " Blocking Indicator: For Stock Removals (User)
             skzue       " Blocking indicator: for putaways (user)
             spgru       " Blocking reason
             anzle       " Number of storage units in storage bin
             maxle       " Max number of storage units in storage bin
             btanr       " Transfer order number of last stock transfer
             btaps       " Item in transfer order of last stock transfer
             kzler       " Indicator whether storage bin is empty
             kzvol       " Indicator whether storage bin is full
      from lagp
      into table t_lagp
      where lgnum in s_lgnum.
      if t_lagp[] is not initial.
        select lgnum       " Warehouse Number / Warehouse Complex
               tanum       " Transfer Order Number
               mblnr       " Number of Material Document
          from ltak
          into table t_ltak
          for all entries in t_lagp
          where lgnum eq t_lagp-lgnum.
      endif.
      if t_ltak[] is not initial.
        select lgnum       " Warehouse Number / Warehouse Complex
               tanum       " Transfer Order Number
               tapos       " Transfer order item
               posnr       " Item number of the SD document
               matnr       " Material Number
               werks       " Plant
               charg       " Batch Number
               bestq       " Stock Category in the Warehouse Management
    *System
               maktx       " Material Description
        from ltap
        into table t_ltak
        for all entries in t_ltak
        where lgnum eq t_ltak-lgnum and tanum eq t_ltak-tanum.
      endif.
    Like this we have to filter the entires.
    Thanks & Regards,
    Chandralekha.

  • Join table SUM using for all entries

    Dear All,
                Will anyone pls. tell me what is the problem in this query, it is not working.
        SELECT aufnr SUM( menge )
         INTO CORRESPONDING FIELDS OF TABLE itab_aufnr
         FROM mkpf
         INNER JOIN mseg ON msegmblnr EQ mkpfmblnr AND mkpfmjahr EQ msegmjahr
         FOR ALL ENTRIES IN itab_rework
          WHERE mseg~aufnr = itab_rework-aufnr
          GROUP BY aufnr.
    Regards,
    Moderator message: please search for available information before asking, "it's not working" is not a proper error description.
    Edited by: Thomas Zloch on Dec 6, 2010 9:41 AM

    When I have used it in loop it is taking so much time to execute.
    That depends upon the amount of data you are processing and the set of codes written inside the loop. For sum you have to use collect statement or a SUM statement inside a control break statement.

  • Can a JOIN statement be rewritten using FOR ALL ENTRIES in any case ?

    I had a SELECT statement, like:
        select p~key1 t~col3 t~col4 p~col2 p~col3
          into table itab1
          from ( table1 as p left outer join table2 as t
                  on p~key1 = t~key1 and t~col2 = someValue ).
    Among which, table1 and table2 are fully buffered.
    Code Inspector suggests that this statement should be, e.g., rewritten using FOR ALL ENTRIES.
    Since FOR ALL ENTRIES is only possible for WHERE conditions of the SELECT statement, which means the internal table right after it is not available for the RESULT clause of the SELECT statement, can the above statement be rewritten? If yes, how?
    Thanks!

    hi ,
    select pkey1 tcol3 tcol4 pcol2 p~col3
          into table itab1
          from ( table1 as p left outer join table2 as t
                  on pkey1 = tkey1 and t~col2 = someValue ).
    <i>look below code</i>
    select * from  table2  into table int_tab2 where col2 = someValue.
    select key1 col2 col3  into table  int_tab1
    FOR ALL ENTRIES IN int_tab2
    WHERE key = int_tab2-key1.
    then use read statements for manipulations
    rgds
    Anver

  • Join 3 tables using FOR ALL ENTRIES

    Hi,
    I want to join 3 tables and show their result in a text file delimited by comma.
    ITs a download program.Can someone tell me how to how to join the three table using for all entires instead of inner join.please give step  by step illustration

    Hi,
    Please check below code which downloads records from 3 tables into excel file.
    if you want other file means you can specify other file type in the fm parameter
    REPORT zstemp_qty2_  LINE-SIZE 255 .
    DATA:it_vbak LIKE vbak OCCURS 0 WITH HEADER LINE.
    DATA:v_file1 LIKE rlgrap-filename.
    DATA:v_file2(80) TYPE c.
    DATA:it_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.
    DATA:it_mara LIKE mara OCCURS 0 WITH HEADER LINE.
    START-OF-SELECTION.
      SELECT * FROM vbak INTO TABLE it_vbak UP TO 100 ROWS.
      IF NOT it_vbak[] IS INITIAL.
        SELECT * FROM vbap INTO TABLE it_vbap
        FOR ALL ENTRIES IN it_vbak
        WHERE vbeln = it_vbak-vbeln.
      ENDIF.
      LOOP AT it_vbap.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
             EXPORTING
                  input  = it_vbap-matnr
             IMPORTING
                  output = it_vbap-matnr.
        MODIFY it_vbap TRANSPORTING matnr.CLEAR it_vbap.
      ENDLOOP.
      IF NOT it_vbap[] IS INITIAL.
        SELECT * FROM mara INTO TABLE it_mara
        FOR ALL ENTRIES IN it_vbap
        WHERE matnr = it_vbap-matnr.
      ENDIF.
      CALL FUNCTION 'F4_FILENAME'
       EXPORTING
         program_name        = sy-cprog
         dynpro_number       = sy-dynnr
      FIELD_NAME          = ' '
       IMPORTING
         file_name           = v_file1          .
      v_file2 = v_file1.
      CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
      BIN_FILESIZE                  = ' '
      CODEPAGE                      = ' '
         filename                      = v_file2
         filetype                      = 'WK1'
      MODE                          = ' '
      WK1_N_FORMAT                  = ' '
      WK1_N_SIZE                    = ' '
      WK1_T_FORMAT                  = ' '
      WK1_T_SIZE                    = ' '
         col_select                    = '1'
      COL_SELECTMASK                = ' '
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
        TABLES
          data_tab                      = it_mara
      FIELDNAMES                    =
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_WRITE_ERROR              = 2
      INVALID_FILESIZE              = 3
      INVALID_TYPE                  = 4
      NO_BATCH                      = 5
      UNKNOWN_ERROR                 = 6
      INVALID_TABLE_WIDTH           = 7
      GUI_REFUSE_FILETRANSFER       = 8
      CUSTOMER_ERROR                = 9
      OTHERS                        = 10
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      LOOP AT it_mara.
        WRITE:/ it_mara-matnr.
      ENDLOOP.
    Regds
    Sivaparvathi
    Please reward points if helpful.....

  • Replacing a inner join with for all entries

    Hi Team,
       In a already developed program I am replacing a inner join with select query follow up with for-all-entris and passing the data to final internal table but in both the case the result should be same then only my replacement will be correct. But my no records in both cases differs. This happening because when i am selecting data from first data base table is 32 lines. then I am doing fo-all-entries moving all the duplicate entries then the no records are four. but in final internal table i am looping the first internal table. So in final internal table the no of records are 32. But in inner join query the records are 16.So please let me know how resolve this issue?
    Thanks and REgards
    Deepa

    Hi Thomas,
      Thanks for ur suggestion.
    The solved that in below.
    In select query I did not change anything The way I had written the code was correct.
    I think many of us know how to write that how to make the performance better in that way.
    I made the change when I transfered the to final internal table.
    The original Inner join code:
    select a~field1 a~field2 a~field3 b~field2 b~field3 b~field4
               from dbtab1 as a  inner join dbtab2 as b
              on a~field1 = b~field1 into it_final where
              a~field1 in s_field1. [Field1  in both the table are key field]
    Before code:
    Sort itab1 by key-fields.
    sort itab2 by keyfields.
    loop at itab1 into wa1.
    move: wa1-field1 to wa_final-field1,
               wa1-field2 to wa_final-field2,
               wa1-field3 to wa_final-field3.
    read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
      if sy-subrc = 0.
      move : wa2-field2 to wa_final-field4,
                 wa2-field3 to wa_final-field5,
                 wa2-field4 to wa_final-field6.
    append wa_final to it_final.
    endif.
    Clear : wa1, wa2, wa_final.
    endloop.
    In this case if the one key fieild value is not present there in second internal table but its there in first internal table still it will read that row with 2nd internal values having zeroes. Normally what does not happen in inner join case if the key field value will same in both the case ,then that will fetch only those rows.
    Changed Code
    loop at itab1 into wa1.
    read table itab2 into wa2 witk key field1 = wa1-field1 binary search.
      if sy-subrc = 0.
    move: wa1-field1 to wa_final-field1,
               wa1-field2 to wa_final-field2,
               wa1-field3 to wa_final-field3.
      move : wa2-field2 to wa_final-field4,
                 wa2-field3 to wa_final-field5,
                 wa2-field4 to wa_final-field6.
    append wa_final to it_final.
    endif.
    Clear : wa1, wa2, wa_final.
    endloop.
    In this case the values will read to final internal table if both key field matches.
    With Regards
    Deepa

  • Inner join with for-all entries

    Why is the below inner join-for all entries does not result in expected output ?
    REPORT  ZTST3                                   .
    tables : ztst1,ztst2 .
    * table ztst1 has 4 fields : mandt,ebeln,ebelp,etenr,char4. ; ztst2 has
    * 3 fields : mandt,ebeln,ebelp,matnr
    *Entries in ztst1
    * EBELN       EBELP   ETERN  CHAR4
    * 5000000000  00010    0001    abc
    * 5000000000  00010    0002    cbd
    * 5000000000  00010    0003    efg
    *Entries in ztst2
    * EBELN       EBELP   matnr
    * 5000000000  00010    matabc
    *expected itab after inner join
    * EBELN       EBELP   CHAR4  MAtnr
    * 5000000000  00010   abc    matabc
    * 5000000000  00010   cbd    matabc
    * 5000000000  00010   efg    matabc
    data : begin of itab1 occurs 0,
           ebeln type ebeln,
           ebelp type ebelp,
           end of itab1.
    data : begin of itab occurs 0,
           ebeln type ebeln,
           ebelp type ebelp,
           char4 type char4,
           matnr type matnr,
           end of itab.
    start-of-selection.
    itab1-ebeln = '5000000000'.
    itab1-ebelp = '00010'.
    append itab1.
    select ztst1~ebeln
           ztst1~ebelp
           ztst1~char4
           ztst2~matnr into corresponding fields of table itab
    from ztst1 inner join ztst2
    on ztst1~ebeln = ztst2~ebeln and
       ztst1~ebeln = ztst2~ebelp
    for all entries in itab1
    where
    ztst1~ebeln eq itab1-ebeln and
    ztst1~ebelp eq itab1-ebelp .
    * why does it return no entries;
    break-point.

    For example in the bellow case
    *Entries in ztst1
    EBELN       EBELP   ETERN  CHAR4
    5000000000  00010    0001    abc
    5000000000  00010    0002    cbd
    5000000000  00010    0003    efg
    5000000002  00020    0003    efg
    5000000002  00020    0003    efg
    *Entries in ztst2
    EBELN       EBELP   matnr
    5000000000  00010    matabc
    5000000002  00020    abc
    may it will return you 2 records yes, than I think you have under stand the working of u201Cfor all entriesu201D ?
    And the following case I think it will work fine.
    *Entries in ztst1
    key  EBELN       EBELP   ETERN  CHAR4
    1       5000000000  00010    0001    abc
    2       5000000000  00010    0002    cbd
    3       5000000000  00010    0003    efg
    4       5000000002  00020    0003    efg
    5       5000000002  00020    0003    efg
    *Entries in ztst2
    EBELN       EBELP   matnr
    5000000000  00010    matabc
    5000000002  00020    abc
    select  ztst1~key
    ztst1~ebeln
           ztst1~ebelp
           ztst1~char4
           ztst2~matnr into corresponding fields of table itab
    from ztst1 inner join ztst2
    on ztst1~ebeln = ztst2~ebeln and
       ztst1~ebelp = ztst2~ebelp
    for all entries in itab1
    where
    ztst1~ebeln eq itab1-ebeln and
    ztst1~ebelp eq itab1-ebelp .
    Sorry, I donu2019t have system with me right now and I am sending you with out testing but I am sure that it is working the same way.
    Please Reply if any problem
    Kind Regards,
    Faisal

Maybe you are looking for

  • Error when executing a .irpt page

    Hi, I am getting the below error when executing a .irpt from the workbench. I am on MII 12.2.2 Build (235). 404   Not Found SAP NetWeaver Application Server 7.20 / AS Java 7.30 Error: S:usrsapALXJ10j2eeclusterappssap.comxappsxmiiearservlet_jspXMII oo

  • Two different iOS X in two internal hard disks?

    hi there! i have my original internal hard drive, and a new SSD. can i have my old mac OS X 10.5 system in one hard disk, and 10.6 in the SSD, and swich them with no problem? ...or my machine will become crazy? i need to work using 10.5 for some comp

  • English Fonts appearing wrong in custom PDF reports

    Hie All, I am facing an issue that when we run any custom made report (pdf) in eng language the output is coming some other weired langauge other then english seems to be russian character. My environment is 12.1.3 fresh installed OS: OEL 5.5 please

  • MacBook Pro Retina 2013 connecting to Presonus mixer

    I bought new MacBook Pro 13" late 2013 to use it with my mixer Presonus StudioLive 16.0.2 http://www.presonus.com/products/StudioLive-16.0.2 To connect computer Presonus has firewire S400 400mb/s connection. MacBook has no firewire connection, but ha

  • Help for backups

    Wanting to backup an important catalogue I followed the procedure BUT noticed that all picture names had been changed to some B0000numbers... I desperately want to save the files under the names I had given in order to retrieve them easily ! Would be