Replacing innerjoin with for all entries

hi,
  i have a requirement that i have to improve the performance of report . this the code below.
SELECT  A~VBELN A~BSTNK A~AUDAT A~KUNNR B~MATNR  B~WERKS B~KWMENG
       FROM VBAK AS A INNER JOIN VBAP  AS B ON A~VBELN = B~VBELN
       INTO CORRESPONDING FIELDS OF TABLE ITEKKo WHERE 
B~MATKL IN S_MATKL AND A~AUDAT IN S_BEDAT AND
A~VKORG IN S_VKORG AND A~VTWEG IN S_VTWEG
   AND B~WERKS IN S_WERKS .
LOOP AT ITEKKO.
  SELECT SINGLE MVGR1 MVGR5 FROM MVKE INTO (ITEKKO-MATKL, ITEKKO-MVGR5)  WHERE
MATNR = ITEKKO-MATNR.
  SELECT SINGLE INCO2 FROM VBKD INTO ITEKKO-NAME1 WHERe VBELN = ITEKKO-VBELN.
  SELECT SINGLE LAND1 FROM KNA1 INTO CCODE WHERE
            KUNNR = ITEKKO-KUNNR.
  SELECT SINGLE LANDX50 FROM T005T INTO ITEKKO-CNAME WHERE
            LAND1 = CCODE   AND SPRAS = 'E'.
  MODIFY ITEKKO.
ENDLOOP.
SELECT C~BLDAT D~VBELN D~POSNR D~VGBEL
           D~MATKL D~MFRGR D~LFIMG D~MEINS D~MATNR
       FROM LIKP AS C INNER JOIN LIPS AS D ON C~VBELN = D~VBELN
       INNER JOIN VBAK AS A ON D~VGBEL = A~VBELN
       INTO CORRESPONDING FIELDS OF TABLE IT_LIPS
       WHERE A~AUDAT IN S_BEDAT
       ORDER BY D~VGBEL D~MFRGR.
LOOP AT IT_LIPS.
  SELECT SINGLE MVGR5 FROM MVKE INTO IT_LIPS-MVGR5 WHERE
                                  MATNR = IT_LIPS-MATNR.
  MODIFY IT_LIPS.
ENDLOOP.
it is taking very long time when the loops r executing.
can anybody please help.

Hi,
Check this coding,
TYPES:BEGIN OF Y_TAB,
             BLDAT TYPE LIKP-BLDAT,
             VBELN TYPE LIPS-VBELN,
             POSNR TYPE LIPS-POSNR,
             VGBEL TYPE LIPS-VGBEL,
             MATKL TYPE LIPS-MATKL,
             MFRGR TYPE LIPS-MFRGR,
             LFIMG TYPE LIPS-LFIMG,
             MEINS TYPE LIPS-MEINS,
             MATNR TYPE LIPS-MATNR,
  END OF LS_TAB.
TYPES : BEGIN OF Y_VBAK,
             VBELN TYPE VBAK-VBELN,
END OF Y_VBAK.
TYPES: BEGIN OF Y_LIPS,
            VBELN TYPE LIPS-VBELN,
            POSNR TYPE LIPS-POSNR,
            VGBEL TYPE LIPS-VGBEL,
            MATKL TYPE LIPS-MATKL,
            MFRGR TYPE LIPS-MFRGR,
            LFIMG TYPE LIPS-LFIMG,
            MEINS TYPE LIPS-MEINS,
            MATNR TYPE LIPS-MATNR,
END OF Y_LIPS.
TYPES : BEGIN OF Y_LIKP,
             BLDAT TYPE LIKP-BLDAT,
            VBELN TYPE LIKP-VBELN,
END OF Y_LIKP.
DATA IT_ITAB TYPE TABLE OF LS_TAB.
DATA WA_ITAB TYPE  LS_TAB.
DATA IT_LIPS TYPE TABLE OF Y_LIPS.
DATA WA_LIPS TYPE  Y_LIPS.
DATA IT_LIKP TYPE TABLE OF Y_LIKP.
DATA IT_VBAK TYPE TABLE OF Y_VBAK.
DATA WA_LIKP TYPE  Y_LIKP.
SELECT VBELN FROM VBAK INTO TABLE IT_VBAK WHERE AUDAT IN S_BEDAT.
SELECT VBELN POSNR VGBEL MATKL MFRGR LFIMG MEINS MATNR FROM
                           LIPS INTO TABLE IT_LIPS FOR ALL ENTRIES IN IT_VBAK
                                                            WHERE VGBEL = IT_VBAK-VBELN.
SELECT BLDAT VBELN FROM LIKP INTO TABLE IT_LIKP FOR ALL ENTRIES IN IT_LIPS WHERE VBELN = IT_LIPS-VBELN.
LOOP AT IT_LIKP INTO WA_LIKP.
  READ TABLE IT_LIPS INTO WA_LIPS WITH  KEY VBELN = WA_LIKP-VBELN.
  IF SY-SUBRC EQ 0.
    MOVE-CORRESPONDING WA_LIPS TO WA_ITAB.
    MOVE WA_LIKP-BLDAT TO WA_ITAB-BLDAT.
    APPEND WA_ITAB TO IT_ITAB.
    CLEAR WA_ITAB.
  ENDIF.
ENDLOOP.
SORT  IT_ITAB BY VGBEL MFRGR.
I Hope it will help.

Similar Messages

  • Replacing innerjoins with for all entries

    can any one help me in replacing the below
    innerjoins with for all entries
      SELECT avbeln aposnr amatnr apstyv a~werks
        FROM vbap AS a INNER JOIN marc AS b
                               ON amatnr = bmatnr AND
                                  awerks = bwerks
        INTO TABLE vbap_itab
       WHERE a~vbeln = i_vbeln-vbeln
         AND a~uepos = 0
         AND b~umrsl = 'VBOM'.
    and please tell me which table we need to select first in vbap and marc and why
    Edited by: ram reddy on Apr 30, 2008 9:27 AM

    hi check this one
    data:
           begin of  vbap_itab,
           vbeln  type vbap_-vbeln,
           posnr type vbap_posnr,
           matnr type vbap_matnr,
           pstyv  type vbap_pstvy,
           werks type vbap_werks,        
           end of itab,
           begin of marc_itab,
              matnr type marc-matnr,
              werks type marc-werks,
          end of marc_itab.
    select matnr
              werks
       from marc
       into table marc-itab
    where umrsl = 'VBOM'.
    if marc_itab is initial.
    exit.
    else.
    select vbeln
              posnr
             matnr
             pstvy
             werks
      from vbap
      into  table vbap_itab
    for all entries in marc_itab
    where matnr = marc_itab-matnr
          and    werks = marc_itab-werks
          and  vbeln = i_vbeln-vbeln
          and uepos = 0.
    endif.
    Edited by: ravi kumar on Apr 30, 2008 9:51 AM

  • 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

  • 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

  • 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

  • Group by with for all entries

    Hi,
       SELECT  max( VBELN ) VGBEL VGPOS POSNR FKIMG VRKME NTGEW  MATNR ARKTX  WERKS MVGR3
           FROM VBRP
           INTO TABLE T_INVIT
           FOR ALL ENTRIES IN T_INVHD
           WHERE  VBELN = T_INVHD-VBELN
           AND    SPART = T_INVHD-SPART
           AND    werks IN swerks
           AND    mvgr3 IN smvgr3
           group by  VBELN VGBEL VGPOS POSNR FKIMG VRKME NTGEW  MATNR ARKTX  WERKS MVGR3.
    i want to (max) invoice no against a delivery i.e vgbel but in this query i am getting error that with for all entries only count *  is allowed.
    regards
    Fozia

    Hi Do this way..
    IF NOT T_INVHD[] is initial.
    LOOP AT T_INVHD
    SELECT max( VBELN ) VGBEL VGPOS POSNR FKIMG VRKME NTGEW MATNR ARKTX WERKS MVGR3
    FROM VBRP
    INTO T_INVIT
    WHERE VBELN = T_INVHD-VBELN
    AND SPART = T_INVHD-SPART
    AND werks IN swerks
    AND mvgr3 IN smvgr3
    group by VGBEL VGPOS POSNR FKIMG VRKME NTGEW MATNR ARKTX WERKS MVGR3.
    IF SY-SUBRC = 0.
    APPEND T_INVIT.
    CLEAR T_INVIT
    ENDIF.
    endselect.
    endloop.
    endif.
    EVEN NO EFFECT ON PERFORMANCE
    RGDS
    RAJESH

  • 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.

  • Using aggregate function along with for all entries: sugest alternative

    My requirement:
    For each record in i_vbap for which 'charg' is initial, need to determine batch using the following logic:
    For the material (MATNR) in i_vbap, select the batch (CHARG) which has the largest (MAX) unrestricted inventory quantity (CLABS) from MCHB table.
    How do I implement this logic without using select statement inside a loop as I cannot use MAX ( CLABS ) function along with FOR ALL ENTRIES in a SELECT?
    Suggest an alternative.

    For each record in i_vbap for which 'charg' is initial ,fetch all the existing 'clabs' value.
    [ Remember to include all the key fields in selct ]
    Sort the new table .
    Put a loop,use at end of 'charg' and append to another table. U get ur solution
    I think this should be the most economic way to do so.

  • 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

  • Can DRIVER itab & RESULTANT  itab  be  same with  FOR ALL  ENTRIES ??

    Hi All,
         Can DRIVER itab & RESULTANT  itab  be  same with  FOR ALL  ENTRIES ??
         Whole idea is  to  update one field  of  ITAB  from another table ....
    Regards
    Jaman
    Edited by: ABAP Techie on Sep 11, 2008 8:25 AM

    I found this in the F1-Help for "FOR ALL ENTRIES":
    >"In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO."
    Check however if you can use a proper JOIN select. This will fill your internal table in one operation and is usually faster than a FOR ALL ENTRIES, contrary to some circulating comments here.
    Thomas

  • 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

  • Need to SUM on a  field  with FOR ALL ENTRIES

    Hi All,
       I  need  to  use  something like  this  appearing  below ....but  SUM  is  not  allowed  with  FOR ALL ENTRIES ......Whats   the  efficient  ALTERNATIVE ???
         SELECT  sum( menge )  INTO   TABLE  imseg
                                FROM   mseg
                                FOR ALL ENTRIES IN iresb
                                WHERE  matnr = iresb-matnr
                                  AND  bwart = '281'
                                  AND  aufpl = iresb-aufpl
                                  AND  aplzl = iresb-aplzl.
        Any  help  will  be  rewarded  &  appreciated ...
    Regards
    Jaman

    Hi Karthik,
         Thanx  a   ton....
          How  about   the  below   approach  .....its   allowed  &   working  fine ....also  simplifying  my  work..
              SELECT  matnr  menge  rsnum  rspos
                      INTO  (ws-matnr, ws-menge, ws-rsnum, ws-rspos)
                      FROM   mseg
                      FOR ALL ENTRIES IN iresb
                      WHERE  matnr = iresb-matnr
                        AND  bwart = mvtyp1
                        AND  rsnum = iresb-rsnum
                        AND  rspos = iresb-rspos.
                      imseg2-matnr =  ws-matnr.
                      imseg2-menge =  ws-menge.
                      imseg2-rsnum =  ws-rsnum.
                      imseg2-rspos =  ws-rspos.
                      COLLECT imseg2.
              ENDSELECT.

  • Problem with for all entries

    Hi all,
       When i was trying to use for all entries, i am not able to pull records inside my internal table. Though both of the tables have the common key fields between them(and ofcourse have entries in that). Now what i have analyzed was, the first table is having 7 primary keys and the one i am using for 'for all entries' comes 6th. Does this gives any impact in pulling records inside my internal table?.Else please give me a possible solution for this. The alternate statement(a normal select query with * ) that i had used for this reserved my dialog processor for a while. Which resulted in 'time exceeded' short dump.

    Hi,
    The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
    SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
    <cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
    The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
    You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
    Hope this is useful
    Reema

  • Innerjoin or for all entries

    Hi Friends,
    please suggest me in performance innerjoin is better or for all entries is better to get data from two transparent tables.
    Krishna.

    hi,
    <b>for all entries is the better method.</b>
    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

Maybe you are looking for

  • Error Message "This iPhone cannot be used because..."

    I am trying to use my iPhone with a new laptop. I installed iTunes most recent version and it works fine. When I plug my iPhone in, I get an error message: "This iPhone cannot be used because the Apple Mobile Device service has not been started." I h

  • How can I get a phone number that I dialed a week ago?

    I dialed a number last week and I need to get it back.   How do I do that?

  • Oracle SSHR (Absence Management) Error - ORA-01436: CONNECT BY LOOP

    The following error message is displayed in Absence Review Page while creating a Leave of Absence for some employees, while working propoerly (withpout any error) for other employees, "An Invalid Setup has been detected for the current Transaction Ty

  • Help with Web Services

    hi, am trying to call a web service from a particular WSDL, i need to use JAX-WS 2.0 as part of this assignment am currently working on, but i just cannot put my head around it and where to start,, would i need to just write a client that would call

  • How to restrict over invoicing the quantity than PO quantity.

    Hi, User is able to post invoices with more quantity than the PO line item quantity due to this if first line item is over invoiced user is not able to add second line items to the PO. Can you please advice me,  is there any validation can be built t