Inner join Vs For all entries

Hi Expert,
Could you please help me in this inner join , Inner join is performance wise is not good so i want to replace instated of inner join for all entries. But when i am checking  records of internal table there is difference. in inner join i am getting 11 records but for all entries i am getting  5 records .
Please help me out where excatly i have done mistake.
SELECT maralvorm maramatkl
        maramatnr marameins
        maraprdha maraspart
        marcausss marcbearz
        marcbeskz marcbstmi
        marc~wzeit                                       
        marcdisgr marcmaabc                             *         marcdismm marcdispo
        marcdispr marcdzeit
        marcplifz marcdisls
        marcbstma marcbstrf
        marc~basmg                                    
        marceisbe marcfevor
        marcfxhor marclvorm
        marcmatnr marcmmsta
        marcprctr marcsobsl
        marctranz marcwerks
        marc~xchar                                        
        marclgpro marcfhori
        marc~rgekz                                      
        mbewbklas mbewbwkey
        mbewlbkum mbewsalk3
        mbewmatnr mbewpeinh
        mbewstprs maktmaktx
        maktmatnr cepcabtei
        cepc~prctr
        marcschgt marcminbe
        marc~ekgrp
        marc~eprio                              
        marc~kausf                                        
        marc~shflg                                      
        marc~shzet                                       
        marc~fabkz
        marc~lgrad
        marc~shpro
        marc~eislo
        marc~rwpro
        marc~lgfsb
        marczzfdwe marczzfdwi                
        marczzsspe marczzsspi              
INTO TABLE i_matl
FROM ( mara
      INNER JOIN marc
      ON marcmatnr = maramatnr
      INNER JOIN mbew
      ON mbewmatnr = marcmatnr
      AND mbewbwkey = marcwerks
      INNER JOIN makt
      ON maktmatnr = maramatnr
      INNER JOIN cepc
      ON cepcprctr = marcprctr
      AND cepcdatbi >= sy-datum )               "*       WHERE maralvorm IN sp$00094
        AND mara~matkl IN sp$00084
        AND mara~meins IN sp$00091
        AND mara~prdha IN sp$00066
        AND mara~spart IN sp$00085
        AND marc~disgr IN sp$00089
        AND marc~dismm IN sp$00067
        AND marc~dispo IN sp$00061
        AND marc~dispr IN sp$00083
        AND marc~fevor IN sp$00090
        AND marc~lvorm IN sp$00092
        AND marc~mmsta IN sp$00086
        AND marc~beskz IN s_beskz
        AND marc~sobsl IN sp$00068
        AND marc~werks IN sp$00062
        AND marc~xchar IN sp$00093
        AND marc~maabc IN sp$00099                        
        AND marc~lgrad IN s_lgrad
        AND marc~lgpro IN s_lgpro
        AND marc~rwpro IN s_rwpro               
        AND marc~lgfsb IN s_lgfsb
         AND marc~schgt INs_schgt                          *         AND marc~shflg IN s_shflg
        AND marc~shzet IN s_shzet                
        AND marc~fabkz IN s_fabkz                    
        AND marc~shpro IN s_shpro                
        AND marc~eislo IN s_eislo               
        AND marc~zzfdwe IN s_zzfdwe                          
        AND marc~zzfdwi IN s_zzfdwi              
        AND marc~zzsspe IN s_zzsspe
        AND marc~zzsspi IN s_zzsspi
        AND mbew~bklas IN sp$00063
        AND mbew~lbkum IN sp$00088
        AND makt~maktx IN sp$00059
        AND makt~spras = c_en
        AND makt~matnr IN sp$00060
        AND cepc~prctr IN sp$00087.
I am using for all entries
fetching data from  marc data base table
  SELECT matnr werks lvorm  xchar mmsta
      maabc  ekgrp dispr dismm
      dispo plifz ausss disls
      beskz sobsl minbe eisbe
      bstmi bstma bstrf fhori
      rgekz fevor bearz tranz
      basmg dzeit wzeit lgrad
      prctr fxhor lgpro disgr
      kausf rwpro lgfsb schgt
      eprio shflg shzet fabkz
      shpro eislo zzfdwe zzfdwi
      zzsspe zzsspi
      FROM marc  INTO  TABLE i_marc
      WHERE  werks IN sp$00062
          AND lvorm IN sp$00092
          AND xchar IN sp$00093
          AND mmsta IN sp$00086
          AND maabc IN sp$00099
          AND dispr IN sp$00083
          AND dismm IN sp$00067
          AND dispo IN sp$00061
          AND beskz IN s_beskz
          AND sobsl IN sp$00068
          AND fevor IN sp$00090
          AND lgrad IN s_lgrad
          AND lgpro IN s_lgpro
          AND disgr IN sp$00089
          AND rwpro IN s_rwpro
          AND lgfsb IN s_lgfsb
          AND schgt IN s_schgt
          AND shflg IN s_shflg
          AND shzet IN s_shzet                
          AND fabkz IN s_fabkz                    
          AND shpro IN s_shpro                
          AND eislo IN s_eislo               
          AND zzfdwe IN s_zzfdwe                          
          AND zzfdwi IN s_zzfdwi              
          AND zzsspe IN s_zzsspe
          AND zzsspi IN s_zzsspi.
  IF sy-subrc EQ 0.
    SORT i_marc BY matnr werks.
  ENDIF.
DELETE ADJACENT DUPLICATES FROM i_marc comparing matnr werks.
*fetching data from mara data base table
  IF  NOT i_marc[] IS  INITIAL.
    SELECT matnr lvorm  matkl
           meins spart prdha
        FROM mara INTO TABLE i_mara
        FOR ALL ENTRIES IN i_marc
         WHERE matnr = i_marc-matnr
         AND   lvorm IN sp$00094
         AND   matkl IN sp$00084
         AND   meins IN sp$00091
         AND   prdha IN sp$00066
         AND   spart IN sp$00085.
  ENDIF.
  IF sy-subrc EQ 0.
    SORT i_mara BY matnr.
  ENDIF.
DELETE ADJACENT DUPLICATES FROM i_mara comparing matnr.
*fetching data from mbew data base table
  IF  NOT i_mara[] IS  INITIAL.
    SELECT matnr bwkey  bwtar lbkum
           salk3 stprs peinh bklas
           FROM mbew  INTO TABLE i_mbew
           FOR ALL ENTRIES IN i_marc
           WHERE matnr = i_marc-matnr
                AND bwkey = i_marc-werks
                AND bklas IN sp$00063
                AND lbkum IN sp$00088.
  ENDIF.
  IF sy-subrc EQ 0.
    SORT i_mbew BY matnr bwkey bwtar.
  ENDIF.
*DELETE ADJACENT DUPLICATES FROM i_mbew comparing  matnr bwkey bwtar.
*fetching data from  makt data base  table
  IF NOT i_mara[] IS INITIAL.
    SELECT matnr spras maktx
      FROM makt INTO TABLE i_makt
      FOR ALL ENTRIES IN i_mara
      WHERE matnr = i_mara-matnr
       AND maktx IN sp$00059
       AND makt~spras = c_en.
  ENDIF.
  IF sy-subrc EQ 0.
    SORT i_makt BY matnr spras.
  ENDIF.
DELETE ADJACENT DUPLICATES FROM i_makt.
*fetching data from cpec data base table
  IF NOT i_marc[] IS INITIAL.
    SELECT prctr  datbi kokrs abtei
        FROM cepc INTO TABLE i_cepc
        FOR ALL ENTRIES IN i_marc
        WHERE prctr = i_marc-prctr
             AND prctr IN sp$00087
             AND datbi >= sy-datum.
  ENDIF.
  IF sy-subrc EQ 0.
    SORT i_cepc BY prctr datbi kokrs.
  ENDIF.
*DELETE ADJACENT DUPLICATES FROM i_cepc.
LOOP AT i_cepc INTO wa_cpec.
read table i_marc into wa_marc with key
                   prctr = wa_cpec-prctr binary search.
   if sy-subrc = 0.
    i_matl-abtei  = wa_cpec-abtei.
    i_matl-prctr1 = wa_cpec-prctr.
    i_matl-ausss =  wa_marc-ausss.
    i_matl-bearz =  wa_marc-bearz.
    i_matl-beskz =  wa_marc-beskz.
    i_matl-bstmi =  wa_marc-bstmi.
    i_matl-wzeit =  wa_marc-wzeit.
    i_matl-disgr =  wa_marc-disgr.
    i_matl-maabc =  wa_marc-maabc.
    i_matl-dismm =  wa_marc-dismm.
    i_matl-dispo =  wa_marc-dispo.
    i_matl-dispr =  wa_marc-dispr.
    i_matl-dzeit =  wa_marc-dzeit.
    i_matl-plifz =  wa_marc-plifz.
    i_matl-disls =  wa_marc-disls.
    i_matl-bstma =  wa_marc-bstma.
    i_matl-bstrf =  wa_marc-bstrf.
    i_matl-basmg =  wa_marc-basmg.
    i_matl-eisbe =  wa_marc-eisbe.
    i_matl-fevor =  wa_marc-fevor.
    i_matl-fxhor =  wa_marc-fxhor.
    i_matl-lvorm1 = wa_marc-fevor.
    i_matl-matnr1 = wa_marc-matnr.
    i_matl-mmsta = wa_marc-mmsta.
    i_matl-prctr = wa_marc-prctr.
    i_matl-sobsl = wa_marc-sobsl.
    i_matl-tranz = wa_marc-tranz.
    i_matl-werks = wa_marc-werks.
    i_matl-xchar = wa_marc-xchar.
    i_matl-lgpro = wa_marc-lgpro.
    i_matl-fhori = wa_marc-fhori.
    i_matl-rgekz = wa_marc-rgekz.
    i_matl-schgt  = wa_marc-schgt.
    i_matl-minbe  = wa_marc-minbe.
    i_matl-ekgrp  = wa_marc-ekgrp.
    i_matl-eprio  = wa_marc-eprio.
    i_matl-kausf  = wa_marc-kausf.
    i_matl-shflg  = wa_marc-shflg.
    i_matl-shzet  = wa_marc-shzet.
    i_matl-fabkz  = wa_marc-fabkz.
    i_matl-lgrad  = wa_marc-lgrad.
    i_matl-shpro  = wa_marc-shpro.
    i_matl-eislo  = wa_marc-eislo.
    i_matl-rwpro  = wa_marc-rwpro.
    i_matl-lgfsb  = wa_marc-lgfsb.
    i_matl-zzfdwe = wa_marc-zzfdwe.
    i_matl-zzfdwi = wa_marc-zzfdwi.
    i_matl-zzsspe = wa_marc-zzsspe.
    i_matl-zzsspi = wa_marc-zzsspi.
endif.
    READ  TABLE i_mara INTO wa_mara WITH KEY
                        matnr = wa_marc-matnr  binary search.
    i_matl-lvorm =  wa_mara-lvorm.
    i_matl-matkl =  wa_mara-matkl.
    i_matl-matnr =  wa_mara-matnr.
    i_matl-meins =  wa_mara-meins.
    i_matl-prdha =  wa_mara-prdha.
    i_matl-spart =  wa_mara-spart.
    READ TABLE  i_makt INTO wa_makt WITH KEY
                        matnr = wa_mara-matnr binary search.
    i_matl-matnr3 = wa_makt-matnr.
    i_matl-maktx = wa_makt-maktx.
    READ TABLE i_mbew INTO wa_mbew WITH  KEY
                          matnr = wa_marc-matnr binary search.
    i_matl-bklas = wa_mbew-bklas.
    i_matl-bwkey = wa_mbew-bwkey.
    i_matl-lbkum = wa_mbew-lbkum.
    i_matl-salk3 = wa_mbew-salk3.
    i_matl-matnr2 = wa_mbew-matnr.
    i_matl-peinh  = wa_mbew-peinh.
    i_matl-stprs = wa_mbew-stprs.
   READ TABLE i_cepc INTO wa_cpec WITH KEY
                         prctr = wa_marc-prctr.
    APPEND  i_matl.
    CLEAR: wa_cpec, wa_mbew, wa_mara, wa_marc.
  ENDLOOP.
Thaks
Waiting your reply.

Hi Sasmita,
I think your final loop is the problem. As you are looping through the CEPC internal table, and reading the other tables. For different materials there might be a same profit center, the read table will fetch you only first occurance of the profit center from the mara or marc table.
So loop through either mara or marc table and read the remaining and populate your final internal tables. This might solve your problem.
Regards,
Ramesh Babu S
*Reward points if it is helpful....

Similar Messages

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

  • 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

  • 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

  • Inner Joins vs For All Entries - performance query

    Hi All,
    I'm a bit confused here...  I see lots and lots (and lots...) of postings from people asking how to get data from multiple tables.
    To me the immediate answer is to use joins in my select statement to reduce the database load but more and more I see people suggesting FOR ALL ENTRIES is better from a performance perspective.
    Now, simple question time, which is more efficient in the real world when doing something like the following:- (this is a basic example but I'm sure you know what I mean.)
    Select  *
      into  table lt_sales_data
      from  vbap as vbap
    inner  join vbak as vbak
         on vbak~vbeln eq vbap~vbeln
      where  vbak~vbeln in so_vbeln.
    or
    Select  *
      into  table lt_vbak_data
      from  vbak
    where  vbeln in so_vbeln.
    if lt_vbak_data[] is not initial.
    select  *
      into  table lt_vbap_data
      from  vbap
      for all entries in lt_vbak_data
    where  vbeln eq lt_vbak_data-vbeln.
    endif.
    Basically I want to know whether joins or for all entries is better from a database performance perspective.
    I want to know why as well so please don't just post links, random cut and paste answers or one liners.  I'm convinced for all entries is slower but am willing to be persuaded otherwise if someone can show me proof.
    Thanks,
    Gareth.

    Thanks to all the opinions so far...  You've backed up what I suspected although I maybe wasn't clear enough with my question and desired result.  I was hoping someone could produce some hard and fast guidelines from SAP themselves dictating which is the better method.  I know 10 years ago I was taught to use joins and to keep my database access to minimal levels, using keyed reads where applicable and using internal tables to filter data where I couldn't use key fields.
    Gautham, I am aware of SM30 but that doesn't answer the general question I was asking.  I've obviously used SM30 to run some comparisons but I was really hoping someone could give me a definitive answer based on hard facts or from attending some training at SAP recently.  And no points for asking for them
    Tamás, I agree with what you are saying about runing many comparisons - it appears to be dependant on any number of criteria which means each case may require different code.  I've not managed to find a consistent comparison of the two methods that would lead me to use one method or the other...
    Karan, thanks for your feelings but it doesn't really help me!  Why/how does it retrieve the data faster than a join?  Have you got testing/proof to back this up?
    Raam, thanks for those links - they are interesting reads and seem to go through the same arguments I'm currently considering.  Although I still don't have a definitie answer!
    Amit, I understand exactly what yuo are saying about myths and urban legends   That was my motivation for this post.  To bo honest, it seems to me that a lot of the "newer" ABAP coders always go for FOR ALL ENTRIES but I wanted to know - is there a reason or do they all just cut and paste off SDN?!  Are they all just scared of complex inner joins?!  What would you all make of this Select statement for example? -   
    select  afvc~arbid
                afko~aufnr
                aufk~objnr
                afko~plnnr
                afko~plnal
                afko~aufpl
                afko~zaehl
                afpo~matnr
                makt~maktx
                afvc~vornr
                afvc~ltxa1
                afvu~aplzl
                afvu~usr10
                afvv~meinh
                afvv~bmsch
                afvv~vge02
                afvv~vgw02
                afvv~mgvrg
                afab~aplzl_vor
          into  table lt_recipe_orders
          from  afko as afko
         inner  join aufk as aufk
            on  aufk~aufnr eq afko~aufnr
         inner  join afpo as afpo
            on  afpo~aufnr eq afko~aufnr
         inner  join makt as makt
            on  makt~matnr eq afpo~matnr
         inner  join afvc as afvc
            on  afvc~aufpl eq afko~aufpl
         inner  join afvu as afvu
            on  afvu~aufpl eq afvc~aufpl
           and  afvu~aplzl eq afvc~aplzl
         inner  join afvv as afvv
            on  afvv~aufpl eq afvu~aufpl
           and  afvv~aplzl eq afvu~aplzl
          left  outer join afab as afab
            on  afab~aufpl_nch eq afvu~aufpl
           and  afab~aplzl_nch eq afvu~aplzl
           for  all entries in t_resources
         where  afko~gltrs ge v_start_date
           and  afko~gstrs le v_start_date
           and  afko~plnty eq gc_task_list_type_2
           and  afpo~dwerk eq v_werks
           and  makt~spras eq sy-langu
           and  afvc~arbid eq t_resources-objid.
    Twinkal, I've always thought less DB hits is a better performing program too - the above example compares 2 db hits to 1...  I don't have issues with complex joins because I've used them so long so can discount that problem but do agree that less DB hits is the ultimate goal.  Providing of course the Selects you write are actually efficient in themselves.
    Murthy, if you build your select statement correctly duplicate records can be avoided in most cases.  How can you say a join statement will hit the database more when in my example there is 1 DB hit compared to 2 for a for all entries?  And I'd love to know the reasoning behind never using a join on more than 2 tables?!  Is that just an urban myth?!
    Thomas, I've just been looking at some of Siegfried's posts and like what I am reading.  As you say, using full keys via joins is essential.
    Gareth.

  • 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

  • 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

  • Plz change code from inner join to for all entries

    REPORT      : ZSD00009                                               *
    DESCRIPTION : REPORT FOR TRACTOR ON STOCK AGING                      *
    CODED BY    : DINESH AGARWAL                                         *
    SPECS BY    : AJAY KOTHI                                             *
    START DATE  : 07TH JUNE , 2000                                       *
    CHANGED     : MANOJ SINGH 01/02/2001                                 *
    CHANGED     : YOGINDER KAURA 27TH JULY 2001                          *
    REPORT  ZMUSA_SD00009                           .
    TABLES : vbrk,vbrp,vbfa,ser01,objk,knvv,mara,mbew, t005u,
             t171t,kna1,equi,ihpa, cabn, ausp.
    DATA : BEGIN OF itab OCCURS 0,
             bzirk1 LIKE vbrk-bzirk,
             bzirk LIKE KNA1-regio, "added by dhiraj - 23.11.2007
             LAND1 LIKE KNA1-LAND1,
             kunde LIKE equi-kunde,
             vbeln LIKE vbrk-vbeln,
             fkdat LIKE vbrk-fkdat,
             matkl LIKE mara-matkl,
             sernr LIKE objk-sernr,
             equnr LIKE objk-equnr ,
             matnr LIKE vbrp-matnr,
             spart LIKE vbrp-spart,
             vbelv LIKE vbrp-vbelv,
             posnv LIKE vbrp-posnv,
             days1(1) TYPE n ,
             days2(1) TYPE n ,
             days3(1) TYPE n ,
             days4(1) TYPE n ,
             days5(1) TYPE n ,
             werks like vbrp-werks,
           END OF itab.
    DATA : BEGIN OF itab_grp OCCURS 0,
             werks like vbrp-werks,
             matkl LIKE mara-matkl,
             bzirk1 LIKE vbrk-bzirk,
             bzirk LIKE KNA1-regio, "added by dhiraj - 23.11.2007
             kunde LIKE equi-kunde,
             vbeln LIKE vbrk-vbeln,
             fkdat LIKE vbrk-fkdat,
             sernr LIKE objk-sernr,
             equnr LIKE objk-equnr ,
             matnr LIKE vbrp-matnr,
             spart LIKE vbrp-spart,
             vbelv LIKE vbrp-vbelv,
             posnv LIKE vbrp-posnv,
             days1(1) TYPE n ,
             days2(1) TYPE n ,
             days3(1) TYPE n ,
             days4(1) TYPE n ,
             days5(1) TYPE n ,
           END OF itab_grp.
    DATA : BEGIN OF dealer ,
           days1(3) TYPE p ,
           days2(3) TYPE p ,
           days3(3) TYPE p ,
           days4(3) TYPE p ,
           days5(3) TYPE p ,
           END OF dealer .
    DATA : state LIKE dealer .
    DATA : matgr LIKE dealer .
    DATA : plant LIKE dealer .
    DATA :  BEGIN OF us,
           days1(4) TYPE p ,
           days2(4) TYPE p ,
           days3(4) TYPE p ,
           days4(4) TYPE p ,
           days5(4) TYPE p ,
           END OF us .
    DATA : lin TYPE i , check_box(1) ,
           dealer_total TYPE i,state_total  TYPE i,
           matgr_total  TYPE i,plant_total  TYPE i,
           us_total TYPE i .
    DATA  vobjnr(22) .
    DATA  no_of_days TYPE i .
    DATA  flag_fkdat.
    DATA  atinn1 LIKE cabn-atinn.
    DATA  atinn LIKE cabn-atinn.
    DATA : atflv LIKE ausp-atflv.
    DATA : atflv1(8) TYPE n.
    DATA : invdate TYPE sy-datum.
    DATA  invoicenum(10) TYPE n .
    DATA : BEGIN OF it_regio OCCURS 0,
            regio LIKE kna1-regio,
           END OF it_regio.
    data : it001w like table of t001w with header line.
    TABLES  vbpa.
    SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : werks FOR vbrp-werks,
                     vkorg FOR vbrk-vkorg,
                     vtweg FOR vbrk-vtweg,
                     spart FOR vbrp-spart.
    SELECTION-SCREEN END OF BLOCK block1 .
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-002.
    SELECT-OPTIONS : matkl FOR mara-matkl,
                     bzirk FOR vbrk-regio," changed by dhiraj - 23.11.2007
                     kunrg FOR vbrk-kunrg ,
                     fkdat FOR vbrk-fkdat.
    SELECTION-SCREEN END OF BLOCK block2 .
    SELECTION-SCREEN BEGIN OF BLOCK block3 WITH FRAME TITLE text-003.
    PARAMETERS : days1(2) TYPE p OBLIGATORY DEFAULT '90' ,
                 days2(2) TYPE p OBLIGATORY DEFAULT '90',
                 days3(2) TYPE p OBLIGATORY DEFAULT '180',
                 days4(2) TYPE p OBLIGATORY DEFAULT '270',
                 days5(2) TYPE p OBLIGATORY DEFAULT '365'.
    SELECTION-SCREEN END OF BLOCK block3 .
    SELECTION-SCREEN BEGIN OF BLOCK reptype WITH FRAME TITLE text-201 .
    PARAMETERS  : detail RADIOBUTTON GROUP rep ,
                  summary RADIOBUTTON GROUP rep ,
                  grp_summ RADIOBUTTON GROUP rep .
    SELECTION-SCREEN END OF BLOCK reptype .
    *start of code by Kalpana for Authority check for REGIO */
    AT SELECTION-SCREEN .
      SELECT regio FROM kna1 INTO TABLE it_regio
       WHERE regio IN bzirk
       AND   kunnr IN kunrg.
      CLEAR it_regio.
      LOOP AT it_regio.
        AUTHORITY-CHECK OBJECT 'Z:AO_REGIO'
                         ID 'REGIO' FIELD it_regio.
        IF sy-subrc NE 0.
          MESSAGE e173(zma) WITH  it_regio.
        ENDIF.
      ENDLOOP.
    *End of code by Kalpana for Authority check for REGIO */
      IF days1 NE days2 .
        MESSAGE e000(8i) WITH text-004  text-009  text-005.
      ELSEIF days3 LE days2 .
        MESSAGE e000(8i) WITH  text-006  text-010  text-005 .
      ELSEIF days4 LE days3 .
        MESSAGE e000(8i) WITH  text-007  text-010  text-006 .
      ELSEIF days5 LE days4 .
        MESSAGE e000(8i) WITH  text-008  text-010  text-007 .
      ENDIF .
    START-OF-SELECTION .
    select abzirk akunrg avbeln afkdat  b~matnr
            cmatkl dvbelv dposnv fsernr  f~equnr
      into corresponding fields of table itab
      from    ( ( ( ( ( vbrk as a inner join vbrp as b
                                              on avbeln = bvbeln )
                           inner join mara as c on cmatnr = bmatnr )
                           inner join vbfa as d on dvbeln = bvbeln
                                               and dposnn = bposnr )
                           inner join ser01 as e on elief_nr = dvbelv
                                                 and eposnr   = dposnv )
                           inner join objk as f on fobknr = eobknr   )
             where a~vkorg in  vkorg
             and   a~vtweg in  vtweg
             and   a~bzirk in  bzirk
             and   a~fkdat in  fkdat
             and   c~matkl in  matkl
             and   a~kunrg in  kunrg
             and   b~spart in  spart
             and   c~mtart = 'FERT'
             and   d~vbtyp_n =  'M'
             and   a~vbtyp   =  'M'
             and   a~fksto   =  ' '
             and   b~vgtyp   =  'J' .
      REFRESH itab.
      CLEAR itab .
      CLEAR cabn .
      select * from t001w into table it001w where werks in werks.
      SELECT  SINGLE  atinn INTO atinn1 FROM  cabn
             WHERE  atnam  = 'INVOICEDATE'.
    *************************modified by dhiraj - 23.11.2007*****************
    SELECT  kbzirk aatflv ekunde eequnr esernr ematnr m~matkl
             INTO CORRESPONDING FIELDS OF  itab
            FROM ( ( ( equi AS e  INNER JOIN ausp AS a
                 ON eequnr = aobjek  )
                  INNER JOIN mara AS m ON ematnr  = mmatnr )
                  INNER JOIN knvv AS k ON kkunnr  = ekunde
                                       AND kspart = mspart )
                          WHERE m~mtart = 'FERT'
                          AND   m~spart IN spart
                          AND   m~matkl IN matkl
                          AND  e~kunde <> ' '
                          AND  e~kunde IN kunrg
                          AND  k~bzirk IN  bzirk
                          and  a~atinn = atinn1
                          AND  k~vkorg = 'M001'
                          AND  k~vtweg = '90'.
      SELECT  kbzirk nregio nland1 aatflv ekunde eequnr esernr ematnr m~matkl
              INTO CORRESPONDING FIELDS OF itab
             FROM ( ( ( ( equi AS e  INNER JOIN ausp AS a
                  ON eequnr = aobjek  )
                   INNER JOIN mara AS m ON ematnr  = mmatnr )
                   INNER JOIN knvv AS k ON kkunnr  = ekunde
                                        AND kspart = mspart )
                   INNER JOIN kna1 as n ON nkunnr  = kkunnr )
                           WHERE m~mtart = 'FERT'
                           AND   m~spart IN spart
                           AND   m~matkl IN matkl
                           AND  e~kunde <> ' '
                           AND  e~kunde IN kunrg
                           AND  nregio IN bzirk "k-bzirk changed to nregio by dhiraj-23.11.2007
                          and  a~atinn = atinn1
                           AND  k~vkorg = 'F041'
                           AND  k~vtweg = '01'.
       added by krunal for plant as select-option
        clear ausp.
        select single * from cabn where atnam = 'DELIVERINGPLANT'.
        SELECT  SINGLE      * FROM  ausp
               WHERE  objek  = itab-equnr
               AND    atinn  = CABN-ATINN.
       CLEAR CABN.
        read table it001w with key werks = ausp-atwrt.
        if sy-subrc <> 0.
         continue.
        else.
          itab-werks = ausp-atwrt.
        endif.
    *end addition
        CLEAR : ausp, knvv .
        SELECT  SINGLE      * FROM  ausp
               WHERE  objek  = itab-equnr
               AND    atinn  = atinn1 .
        MOVE ausp-atflv   TO atflv1 .
        MOVE atflv1 TO invdate .
        MOVE invdate TO itab-fkdat.
        CLEAR : cabn, ausp, atinn.
        SELECT  SINGLE  atinn INTO atinn FROM  cabn
               WHERE  atnam  = 'INVOICENO' .
        SELECT SINGLE      * FROM  ausp
             WHERE  objek  = itab-equnr
             AND    atinn  = atinn.
        MOVE ausp-atflv TO invoicenum .
        MOVE invoicenum TO itab-vbeln.
        IF NOT fkdat-low IS INITIAL .
          IF invdate GE fkdat-low AND invdate LE fkdat-high .
            APPEND itab.
          ELSE.
            CONTINUE.
          ENDIF.
        ELSE.
          APPEND itab.
        ENDIF.
      ENDSELECT.
      SORT itab BY sernr matnr .
      DELETE ADJACENT DUPLICATES FROM itab COMPARING sernr matnr .
      SORT itab BY equnr .
      LOOP AT itab .
        CONCATENATE 'IE' itab-equnr INTO vobjnr .
        SELECT SINGLE * FROM ihpa  WHERE objnr = vobjnr
                                 AND   parvw = 'RE'
                                 AND   obtyp = 'IEQ'
                                 AND kzloesch EQ space. " Yogi on 27/06/2001
        IF sy-subrc EQ 0 .
          DELETE itab INDEX sy-tabix .
          CONTINUE .
        ELSE .
          no_of_days = sy-datum - itab-fkdat .
          IF no_of_days LE days1 .
            itab-days1 = 1 .
          ELSEIF no_of_days GT days2 AND no_of_days LE days3.
            itab-days2 = 1 .
          ELSEIF no_of_days GT days3 AND no_of_days LE days4.
            itab-days3 = 1 .
          ELSEIF no_of_days GT days4 AND no_of_days LE days5.
            itab-days4 = 1 .
          ELSEIF no_of_days GT days5 .
            itab-days5 = 1 .
          ENDIF .
          MODIFY itab INDEX sy-tabix .
        ENDIF .
      ENDLOOP .
    END-OF-SELECTION .
      DESCRIBE TABLE itab LINES lin .
      IF lin GT 0 .
        SORT itab BY bzirk kunde  vbeln .
        IF detail = 'X' .
          PERFORM disp_list .
        ELSEIF summary = 'X' .
          PERFORM summary_list .
        ELSEIF grp_summ = 'X' .
          PERFORM grp_summ_list .
        ENDIF.
      ELSE .
      MESSAGE i000(8i) WITH 'No Records exist as per Selection Condititon' .
      ENDIF .
    TOP-OF-PAGE .
      WRITE : / text-011 , ' - ' , sy-datum .
    *&      Form  DISP_LIST
          text
    -->  p1        text
    <--  p2        text
    FORM disp_list.
      LOOP AT itab.
    ********changes made by dhiraj - 23.11.2007********************
        AT NEW bzirk.
          SKIP .
         SELECT SINGLE * FROM t171t  WHERE bzirk = itab-bzirk
                                     AND   spras = 'E'   .
          SELECT SINGLE * FROM t005u WHERE spras = sy-langu
                                              AND BLAND = itab-bzirk AND LAND1 = ITAB-LAND1.
          PERFORM list_heading.
          FORMAT COLOR 4 INTENSIFIED ON.
          WRITE :/ 'Sales Region : ',itab-bzirk,30 t005u-BEZEI
                                        ,81 ''.
          ULINE .
        ENDAT.
        AT NEW kunde.
          SELECT SINGLE * FROM kna1 WHERE kunnr = itab-kunde .
          FORMAT COLOR 3 INTENSIFIED ON.
          WRITE :/ 'Dealer         : ',itab-kunde,30(25) kna1-name1,
                 60 'City  : ' ,kna1-ort01, 81 ''.
          ULINE .
        ENDAT.
        AT NEW fkdat .
          FORMAT COLOR OFF INTENSIFIED OFF .
          WRITE : /5 itab-vbeln,
                   20 itab-fkdat .
          CLEAR flag_fkdat .
        ENDAT .
       at new matkl .
         format color 2 intensified on.
         write :/ 'Material Group    : ',itab-matkl, 81 ''.
         skip .
       endat .
       mcnt = mcnt + 1 .
        dealer-days1 = dealer-days1 + itab-days1  .
        dealer-days2 = dealer-days2 + itab-days2  .
        dealer-days3 = dealer-days3 + itab-days3  .
        dealer-days4 = dealer-days4 + itab-days4  .
        dealer-days5 = dealer-days5 + itab-days5  .
        state-days1  = state-days1 + itab-days1  .
        state-days2  = state-days2 + itab-days2  .
        state-days3  = state-days3 + itab-days3  .
        state-days4  = state-days4 + itab-days4  .
        state-days5  = state-days5 + itab-days5  .
        IF flag_fkdat EQ 'Y'  .
          NEW-LINE .
        ENDIF .
        WRITE :    35 itab-matnr, "krunal
                   55 itab-sernr,
                   72 itab-werks, "krunal
                   83 itab-days1 ,
                   93 itab-days2 ,
                   103 itab-days3 ,
                   113 itab-days4 ,
                   123 itab-days5 .
        PERFORM get_musa_ta.
        flag_fkdat = 'Y' .
       at end of matkl .
         skip .
         format color 2 intensified on.
         write :/ 'Total For    : ',itab-matkl, ' - ' , mcnt .
         clear mcnt .
         uline  .
       endat .
        AT END OF kunde.
          dealer_total = dealer-days1 + dealer-days2 + dealer-days3
                                     + dealer-days4 + dealer-days5 .
          FORMAT COLOR 3 INTENSIFIED ON.
          WRITE :/ 'Total for  : ',itab-kunde,' - ' ,
                   79 dealer-days1 ,
                   89 dealer-days2 ,
                   99 dealer-days3 ,
                   109 dealer-days4 ,
                   119 dealer-days5 ,
                   129 dealer_total  .
          CLEAR : dealer_total , dealer .
          ULINE .
        ENDAT.
        AT END OF bzirk.
          state_total = state-days1 + state-days2 + state-days3
                                    + state-days4 + state-days5 .
          FORMAT COLOR 4 INTENSIFIED ON.
          WRITE :/ 'Total for  : ',itab-bzirk,' - ' ,
                   79 state-days1 ,
                   89 state-days2 ,
                   99 state-days3 ,
                   109 state-days4 ,
                   119 state-days5 ,
                   129 state_total  .
          CLEAR : state_total , state .
          ULINE.
        ENDAT.
      ENDLOOP.
    ENDFORM.                               " DISP_LIST
    *&      Form  LIST_HEADING
          text
    -->  p1        text
    <--  p2        text
    FORM list_heading.
      DATA : text1(7) , text2(7) , text3(7) , text4(7) , text5(7),
             text11(4) , text12(4) , text13(4) , text14(4) , text15(4) .
      text11 = days1 .
      text12 = days2 .
      text13 = days3 .
      text14 = days4 .
      text15 = days5 .
      CONCATENATE : '=<' text11 INTO text1 ,
                    '>'  text12 INTO text2 ,
                    '>'  text13 INTO text3 ,
                    '>'  text14 INTO text4 ,
                    '>'  text15 INTO text5 .
      ULINE.
      FORMAT COLOR 1 INTENSIFIED OFF.
      WRITE :/5  'Invoice No.',
              20 'Invoice Dt',
              34 'Material',
              55 'Serial No .' ,
              72 'Plant',
              79  text1 ,
              89  text2 ,
              99  text3 ,
              109  text4 ,
              119  text5 ,
              129 'Floor' ,
              139  'Total'  .
      ULINE.
    ENDFORM.                               " LIST_HEADING
    *&      Form  SUMMARY_LIST
          text
    -->  p1        text
    <--  p2        text
    FORM summary_list.
      CLEAR : us, us_total .
      LOOP AT itab.
        AT FIRST.
          SKIP .
    ******modified by dhiraj- 23.11.2007*******************************
         SELECT SINGLE * FROM t171t  WHERE bzirk = itab-bzirk
                                     AND   spras = 'E'   .
          SELECT SINGLE * FROM t005u WHERE spras = sy-langu
                                              AND BLAND = itab-bzirk AND LAND1 = ITAB-LAND1.
          PERFORM list_heading_summary.
         format color 4 intensified on.
         write :/ 'Sales District : ',itab-bzirk,30 t171t-bztxt
                                       ,81 ''.
          ULINE .
        ENDAT.
        AT NEW kunde.
          SELECT SINGLE * FROM kna1 WHERE kunnr = itab-kunde .
         format color 3 intensified on.
         write :/ 'Dealer         : ',itab-kunde,30(25) kna1-name1,
                60 'City  : ' ,kna1-ort01, 81 ''.
         uline .
        ENDAT.
        AT NEW fkdat .
         format color off intensified off .
         write : /5 itab-vbeln,
                  20 itab-fkdat .
          CLEAR flag_fkdat .
        ENDAT .
       at new matkl .
         format color 2 intensified on.
         write :/ 'Material Group    : ',itab-matkl, 81 ''.
         skip .
       endat .
       mcnt = mcnt + 1 .
        dealer-days1 = dealer-days1 + itab-days1  .
        dealer-days2 = dealer-days2 + itab-days2  .
        dealer-days3 = dealer-days3 + itab-days3  .
        dealer-days4 = dealer-days4 + itab-days4  .
        dealer-days5 = dealer-days5 + itab-days5  .
        state-days1  = state-days1 + itab-days1  .
        state-days2  = state-days2 + itab-days2  .
        state-days3  = state-days3 + itab-days3  .
        state-days4  = state-days4 + itab-days4  .
        state-days5  = state-days5 + itab-days5  .
        us-days1  = us-days1 + itab-days1  .
        us-days2  = us-days2 + itab-days2  .
        us-days3  = us-days3 + itab-days3  .
        us-days4  = us-days4 + itab-days4  .
        us-days5  = us-days5 + itab-days5  .
        IF flag_fkdat EQ 'Y'  .
          NEW-LINE .
        ENDIF .
       write :    42 itab-sernr ,
                  59 itab-days1 ,
                  69 itab-days2 ,
                  79 itab-days3 ,
                  89 itab-days4 ,
                  99 itab-days5 .
        flag_fkdat = 'Y' .
       at end of matkl .
         skip .
         format color 2 intensified on.
         write :/ 'Total For    : ',itab-matkl, ' - ' , mcnt .
         clear mcnt .
         uline  .
       endat .
        AT END OF kunde.
          dealer_total = dealer-days1 + dealer-days2 + dealer-days3
                                     + dealer-days4 + dealer-days5 .
         format color 3 intensified on.
         write :/ 'Total for  : ',itab-kunde,' - ' ,
                  57 dealer-days1 ,
                  67 dealer-days2 ,
                  77 dealer-days3 ,
                  87 dealer-days4 ,
                  97 dealer-days5 ,
                  107 dealer_total  .
          CLEAR : dealer_total , dealer .
         uline .
        ENDAT.
        AT END OF bzirk.
    **************modified by dhiraj - 23.11.2007****************
         SELECT SINGLE * FROM t171t  WHERE bzirk = itab-bzirk
                                     AND   spras = 'E'   .
          SELECT SINGLE * FROM t005u WHERE spras = sy-langu
                                              AND BLAND = itab-bzirk AND LAND1 = ITAB-LAND1.
          state_total = state-days1 + state-days2 + state-days3
                                    + state-days4 + state-days5 .
          FORMAT COLOR 4 INTENSIFIED ON.
          WRITE :/10 t171t-bztxt,   " 'Total for  : ',itab-bzirk,' - ' ,
                   57 state-days1 ,
                   67 state-days2 ,
                   77 state-days3 ,
                   87 state-days4 ,
                   97 state-days5 ,
                   107 state_total  .
          CLEAR : state_total , state .
          ULINE.
        ENDAT.
        us_total = us-days1 + us-days2 + us-days3 + us-days4 + us-days5 .
      ENDLOOP.
      SKIP 2.
      FORMAT COLOR 5 INTENSIFIED ON.
      WRITE :/10 'Total for US : ' ,
                55 us-days1 ,
                65 us-days2 ,
                75 us-days3 ,
                85 us-days4 ,
                95 us-days5 ,
                105 us_total  .
    ENDFORM.                               " SUMMARY_LIST
    *&      Form  LIST_HEADING_SUMMARY
          text
    -->  p1        text
    <--  p2        text
    FORM list_heading_summary.
      DATA : text1(7) , text2(7) , text3(7) , text4(7) , text5(7),
             text11(4) , text12(4) , text13(4) , text14(4) , text15(4) .
      text11 = days1 .
      text12 = days2 .
      text13 = days3 .
      text14 = days4 .
      text15 = days5 .
      CONCATENATE : '=<' text11 INTO text1 ,
                    '>'  text12 INTO text2 ,
                    '>'  text13 INTO text3 ,
                    '>'  text14 INTO text4 ,
                    '>'  text15 INTO text5 .
      ULINE.
      FORMAT COLOR 1 INTENSIFIED OFF.
      WRITE :/10  'State',
              57  text1 ,
              67  text2 ,
              77  text3 ,
              87  text4 ,
              97  text5 ,
              110  'Total'  .
      ULINE.
    ENDFORM.                               " LIST_HEADING_SUMMARY
    *&      Form  LIST_HEADING_SUMMARY
          text
    -->  p1        text
    <--  p2        text
    FORM list_heading_grp_summary.
      DATA : text1(7) , text2(7) , text3(7) , text4(7) , text5(7),
             text11(4) , text12(4) , text13(4) , text14(4) , text15(4) .
      text11 = days1 .
      text12 = days2 .
      text13 = days3 .
      text14 = days4 .
      text15 = days5 .
      CONCATENATE : '=<' text11 INTO text1 ,
                    '>'  text12 INTO text2 ,
                    '>'  text13 INTO text3 ,
                    '>'  text14 INTO text4 ,
                    '>'  text15 INTO text5 .
      ULINE.
      FORMAT COLOR 1 INTENSIFIED OFF.
      WRITE :/10  'Material Group',
              57  text1 ,
              67  text2 ,
              77  text3 ,
              87  text4 ,
              97  text5 ,
              110  'Total'  .
      ULINE.
    ENDFORM.                               " LIST_HEADING_GRP_SUMMARY
    *&      Form  GET_MUSA_TA
          text
    -->  p1        text
    <--  p2        text
    FORM get_musa_ta.
      CLEAR vbpa .
      SELECT SINGLE    * FROM  vbpa
             WHERE  vbeln  = itab-vbeln
             AND    parvw  =  'RE' .
          and    kunnr  = 'TA001' .
      IF sy-subrc = 0 .
        IF vbpa-kunnr = 'TA001' .
          WRITE : 129 'TA ' .
        ELSE.
          WRITE : 129 'MUSA' .
        ENDIF.
      ENDIF.
    ENDFORM.                               " GET_MUSA_TA
    *&      Form  grp_summ_list
          text
    -->  p1        text
    <--  p2        text
    FORM grp_summ_list .
      CLEAR : us, us_total .
    itab_grp[] = itab[] .
    sort itab_grp BY werks matkl.
      LOOP AT itab_grp.
        AT FIRST.
          SKIP .
          PERFORM list_heading_grp_summary.
          ULINE .
        ENDAT.
        matgr-days1  = matgr-days1 + itab_grp-days1  .
        matgr-days2  = matgr-days2 + itab_grp-days2  .
        matgr-days3  = matgr-days3 + itab_grp-days3  .
        matgr-days4  = matgr-days4 + itab_grp-days4  .
        matgr-days5  = matgr-days5 + itab_grp-days5  .
        plant-days1 = plant-days1 + matgr-days1 .
        plant-days2 = plant-days2 + matgr-days2 .
        plant-days3 = plant-days3 + matgr-days3 .
        plant-days4 = plant-days4 + matgr-days4 .
        plant-days5 = plant-days5 + matgr-days5 .
        us-days1  = us-days1 + itab_grp-days1  .
        us-days2  = us-days2 + itab_grp-days2  .
        us-days3  = us-days3 + itab_grp-days3  .
        us-days4  = us-days4 + itab_grp-days4  .
        us-days5  = us-days5 + itab_grp-days5  .
        IF flag_fkdat EQ 'Y'  .
          NEW-LINE .
        ENDIF .
       write :    42 itab-sernr ,
                  59 itab-days1 ,
                  69 itab-days2 ,
                  79 itab-days3 ,
                  89 itab-days4 ,
                  99 itab-days5 .
        flag_fkdat = 'Y' .
        AT END OF matkl.
          matgr_total = matgr-days1 + matgr-days2 + matgr-days3
                                    + matgr-days4 + matgr-days5 .
          FORMAT COLOR 4 INTENSIFIED ON.
          WRITE :/10 itab_grp-matkl,   " 'Total for  : ',itab_grp-matkl,' - ' ,
                   57 matgr-days1 ,
                   67 matgr-days2 ,
                   77 matgr-days3 ,
                   87 matgr-days4 ,
                   97 matgr-days5 ,
                   107 matgr_total  .
          CLEAR : matgr_total , matgr .
          ULINE.
        ENDAT.
        AT END OF werks.
          plant_total = plant-days1 + plant-days2 + plant-days3
                                    + plant-days4 + plant-days5 .
          FORMAT COLOR 4 INTENSIFIED ON.
          WRITE :/10 itab_grp-werks,   " 'Total for  : ',itab_grp-werks,' - ' ,
                   57 plant-days1 ,
                   67 plant-days2 ,
                   77 plant-days3 ,
                   87 plant-days4 ,
                   97 plant-days5 ,
                   107 plant_total  .
          CLEAR : plant_total , plant .
          ULINE.
        ENDAT.
        us_total = us-days1 + us-days2 + us-days3 + us-days4 + us-days5 .
      ENDLOOP.
      SKIP 2.
      FORMAT COLOR 5 INTENSIFIED ON.
      WRITE :/10 'Total  : ' ,
                55 us-days1 ,
                65 us-days2 ,
                75 us-days3 ,
                85 us-days4 ,
                95 us-days5 ,
                105 us_total  .
    ENDFORM.                    " grp_summ_list

    {SELECT OBJEK CUOBJ
      INTO CORRESPONDING FIELDS OF TABLE TAB_INOB
      FROM INOB
    WHERE OBJEK IN R_MATNR.
    SELECT ATWRT OBJEK ATINN
      INTO CORRESPONDING FIELDS OF TABLE TAB_AUSP
      FROM AUSP
       FOR ALL ENTRIES IN TAB_INOB
    WHERE OBJEK = TAB_INOB-CUOBJ.
    SELECT ATNAM
      INTO TABLE TAB_CABN
      FROM CABN
       FOR ALL ENTRIES IN TAB_INOB
    WHERE ATNAM = 'ZCURSEASON'
        OR ATNAM = 'ZCURYEAR'
       AND ATINN = TAB_AUSP-ATINN.
    after this you can gether the data into one internal table.
    Form one inter nal table it_final.
    loop at TAB_INOB.
    it_final-OBJEK = tab_inob-OBJEK.
    it_final-CUOBJ = tab_inob-CUOBJ.
    READ TABLE TAB_CABN  WITH KEY OBJEK = TAB_INOB-CUOBJ.
    IT_FINAL-ATWRT = TAB_CABN-ATWRT.
    IT_FINAL-ATINN = TAB_CABN-ATINN.
    DO SAME FOR THIRD TABLE
    AFFTER DO ALL
    APPEND IT_FINAL.
    ENDLOOP.}

  • Inner join Vs for all entries for performance

    hi,
        i need to fetch data from 5 tables where i have common key vbeln, is this suggestable to write a select query with inner join or write an inner join for 2 tables with more fileds and for remaining using for all entries.... please suggest how can i increase the performance...all points are rewarded....
    thnaks alot.

    Is this a dialog program or a data extract? Rob is right in that the difference is negligible IF the number of records involved are only a few.
    On the other hand, if you are extracting a large number of records, then the performance depends on a number of things and is generally unpredictable.
    The way I approach it is by first developing the extract program with a join because it is easier to code. If the program run time is within the acceptable range, I would let it be and migrate to production. If the performance is of high priority and if the join appears to take long time, then I will comment out the code and try the FAE approach. If the run time with FAE is not markedly better, then I would go back to join.

  • Query related to inner join V/S all entries........

    Hi all,
    I have a dought ...related to join and all entries
    Which one will be the better as per performance prospective :
    1>For all entries
    or
    2> using inner join condition
    i am combining 2 tables ...
    but in my where clause is having 6-7 condition if i used inner join concept...
    Please let me know thanks for the help...in advance
    regards
    Amit

    Check Re: Multiple Table Join instead of Nested Selects? I wrote a program that compares the performance of a join against for all entries. The join won. But the best thing to do is for you test and compare both methods for your particular situation.
    In a select, the most important factor is the use of an index.
    Rob

  • Left outer join using For All Entries

    how to implement left outer join using for all entries In REPORTS.

    hi Mansi,
    this is how i populate
    SELECT VGBEL LFIMG POSNR VBELN FROM LIPS INTO  TABLE IT_delv  FOR ALL ENTRIES IN IT_VBAP WHERE VGBEL = IT_VBAP-VBELN.
    LOOP AT IT_delv INTO WA_delv.
    WA_FINAL-VBELN_1 = WA_DELV-VBELN_1.
    WA_FINAL-LFDAT =   WA_DELV-LFDAT.
    WA_FINAL-LFIMG   = WA_DELV-LFIMG.
    WA_FINAL-POSNR2 =   WA_DELV-POSNR2..
    APPEND WA_FINAL TO IT_FINAL.
    CLEAR: WA_FINAL , WA_delv.
    ENDLOOP.
    LOOP AT IT_FINAL INTO WA_FINAL.
    READ TABLE IT_vbap INTO WA_vbap WITH KEY VGBEL = WA_FINAL-VBELN.
      WA_FINAL-VBELN = WA_VBAP-VBELN.
    WA_FINAL-MATNR = WA_VBAP-MATNR.
    WA_FINAL-KWMENG = WA_VBAP-KWMENG.
    WA_FINAL-NETWR = WA_VBAP-NETWR.
    MODIFY IT_FINAL FROM WA_FINAL.
    ENDLOOP.
    My question is , it_vbap has 5 five records A,B,C,D,E.
    in it_delv ,there are 20 record corrresponding to A,B,D of IT_VBAP.
    in final table i wont get info of recors B,E. I want those info also in final table ..how can i do that...

  • JOINS Vs FOR ALL ENTRIES

    hi,
    I have to extract data from 6 tables based on cross check reference among these tables.some of the tables do not have foregin key references,but i have written SELECT query joining all the 6 tables, it works fine.
    My question is, if i use FOR ALL ENTRIES instead of an inner join will it improve performance?
         but no of database hits would be more isn't it?
    Kindly reply ASAP

    hi ,
    here you go ,,,
    1. in the innerjoin system will hit the databasa one time.. then fetch the data..for the tables u have joined... when u use the join make sure the query shold not effect the performance.. try to paas all the primary key values.. then link the tables using the complete primary...
    2. when u use the FOR ALL ENTRIES.. the system will retrive all the records which matches the FIELDS which u r refering in the Internal tabel... while using the FOR ALL ENTRIES.. creal the duplicate entries.. other wise it select the record more number of time at data base level... but u will get the entries properly...
    Regards,
    Ranjita

  • Joins to For All Entries

    Hi ABAP Folks,
    I am extracting a set a values from 5 different tables using FOR ALL statement and consolidating the results of each internal table to form a MASTER INTERNAL TABLE containing fields USERNAME ROLENAME ROLENAMETEXT TCODE TCODETEXT.
    BNAME UNAME->(USERNAME)
    AGR_NAME -> ROLES
    OBJECT,OBJCT->AUTHORISATION OBJ
    If the user input is a group name.
    Select BNAME CLASS From USR02 into LT_USR02 where CLASS IN S_USRGRP
    Select UNAME AGR_NAME into LT_AGR_USERS From AGR_USERS For All entries in LT_USR02 where UNAME = LT_USR02-BNAME
    Select AGR_NAME OBJECT into LT_AGR_1251 From AGR_1251 For All entries in LT_AGR_USERS where AGR_NAME = LT_AGR_USERS-AGR_NAME
    Select AGR_NAME TEXT into LT_AGR_TEXTS From AGR_TEXTS For All entries in LT_AGR_1251 where AGR_NAME = LT_AGR_1251-AGR_NAME
    Select OBJCT TCODE into LT_TSTCA From TSTCA For All entries in LT_AGR_1251 where OBJCT = LT_AGR_1251-OBJECT
    Select TCODE TEXTS into LT_TSTCT From TSTCT For All entries in LT_TSTCA where TCODE = LT_TSTCA-TCODE.
    Resultant ITAB IS User Name, User Group, User Group Texts, Transaction Codes, Transaction Code Text.
    <b>Is it better to go for a join in this case?Will joins be more efficient?Any help welcome and will be rewarded.</b>
    in case yes,Syntax for the above case will be helpful.
    Thanks in Advance.
    <b></b>

    Jayant,
    The joins are helpful when the two tables are related to each other basically VBAK and VBAP would be useful to join on document number but it is not advisable to join vbap and aufo on material number.
    In your case you can join the USER* related data and Transaction* related data via joins.
    Message was edited by: Anurag Bankley
    Message was edited by: Anurag Bankley

Maybe you are looking for