<?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 improving loop performance in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573055#M587717</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a nested loop which loops through two itabs. Since there are too many records in both the itabs it is taking too much of time. Could anyone please suggest some ways to improve this code so that it takes less time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Two itabs are itab1 and itab2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab1.&lt;/P&gt;&lt;P&gt;  CLEAR L_TABIX.&lt;/P&gt;&lt;P&gt;  APPEND itab1 TO vsel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  READ TABLE itab2 WITH KEY cuobj = itab1-cuobj binary search.&lt;/P&gt;&lt;P&gt;  IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;        CONTINUE.&lt;/P&gt;&lt;P&gt;  ELSE.&lt;/P&gt;&lt;P&gt;        l_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;        LOOP AT itab2 FROM l_tabix.&lt;/P&gt;&lt;P&gt;          IF itab2-cuobj NE itab1-cuobj.&lt;/P&gt;&lt;P&gt;             EXIT.&lt;/P&gt;&lt;P&gt;          ENDIF.&lt;/P&gt;&lt;P&gt;          READ TABLE ymodes WITH KEY mode = itab2-mode.&lt;/P&gt;&lt;P&gt;          IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;             IF itab2-wtsta NE ' ' AND&lt;/P&gt;&lt;P&gt;                  CLEAR itab2-wtsta.&lt;/P&gt;&lt;P&gt;             ENDIF.&lt;/P&gt;&lt;P&gt;             APPEND itab2 TO wsel.&lt;/P&gt;&lt;P&gt;          ENDIF.&lt;/P&gt;&lt;P&gt;       ENDLOOP.&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;&lt;/P&gt;&lt;P&gt;Regards &lt;/P&gt;&lt;P&gt;Sudha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Jul 2007 06:37:30 GMT</pubDate>
    <dc:creator>sudha_naik</dc:creator>
    <dc:date>2007-07-26T06:37:30Z</dc:date>
    <item>
      <title>improving loop performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573055#M587717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a nested loop which loops through two itabs. Since there are too many records in both the itabs it is taking too much of time. Could anyone please suggest some ways to improve this code so that it takes less time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Two itabs are itab1 and itab2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab1.&lt;/P&gt;&lt;P&gt;  CLEAR L_TABIX.&lt;/P&gt;&lt;P&gt;  APPEND itab1 TO vsel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  READ TABLE itab2 WITH KEY cuobj = itab1-cuobj binary search.&lt;/P&gt;&lt;P&gt;  IF sy-subrc NE 0.&lt;/P&gt;&lt;P&gt;        CONTINUE.&lt;/P&gt;&lt;P&gt;  ELSE.&lt;/P&gt;&lt;P&gt;        l_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;        LOOP AT itab2 FROM l_tabix.&lt;/P&gt;&lt;P&gt;          IF itab2-cuobj NE itab1-cuobj.&lt;/P&gt;&lt;P&gt;             EXIT.&lt;/P&gt;&lt;P&gt;          ENDIF.&lt;/P&gt;&lt;P&gt;          READ TABLE ymodes WITH KEY mode = itab2-mode.&lt;/P&gt;&lt;P&gt;          IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;             IF itab2-wtsta NE ' ' AND&lt;/P&gt;&lt;P&gt;                  CLEAR itab2-wtsta.&lt;/P&gt;&lt;P&gt;             ENDIF.&lt;/P&gt;&lt;P&gt;             APPEND itab2 TO wsel.&lt;/P&gt;&lt;P&gt;          ENDIF.&lt;/P&gt;&lt;P&gt;       ENDLOOP.&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;&lt;/P&gt;&lt;P&gt;Regards &lt;/P&gt;&lt;P&gt;Sudha&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 06:37:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573055#M587717</guid>
      <dc:creator>sudha_naik</dc:creator>
      <dc:date>2007-07-26T06:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: improving loop performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573056#M587718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PLease use the following code if itab1 table use the primare data of cuobj.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;loop at itab1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab 2 where cuobj = itab1-cuobj .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do your necessary steps over here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;endloop.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will definitely improve performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Rewards points if it is useful.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kinjal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 08:17:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573056#M587718</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T08:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: improving loop performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573057#M587719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please check whether you could use a sorted table for itab2, would make your&lt;/P&gt;&lt;P&gt;codingg simpler, but not faster. Onyl then the above loop at where works&lt;/P&gt;&lt;P&gt;performantly. The nested loops are not recommended for standard tables! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a sorted table is not possible, then itab must be sorted outside of loop at itab1,&lt;/P&gt;&lt;P&gt;this is not noted in your example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The rest of your example is o.k., use binary search to find starting point,&lt;/P&gt;&lt;P&gt;loop from index, exit if itab2-cuobj NE itab1-cuobj. &lt;/P&gt;&lt;P&gt;This can not be the problem, maybe you expect to much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How about READ TABLE ymodes WITH KEY mode = itab2-mode,&lt;/P&gt;&lt;P&gt;how large is ymode? If it is more than 20 lines, then it would be a good&lt;/P&gt;&lt;P&gt;idea to have a hashed table here as this read is executed inside the nested loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use SE30 to check the runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 09:27:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573057#M587719</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T09:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: improving loop performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573058#M587720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use binary search for READ TABLE ymodes.&lt;/P&gt;&lt;P&gt;And also cross check wheather itab1, itab2, ymodes are sorted or not with required key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;itab1&amp;lt;/b&amp;gt; may contain multiple records with same &amp;lt;b&amp;gt;cuobj&amp;lt;/b&amp;gt; value. so, in that case same code is processed multiple times for same values. Try to avoid this according to the data present in the tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop at where takes much longer time for tables with large number of records as it reads complete table for each loop pass of the given condition in where clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sankar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 09:32:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573058#M587720</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T09:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: improving loop performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573059#M587721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sankar is right, but you have to careful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't have to sort itab1, the loop processes anyway everything.&lt;/P&gt;&lt;P&gt;Checking for duplicates is probabyl more expensive then the processing&lt;/P&gt;&lt;P&gt;of a few duplicates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfriied&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 12:17:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573059#M587721</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T12:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: improving loop performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573060#M587722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look at the parallel cursor method in &amp;lt;a href="/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops of Nested Loops&amp;lt;/a&amp;gt;. Basically: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;sort ITAB1 and ITAB2 by a key (CUOBJ).
LOOP through ITAB1.
  LOOP through ITAB2 FROM INDEX  XYZ.
    XYZ  =  SY-TABIX.
    IF  ITAB2-KEY  &amp;gt;  ITAB1-KEY.
      EXIT.
    ELSEIF ITAB1-KEY  &amp;gt;  ITAB2-KEY.
      CONTINUE.
    ENDIF.
    your process.
  ENDLOOP.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Additionally sort YMODES and use a BINARY SEARCH for your read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MattG.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jul 2007 12:21:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/improving-loop-performance/m-p/2573060#M587722</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-28T12:21:46Z</dc:date>
    </item>
  </channel>
</rss>

