The select with for all entries is not working correctly

IF NOT i_ekko_ekpo[] IS INITIAL.
    SELECT ebeln
           ebelp
           zekkn
           vgabe
           bewtp
           menge
           bpmng
           shkzg
           INTO TABLE i_ekbe
           FROM ekbe
           FOR ALL ENTRIES IN i_ekko_ekpo
           WHERE ebeln EQ i_ekko_ekpo-ebeln.
            AND ebelp EQ i_ekko_ekpo-ebelp.
    IF sy-subrc EQ 0.
      SORT i_ekbe.
    ENDIF.
  ENDIF.
I have a PO with 2 line items in i_ekko_ekpo. In EKBE, I have 49 recs for this PO and this select is returning only 13 recs.
I tried by commenting EBELP and still the same result.
Thanks
Kiran
Edited by: kiran dasari on May 22, 2009 9:56 PM

Hi Sudhi, I added these now but still no charm
    SELECT ebeln
           ebelp
           zekkn
           vgabe
           bewtp
           menge
           bpmng
           shkzg
           INTO TABLE i_ekbe
           FROM ekbe
           FOR ALL ENTRIES IN i_ekko_ekpo
           WHERE ebeln EQ i_ekko_ekpo-ebeln
             AND ebelp EQ i_ekko_ekpo-ebelp
             AND zekkn GE '00'
             AND vgabe IN ('1','2').
And as per your note: in the 13 entries, am having duplicate also. This is something weird for me now.
Any more clues.
Thanks
Kiran

Similar Messages

  • Dynamic SELECT with FOR ALL ENTRIES IN: take 2

    Hello Xperts,
    we are now having a bit of new trouble with the following SELECT ... special thanks to Raul and Suhas for their previous contributions.
    FIELD-SYMBOLS:
            <itab1>      TYPE standard table.
      ASSIGN ATTR_T_I->* TO <itab1>.
        select
          FIELD1
          FIELD2
        from DBTAB1
        into CORRESPONDING FIELDS OF table <itab1>
        FOR ALL ENTRIES IN <itab1>
        where
           (condition).
    ATTR_T_I is a static attibute of type table containing 10 records where all records have FIELD1 and FIELD2 empty.
    The select finds in DBTAB1 entries fulfilling the 'condition' for 8 of the above 10 records in ATTR_T_I.
    Hence, after the select 8 of the 10 records in ATTR_T_I have the fields FIELD1 and FIELD2 filled (ie not empty).
    So far so good!
    BUT: the 2 remaining records (i.e. those without entries in DBTAB1 fullfilling 'condition') have been deleted! Why? This is not what we want nor expected.
    Any ideas out there how to fix this?
    Thanx!

    Martin Helmstein wrote:
    > Yes, 'condition' contains all the key fields of DBTAB1.
    Hi Martin,
    It's not the Where condition fields i was talking about. I was referring to the Select fields, you have to SELECT all the keyfields when using FAE. Something like this:
    SELECT key1 key2 ... keyn "all the key fields of the table
    field1 field2 ... fieldn
    FROM table
    INTO CORRESPONDING FIELDS OF it_data
    FOR ALL ENTRIES IN <itab>
    WHERE (condition).
    You can search in the forums for further details. It has been discussed many a times.
    BR,
    Suhas

  • Dynamic SELECT with FOR ALL ENTRIES IN

    Hello Xperts,
    we are having a bit of trouble with the following SELECT
    FIELD-SYMBOLS:
            <itab1>      TYPE standard table.
      ASSIGN ATTR_T_I->* TO <itab1>.
        select
          FIELD1
          FIELD2
        from DBTAB1
        into CORRESPONDING FIELDS OF table <itab1>
        FOR ALL ENTRIES IN <itab1>
        where
          FIELD3     =   <itab1>-FIELD3    and
          FIELD4     =   <itab1>-FIELD4
    ATTR_T_I is a static attibute of type table.
    The syntax check throws the following message:
    The specified type has no structure and therefore no component  called FIELD3.
    Any ideas out there how to solve this issue?
    Thanx!

    Hi Martin,
    Change your code like this and try.
    DATA: itab2 TYPE TABLE OF string.
    FIELD-SYMBOLS:
            <itab1>      TYPE standard table.
      ASSIGN ATTR_T_I->* TO <itab1>.
    APPEND 'FIELD3     =   <itab1>-FIELD3    and' TO itab2.
    APPEND 'FIELD4     =   <itab1>-FIELD4' TO itab2.
        select
          FIELD1
          FIELD2
        from DBTAB1
        into CORRESPONDING FIELDS OF table <itab1>
        FOR ALL ENTRIES IN <itab1>
        where
          (itab2)
    Regards,
    Rahul Muraleedharan.

  • 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

  • Inner Join with For All Entries - 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><b></b>

    An Inner Join with for all entries should be done if you add this....
    IF NOT gi_sales[] IS INITIAL.
    SELECT k~ebeln k~ebelp k~vbeln k~vbelp
    FROM ekkn AS k INNER JOIN ekbe AS b ON k~ebeln = b~ebeln
    AND k~ebelp = b~ebelp
    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.
    ENDIF.
    Also, while you use an index or the complete key for the SELECT, your not going to suffer from lack of performance -;)
    Greetings,
    Blag.

  • Does 'For All Entries in itab' work exactly like 'Join' statement?

    Hi,
    I would like to know that if 'For All Entries in itab' work exactly like 'Join' statement?
    If yes, then when I use 'For All Entries in itab' and a 'Join' statement seperately with the same logical conditions for both, the number of records returned by the two methods are not same. Ideally, they should both return the same number of recs.
    Can somebody help?
    With regards.

    Hi,
    for all entries will not work in the same way unless untill it should satisfy some conditions,
    it has some pre-requisests...
    like in the select clause or in where clause or in both the cluases, there should be entire key..
    then only it will behave like the join statement..
    hope i am clear.
    please revert back if u have any quiries.
    Regards,
    Sunil Kumar Mutyala.

  • What is the use of for all entries in select statement

    what is the use of for all entries in select statement

    hi,
    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.
    *******************************8
    look another example
    what is the use of FOR ALL ENTRIES
    1. INNER JOIN
    DBTAB1 <----
    > DBTAB2
    It is used to JOIN two DATABASE tables
    having some COMMON fields.
    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)
    4
    REPORT abc.
    DATA : BEGIN OF itab OCCURS 0,
    bukrs LIKE t001-bukrs,
    END OF itab.
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    itab-bukrs = '1000'.
    APPEND itab.
    itab-bukrs = '1100'.
    APPEND itab.
    SELECT * FROM t001
    INTO TABLE t001
    FOR ALL ENTRIES IN itab
    WHERE bukrs = itab-bukrs.
    LOOP AT t001.
    WRITE :/ t001-bukrs.
    ENDLOOP.
    Hope this helps!
    Regards,
    Anver
    <i>if hlped pls mark points</i>

  • How does select stmt with for all entries uses Indexes

    Hello all,
    I goes through a number of documents but still confused how does select for all entries uses indexes if fields are not in sequences. i got pretty much the same results if i take like two cases on Hr tables HRP1000 and HRP1001(with for all entries based upon hrp1000). Here is the sequence of index fields on hrp1001 (MANDT, OTYPE, OBJID, PLVAR, RSIGN, RELAT, ISTAT, PRIOX, BEGDA, ENDDA, VARYF, SEQNR). in second case objid field is in sequence as in defined Index but i dont see significant increase in field even though the number of records are around 30000. My question is does it make a differrence to use field sequence (same as in table indexes) in comparison to redundant field sequence (not same as defined in table indexes), secondly how we can ge tto know if table index is used in Select for entries query i tried Explain in ST05 but its not clear if it uses any index at all in hrp1001 read.
    here is the sample code i use to get test results.
    test case 1
    REPORT  zdemo_perf_select.
    DATA: it_hrp1000 TYPE STANDARD TABLE OF hrp1000 WITH HEADER LINE.
    DATA: it_hrp1001 TYPE STANDARD TABLE OF hrp1001 WITH HEADER LINE.
    DATA: it_hrp1007 TYPE STANDARD TABLE OF hrp1007 WITH HEADER LINE.
    DATA: it_pa0000 TYPE STANDARD TABLE OF pa0000 WITH HEADER LINE.
    DATA: it_pa0001 TYPE STANDARD TABLE OF pa0001 WITH HEADER LINE.
    DATA: it_pa0002 TYPE STANDARD TABLE OF pa0002 WITH HEADER LINE.
    DATA: it_pa0105_10 TYPE STANDARD TABLE OF pa0105 WITH HEADER LINE.
    DATA: it_pa0105_20 TYPE STANDARD TABLE OF pa0105 WITH HEADER LINE.
    DATA: t1 TYPE timestampl,
          t2 TYPE timestampl,
          t3 TYPE timestampl 
    SELECT * FROM hrp1000 CLIENT SPECIFIED  INTO TABLE it_hrp1000 bypassing buffer
                WHERE mandt EQ sy-mandt AND
                      plvar EQ '01' AND
                      otype EQ 'S'AND
                      istat EQ '1' AND
                      begda <= sy-datum AND
                      endda >= sy-datum AND
                      langu EQ 'EN'.
    GET TIME STAMP FIELD t1.
    SELECT * FROM hrp1001 CLIENT SPECIFIED INTO TABLE it_hrp1001 bypassing buffer
                FOR ALL ENTRIES IN it_hrp1000
                 WHERE mandt EQ sy-mandt AND
                        otype EQ 'S' AND
    *                    objid EQ it_hrp1000-objid and
                        plvar EQ '01' AND
                        rsign EQ 'B' AND
                        relat EQ '007' AND
                        istat EQ '1' AND
                        begda LT sy-datum AND
                        endda GT sy-datum and
                        sclas EQ 'C' and
                        objid EQ it_hrp1000-objid.
    *                    %_hints mssqlnt 'INDEX(HRP1001~0)'.
    *delete it_hrp1001 where sclas ne 'C'.
    GET TIME STAMP FIELD t2.
    t3 = t1 - t2.
    WRITE: 'Time taken - ', t3.
    test case 2
    REPORT  zdemo_perf_select.
    DATA: it_hrp1000 TYPE STANDARD TABLE OF hrp1000 WITH HEADER LINE.
    DATA: it_hrp1001 TYPE STANDARD TABLE OF hrp1001 WITH HEADER LINE.
    DATA: it_hrp1007 TYPE STANDARD TABLE OF hrp1007 WITH HEADER LINE.
    DATA: it_pa0000 TYPE STANDARD TABLE OF pa0000 WITH HEADER LINE.
    DATA: it_pa0001 TYPE STANDARD TABLE OF pa0001 WITH HEADER LINE.
    DATA: it_pa0002 TYPE STANDARD TABLE OF pa0002 WITH HEADER LINE.
    DATA: it_pa0105_10 TYPE STANDARD TABLE OF pa0105 WITH HEADER LINE.
    DATA: it_pa0105_20 TYPE STANDARD TABLE OF pa0105 WITH HEADER LINE.
    DATA: t1 TYPE timestampl,
          t2 TYPE timestampl,
          t3 TYPE timestampl 
    SELECT * FROM hrp1000 CLIENT SPECIFIED  INTO TABLE it_hrp1000 bypassing buffer
                WHERE mandt EQ sy-mandt AND
                      plvar EQ '01' AND
                      otype EQ 'S'AND
                      istat EQ '1' AND
                      begda <= sy-datum AND
                      endda >= sy-datum AND
                      langu EQ 'EN'.
    GET TIME STAMP FIELD t1.
    SELECT * FROM hrp1001 CLIENT SPECIFIED INTO TABLE it_hrp1001 bypassing buffer
                FOR ALL ENTRIES IN it_hrp1000
                 WHERE mandt EQ sy-mandt AND
                        otype EQ 'S' AND
                        objid EQ it_hrp1000-objid and
                        plvar EQ '01' AND
                        rsign EQ 'B' AND
                        relat EQ '007' AND
                        istat EQ '1' AND
                        begda LT sy-datum AND
                        endda GT sy-datum and
                        sclas EQ 'C'." and
    *                    objid EQ it_hrp1000-objid.
    *                    %_hints mssqlnt 'INDEX(HRP1001~0)'.
    *delete it_hrp1001 where sclas ne 'C'.
    GET TIME STAMP FIELD t2.
    t3 = t1 - t2.
    WRITE: 'Time taken - ', t3.

    Mani wrote:
    Thank you for your answer, its very helpful but i am still nor sure how does parameter rsdb/max_blocking_factor affect records size.
    Hi,
    The blocking affects the size of the statement and the memory structures for returning the result.
    So if your itab has 500 rows and your blocking is 5, the very same statement will be executed 100 times.
    Nothing good or bad about this so far.
    Assume, your average result for an inlist 5 statement is 25 records with an average size of 109 bytes.
    You average result size will be 2725 byte plus overhead which will nearly perfectly fit into two 1500 byte ethernet frames.
    Nothing to do in this case.
    Assume your average result for an inlist 5 statement is 7 records with an average size of 67 bytes.
    You average result size will be ~ 470 byte plus overhead which will only fill 1/3 of a 1500 byte ethernet frame.
    In this case, setting the blocking to 12 ... 15 will give you 66% network transfer performance gain,
    and reduces the number of calls to the DB by 50%, giving additional benefit.
    Now this is an extreme example. The longer the average row length is, the lower will be the average loss in the network.
    You have the same effects in memory structures, but on that layer you are fighting single micro seconds instead of
    hundreds of these, so in real life it is rarely measurable.
    Depending on table-statistics, oracle might decide for short inlists to use a concatanation instead of an inlist.
    This is supposed to be more costy, but I never had a case where I could proove a big difference.
    Values from 5 to 15 for blocking seem to be ok for me. If you have special statements in customer coding,
    it #might# be benefitial to do the mentioned calculations and do some network tracing to see if you can squeeze your
    network efficiency by tuning the blocking.
    If you have jumbo frames enabled, it might be worth to be analyzed as well.
    If you are only on a DB-CI system that is loopback connected to the DB, I doubt there might be a big outcome.
    Hope this helps
    Volker

  • 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

  • Alternative for / Problems with: "For all entries in data_package"

    Hi Guys
    I doing some ABAP in a Start Rotine in BW and would like to do the following:
      select * from /BI0/PMATERIAL into table 0mat
      for all entries in DATA_PACKAGE
      where material = DATA_PACKAGE-/bic/zmaterial.
    But I get the following error:
    E:When using the addition "FOR ALL ENTRIES IN itab", the fields "MATERIAL" and "DATA_PACKAGE-/BIC/ZMATERIAL" must have the same type and length. and length.
    ZMATERIAL:
    - Length: 28
    - Type: CHAR - Character String
    ZMATERIAL:
    - Length: 18
    - Type: CHAR - Character String
    According to the error message "For all entries" cannot be used in this case since the lengths are not identical, but is there an alternative way to do what I would like to do?
    Thanks in advance, kind regards,
    Torben

    Hi
    one thing you can try like this define one variable in other itab of same type
    then loop at the first table and assign it to new field and modify the itab
    then use this field with for all entries
    Regards
    Shiva

  • 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

  • Hi guru's what is the diff between for all entries & joins

    hi guru's what is the diff between for all entries & joins

    Hi Vasu,
    Joins are used to fetch data fast from Database tables:
    Tables are joined with the proper key fields to fetch the data properly.
    If there are no proper key fields between tables don't use Joins;
    Important thing is that don't USE JOINS FOR CLUSTER tableslike BSEG and KONV.
    Only use for Transparenmt tables.
    You can also use joins for the database VIews to fetch the data.
    JOINS
    ... FROM tabref1 [INNER] JOIN tabref2 ON cond
    Effect
    The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
    In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
    Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Inner Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE LIKE SFLIGHT-FLDATE,
    CARRID LIKE SFLIGHT-CARRID,
    CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
    INTO (CARRID, CONNID, DATE)
    FROM SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID
    WHERE FCONNID = PCONNID
    AND P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1 Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
    Left Outer Join
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    1
    e1
    f1
    g1
    h1
    a3
    b3
    c3
    2
    NULL
    NULL
    NULL
    NULL
    NULL
    a4
    b4
    c4
    3
    3
    e2
    f2
    g2
    h2
    |--||||||||--|
    Example
    Output a list of all custimers with their bookings for October 15th, 2001:
    DATA: CUSTOMER TYPE SCUSTOM,
    BOOKING TYPE SBOOK.
    SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
    SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
    INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID)
    FROM SCUSTOM LEFT OUTER JOIN SBOOK
    ON SCUSTOMID = SBOOKCUSTOMID AND
    SBOOK~FLDATE = '20011015'
    ORDER BY SCUSTOMNAME SBOOKFLDATE.
    WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
    BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
    BOOKING-BOOKID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
    Note
    For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
    Only a table or view may come after the JOIN operator, not another join statement.
    The only logical operator allowed in the ON condition is AND.
    Each comparison in the ON condition must contain a field from the right-hand table.
    Comparisons in the WHERE condition must not contain a field from the right-hand table.
    The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
    Note
    In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
    Example
    Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
    DATA: BEGIN OF WA,
    FLIGHT TYPE SFLIGHT,
    PFLI TYPE SPFLI,
    CARR TYPE SCARR,
    END OF WA.
    SELECT * INTO WA
    FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
    ON FCARRID = PCARRID AND
    FCONNID = PCONNID )
    INNER JOIN SCARR AS C
    ON FCARRID = CCARRID
    WHERE P~CITYFROM = 'FRANKFURT'
    AND P~CITYTO = 'NEW YORK'
    AND F~FLDATE BETWEEN '20010910' AND '20010920'
    AND FSEATSOCC < FSEATSMAX.
    WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
    WA-FLIGHT-CONNID.
    ENDSELECT.
    And for all entries,
    this will help u.
    use of FOR ALL ENTRIES:
    1. INNER JOIN
    DBTAB1 <----
    > DBTAB2
    It is used to JOIN two DATABASE tables
    having some COMMON fields.
    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)
    4
    REPORT abc.
    DATA : BEGIN OF itab OCCURS 0,
    bukrs LIKE t001-bukrs,
    END OF itab.
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    itab-bukrs = '1000'.
    APPEND itab.
    itab-bukrs = '1100'.
    APPEND itab.
    SELECT * FROM t001
    INTO TABLE t001
    FOR ALL ENTRIES IN itab
    WHERE bukrs = itab-bukrs.
    LOOP AT t001.
    WRITE :/ t001-bukrs.
    ENDLOOP.
    cheers,
    Hema.

  • Can we use inner joins with for all entries?

    Hi,
        Can we use innerjoin on two tables MARA and MAKT against the materials in
        the  internal table.
        If so ,please let me know whether there is performance issue.Because if there is
        bad performance issue or something else like thise means,my project manager
        wont allow to include.
        So can one let me know about this.
    Thanks,
    Balaji

    Hi Arunkumar,
                               I think you are not clear.My question is can I use innerjoin with
    for all entries.For example below is my code.
    SELECT A~MATNR
             B~MAKTX
             A~MTART
             A~MATKL
             FROM MARA AS A INNER JOIN MAKT AS B
             ON AMATNR = BMATNR
             INTO TABLE IT_MARA_MAKT
             FOR ALL ENTRIES IN IT_MATNR
             WHERE A~MATNR = IT_MATNR-MATNR
             AND   A~EXTWG = P_EXTWG
             AND   A~SPART = P_SPART.
    Can we use like this for all entries along with innerjoins.
    Thanks,
    Balaji

  • 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

Maybe you are looking for

  • SONY HC1 CANNOT CAPTURE WITH FCP 6.0

    HELP PLEASE!! This problem is driving me mental. I have a Sony HDR HC1. I've been shooting in DV PAL 4:3 before and had no problems at all. It's well past time when i should be shooting in HDV 16:9. I have changed the settings on the video camera to

  • Tiny font in Yahoo games...  please help, I'm baffled

    I am running Snow Leopard and until a couple of days ago, I played lots of cards in Yahoo games.   Then I went to play cards and the font in the games lobby was unreadably small.   This only occurs in this specific situation... in all other applicati

  • Jobs in Oracle Server 8.0.5

    Hi! I have an Oracle server 8.0.5 installed in WIndows NT 4 (SP 6). And I submitted a Job, but when the right time comes, this job is not executed. who installed oracle server wasn't me, so i don't know much confguration details. in other test i have

  • Built in Bridge on TC endpoints

    Hey, I am just new to the video side of things and I am trying to find out what TC endpoints have the 4 party built in bridge.  Is there a document that can show me this? Thanks, Cameron

  • Lecture message redondant sur un port serie rs232

    Bonjour, J'ai un système qui m'envoie un message sur le port série toutes les secondes. Donc je viens lire le port série toutes les secondes et j'enregistre les messages dans un fichier texte. Quand je dépouille le fichier je m'aperçois que des fois