<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: nested loops in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402871#M817094</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Why are you using loops within the loops? thats why you get the performance issues. You have to read the tables then assign each feild then append to the final table. It will solve your problem.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sarada&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Feb 2008 13:24:32 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-02-12T13:24:32Z</dc:date>
    <item>
      <title>nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402870#M817093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the problem is for every record its displaying the same GL ACC(saknr) no.. it should be differ for every record.. while debugging i am able to get the different values...but in the final result its not... please help me out....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and please write the code using read statement....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT mblnr mjahr budat &lt;/P&gt;&lt;P&gt;       FROM mkpf &lt;/P&gt;&lt;P&gt;       INTO CORRESPONDING FIELDS OF &lt;/P&gt;&lt;P&gt;       TABLE itab_mkpf&lt;/P&gt;&lt;P&gt;       WHERE budat IN s_budat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT bukrs mblnr zeile&lt;/P&gt;&lt;P&gt;       bwtar matnr  gsber &lt;/P&gt;&lt;P&gt;       werks menge meins  dmbtr &lt;/P&gt;&lt;P&gt;  FROM mseg &lt;/P&gt;&lt;P&gt;  INTO CORRESPONDING FIELDS OF &lt;/P&gt;&lt;P&gt;  TABLE itab_mseg&lt;/P&gt;&lt;P&gt;  FOR ALL ENTRIES IN &lt;/P&gt;&lt;P&gt;  itab_mkpf WHERE bukrs EQ p_bukrs&lt;/P&gt;&lt;P&gt;            AND mblnr EQ itab_mkpf-mblnr &lt;/P&gt;&lt;P&gt;            AND gsber IN p_gsber&lt;/P&gt;&lt;P&gt;            AND bwtar IN s_bwtar &lt;/P&gt;&lt;P&gt;            AND mjahr EQ  itab_mkpf-mjahr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT bukrs saknr&lt;/P&gt;&lt;P&gt;  FROM skb1&lt;/P&gt;&lt;P&gt;  INTO  corresponding fieldS of &lt;/P&gt;&lt;P&gt;  table itab_skb1 WHERE bukrs EQ p_bukrs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr maktx &lt;/P&gt;&lt;P&gt;       FROM makt INTO &lt;/P&gt;&lt;P&gt;       TABLE itab_makt &lt;/P&gt;&lt;P&gt;       FOR ALL ENTRIES IN itab_mseg &lt;/P&gt;&lt;P&gt;       WHERE matnr EQ itab_mseg-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab_mkpf.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab_mseg WHERE mblnr EQ itab_mkpf-mblnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   MOVE-CORRESPONDING  itab_mseg TO itab_final.&lt;/P&gt;&lt;P&gt;**************&lt;/P&gt;&lt;P&gt;   LOOP AT itab_skb1 WHERE bukrs EQ itab_mseg-bukrs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   MOVE-CORRESPONDING itab_skb1 TO itab_final.&lt;/P&gt;&lt;P&gt;*******************&lt;/P&gt;&lt;P&gt; LOOP AT itab_makt WHERE matnr EQ itab_mseg-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  MOVE-CORRESPONDING  itab_makt TO itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CLEAR itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;all the table are with header  line...&lt;/P&gt;&lt;P&gt;if i move the data to main table the value of gl account field SAKNR is same for all the records...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here i need to get different value for saknr for different records and also this is the performance issue please give me the solution for this ......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;babu&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Aeda N on Feb 12, 2008 2:22 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Aeda N on Feb 12, 2008 2:26 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 13:16:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402870#M817093</guid>
      <dc:creator>NAeda</dc:creator>
      <dc:date>2008-02-12T13:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402871#M817094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Why are you using loops within the loops? thats why you get the performance issues. You have to read the tables then assign each feild then append to the final table. It will solve your problem.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sarada&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 13:24:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402871#M817094</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-12T13:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402872#M817095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt; create one more internal table same as itab_final and do this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear itab_mkpf.&lt;/P&gt;&lt;P&gt;LOOP AT itab_mkpf.&lt;/P&gt;&lt;P&gt;read table itab_mseg with key  mblnr = itab_mkpf-mblnr.&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING itab_mseg TO itab_table.&lt;/P&gt;&lt;P&gt;append itab_table.&lt;/P&gt;&lt;P&gt;clear itab_table.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clear itab_table.&lt;/P&gt;&lt;P&gt;loop at itab_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table itab_skb1 with key bukrs = itab_table-bukrs.&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING itab_skb1 TO itab_final.&lt;/P&gt;&lt;P&gt;append itab_final.&lt;/P&gt;&lt;P&gt;clear itab_final.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;*******************&lt;/P&gt;&lt;P&gt;read table itab_makt With key matnr = itab_table-matnr.&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING itab_makt TO itab_final.&lt;/P&gt;&lt;P&gt;append itab_final.&lt;/P&gt;&lt;P&gt;clear itab_final.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i hope it may work for u.&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;ravi shankar reddy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 14:12:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402872#M817095</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-12T14:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402873#M817096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will not get much benefit from using the READ statement unless you add the BINARY SEARCH option to it or use hashed or sorted tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[The  Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 15:15:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402873#M817096</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-12T15:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402874#M817097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nested loops is always a performance issue. use the parallel cursor in such a case. look at the link below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm" target="test_blank"&gt;http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2008 02:40:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402874#M817097</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-13T02:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: nested loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402875#M817098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi babu,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need not to write the loops that many times when you have only single record in each tables. you just read the tables by looping the Item tables.  and also define all the fields in the proper order (Refer D/B tables), so that you can avoid ' INTO CORRESPONDING FIELDS OF ' in Select statements.this is also makes some sense in performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT mblnr mjahr budat &lt;/P&gt;&lt;P&gt;FROM mkpf &lt;/P&gt;&lt;P&gt;INTO TABLE itab_mkpf&lt;/P&gt;&lt;P&gt;WHERE budat IN s_budat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt; sort itab_mkpf by mblnr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: in the below table add SAKTO field also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT bukrs mblnr zeile&lt;/P&gt;&lt;P&gt;bwtar matnr gsber &lt;/P&gt;&lt;P&gt;werks menge meins dmbtr &lt;/P&gt;&lt;P&gt;FROM mseg &lt;/P&gt;&lt;P&gt;INTO TABLE itab_mseg&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN &lt;/P&gt;&lt;P&gt;itab_mkpf WHERE bukrs EQ p_bukrs&lt;/P&gt;&lt;P&gt;AND mblnr EQ itab_mkpf-mblnr &lt;/P&gt;&lt;P&gt;AND gsber IN p_gsber&lt;/P&gt;&lt;P&gt;AND bwtar IN s_bwtar &lt;/P&gt;&lt;P&gt;AND mjahr EQ itab_mkpf-mjahr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt; sort itab_mseg by mblnr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT bukrs saknr&lt;/P&gt;&lt;P&gt;FROM skb1&lt;/P&gt;&lt;P&gt;INTO table itab_skb1 &lt;/P&gt;&lt;P&gt;WHERE bukrs EQ p_bukrs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt; sort itab_skb1 by saknr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT matnr maktx &lt;/P&gt;&lt;P&gt;FROM makt INTO &lt;/P&gt;&lt;P&gt;TABLE itab_makt &lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN itab_mseg &lt;/P&gt;&lt;P&gt;WHERE matnr EQ itab_mseg-matnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt; sort itab_makt by matnr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab_mkpf.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab_mseg with key mblnr = itab_mkpf-mblnr binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING itab_mseg TO itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab_skb1 with key saknr = itab_mseg-mblnr&lt;/P&gt;&lt;P&gt;                                             bukrs = itab_mkpf-SAKTO&lt;/P&gt;&lt;P&gt;                                                         binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING itab_skb1 TO itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab_makt with key matnr = itab_mkpf-matnr binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MOVE-CORRESPONDING itab_makt TO itab_final.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND itab_final.&lt;/P&gt;&lt;P&gt;CLEAR itab_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if itab_final[] is not initial.&lt;/P&gt;&lt;P&gt;sort itab_final by mblnr.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dont forget to Reward, if my solution is solved your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Murali.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2008 03:07:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-loops/m-p/3402875#M817098</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-13T03:07:55Z</dc:date>
    </item>
  </channel>
</rss>

