<?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: Performance tuning the loop statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554883#M582196</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First sort the table by column1... so all records are in sorted form..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
sort ITAB by column1..
read table ITAB with key column1 = 'A'.
l_index = sy-tabix + 1.

read table ITAB index l_index.

if sy-subrc eq 0.
write:/ 'More than 1 record'.
else.
write:/ 'Single record only'.
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if useful&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Prax&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Jul 2007 17:36:46 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-07-20T17:36:46Z</dc:date>
    <item>
      <title>Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554880#M582193</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;I have the following requirement.&lt;/P&gt;&lt;P&gt;I have an internal table IT_TEST1 which has values &lt;/P&gt;&lt;P&gt;Column1&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;C&lt;/P&gt;&lt;P&gt;D&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;consider a second internal table IT_TEST2. It'll have values like as follows:..I need to know which are the entries in column1 that have more than one entry in column 2 without looping through this internal table..Kindly suggest..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Column1 column2&lt;/P&gt;&lt;P&gt;A            VAL1&lt;/P&gt;&lt;P&gt;B            VAL1&lt;/P&gt;&lt;P&gt;B            VAL2&lt;/P&gt;&lt;P&gt;C            VAL1&lt;/P&gt;&lt;P&gt;C            VAL2&lt;/P&gt;&lt;P&gt;D            VAL1&lt;/P&gt;&lt;P&gt;D            VAL2&lt;/P&gt;&lt;P&gt;D            VAL3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This has caused very big performance issue for it is&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2007 13:33:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554880#M582193</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-20T13:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554881#M582194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;  I would suggest do the read with binary serach over second table and then in addition check if thenext entry has the same key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;  READ ITAB2 WITH KEY k = A BINARY SEARCH&lt;/P&gt;&lt;P&gt;  lv _idx = sy-tabix + 1.&lt;/P&gt;&lt;P&gt;  READ ITAB2 INDEX lv _idx.&lt;/P&gt;&lt;P&gt;  ...check if the second record has the same key -- if so you have at least duplicates &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR, Artem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;remember points&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2007 13:37:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554881#M582194</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-20T13:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554882#M582195</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;You can try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Make a temporary internal table and copy IT_TEST2 into this IT_TEMP.&lt;/P&gt;&lt;P&gt;2. Now LOOP AT IT_TEST1&lt;/P&gt;&lt;P&gt;3. READ TABLE IT_TEMP WITH KEY Column1 = IT_TEST1-column1 binary search.&lt;/P&gt;&lt;P&gt;4. DELETE IT_TEMP. This will delete the current entry from IT_TEMP&lt;/P&gt;&lt;P&gt;5. Now again read IT_TEMP. READ TABLE IT_TEMP WITH KEY Column1 = IT_TEST1-column1 binary search.&lt;/P&gt;&lt;P&gt;6. If SY-SUBRC = 0 then you have more than one entry in IT_TEST2.&lt;/P&gt;&lt;P&gt;7. ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2007 17:32:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554882#M582195</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-20T17:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554883#M582196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First sort the table by column1... so all records are in sorted form..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
sort ITAB by column1..
read table ITAB with key column1 = 'A'.
l_index = sy-tabix + 1.

read table ITAB index l_index.

if sy-subrc eq 0.
write:/ 'More than 1 record'.
else.
write:/ 'Single record only'.
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward if useful&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Prax&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jul 2007 17:36:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554883#M582196</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-20T17:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554884#M582197</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;I have faced a similar problem and the following strategy has saved a lot of processing time&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the following code may serve your pupose&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you are using IT_TEST2 for further processing please use IT_TEST3&lt;/P&gt;&lt;P&gt;otherwise use IT_TEST2 instead of IT_TEST3 in the code below......'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*************************&lt;STRONG&gt;CODE SAMPLE&lt;/STRONG&gt;************************************&lt;/P&gt;&lt;P&gt;data : IT_TEST3 like IT_TEST2.  "declare internal table same as IT_TEST2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IT_TEST3[] = IT_TEST2[].  &lt;/P&gt;&lt;P&gt;    "Pass contents if IT_TEST2 is used for further processing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort IT_TEST1 by column1 .  "Sort&lt;/P&gt;&lt;P&gt;Sort IT_TEST3 by column1 .  "Sort&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   loop at IT_TEST1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;           read table IT_TEST3 &lt;/P&gt;&lt;P&gt;                with key column1 = IT_TEST1-column1.&lt;/P&gt;&lt;P&gt;                     &lt;/P&gt;&lt;P&gt;                 if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;                       &lt;/P&gt;&lt;P&gt;                      describle table IT_TEST3 lines n.&lt;/P&gt;&lt;P&gt;                          if lines &amp;gt; 1.&lt;/P&gt;&lt;P&gt;                             "Multiple entries&lt;/P&gt;&lt;P&gt;                           else.&lt;/P&gt;&lt;P&gt;                             "Single entry&lt;/P&gt;&lt;P&gt;                          endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                 endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  "Perform all operations on IT_TEST3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    DELETE IT_TEST3 WHERE  column1 = IT_TEST1-column1.&lt;/P&gt;&lt;P&gt;"Delete the entry in IT_TEST3 already processed with the key of IT_TEST1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Next time you do the read entries for the previous and all predecessor loops&lt;/P&gt;&lt;P&gt; will not be there'&lt;/P&gt;&lt;P&gt;"As you go down the loop performance increases&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;Byju&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Jul 2007 09:47:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554884#M582197</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-21T09:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554885#M582198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think there is not one decent solution to your problem as all use nested loop which will kill your performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I am not sure whether I really understand your problem. To count the number of entries make it necessary to loop over the whole table, therefore you must&lt;/P&gt;&lt;P&gt;loop of table2. But you should not loop inside another loop on table1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I propose precprocessing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;define a hashed table itab3 with key column2 and count&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab2 into wa2.&lt;/P&gt;&lt;P&gt;  read itab3 with table key column2 = wa2-column2.&lt;/P&gt;&lt;P&gt;  if ( sysubrc eq 0 )&lt;/P&gt;&lt;P&gt;    wa3-count = wa3-count + 1.&lt;/P&gt;&lt;P&gt;    modify itab3&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;   insert itab3&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;=&amp;gt; itab3 will tell you how often the values in itab2 appear. It need only one loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then it is very simple to solve your problem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop itab1..&lt;/P&gt;&lt;P&gt;  read itab3&lt;/P&gt;&lt;P&gt;  if ( count &amp;gt; 1 ).&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;Coding is not exactly correct. Please correct, if I did not understand your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Siegfried Boes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 06:12:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554885#M582198</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T06:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Performance tuning the loop statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554886#M582199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the parallel cursor method of looping through the two tables: Read &amp;lt;a href="/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops of Nested Loops&amp;lt;/a&amp;gt;.&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>Fri, 27 Jul 2007 09:15:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-tuning-the-loop-statement/m-p/2554886#M582199</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-27T09:15:51Z</dc:date>
    </item>
  </channel>
</rss>

