<?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: Read table binary search vs indexed loop inside loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128724#M1189043</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I does not really matter how you call it,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab1
  LOOP AT sort2 WHERE 
  ENDLOOP.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is the simpelst solution for your task, and it is as good in performance as any other&lt;/P&gt;&lt;P&gt;solution, see blog&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab1
   READ TABLE itab2 .... BINARY SEARCH.
   idx2 = sy-tabix.

   LOOP AT itab2 FROM idx2.
      IF ( condition .... not fullfilled).
        EXIT.
      ENDIF.
   ENDLOOP.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can always read recommendations such as 'Avoid nested loop', but they are as useful&lt;/P&gt;&lt;P&gt;as recommendation 'Avoid eating, the food can be poisoned'.  Either you must compare the tables are you don't have to compare them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no fundatmental difference between a READ inside a LOOP and a LOOP with a condition inside a LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Jan 2009 14:16:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-01-27T14:16:51Z</dc:date>
    <item>
      <title>Read table binary search vs indexed loop inside loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128720#M1189039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;it1 entries 70k  (internal table)&lt;/P&gt;&lt;P&gt;it2 entries 150k (it1 to it2, 1 to n )&lt;/P&gt;&lt;P&gt;it3 entries 70k    (it1 to it3, 1 to 1 )&lt;/P&gt;&lt;P&gt;it4 entries 70k (it1 to it4, 1 to 1 )&lt;/P&gt;&lt;P&gt;it5 entries 150k (it2 to it5,  1 to 1 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. is it better to loop through it1 and then loop through it2 using indexed loop. then further read stmt with binary search on 1 to 1 relationship table inside indexed loop.&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;2. it is better to loop through it2 and then use read using binari search on each table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which one is better performance wise.&lt;/P&gt;&lt;P&gt;I appreciate any reply on tyhe same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mani&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Mani on Jan 26, 2009 7:21 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2009 00:21:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128720#M1189039</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-27T00:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read table binary search vs indexed loop inside loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128721#M1189040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in my point of view first one is good.&lt;/P&gt;&lt;P&gt;also sort the table before binary search other wise it wiil not increas performance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2009 06:32:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128721#M1189040</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-27T06:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Read table binary search vs indexed loop inside loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128722#M1189041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;+ Use sorted tables! &lt;/P&gt;&lt;P&gt;    With standard tables it is possible but more complicated,&lt;/P&gt;&lt;P&gt;        read the blog&lt;/P&gt;&lt;P&gt;           Measurements on internal tables: Reads and Loops:&lt;/P&gt;&lt;P&gt;           /people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+  get a structure like this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab1
   LOOP   AT   itab2  WHERE key1 = wa1-key
   ....
   ENDLOOP.

   READ TABLE itab3 WITH key = wa1-key.

   LOOP   AT   itab4  WHERE key1 = wa1-key
   ....
   ENDLOOP.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not more than two loops should be open.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2009 07:50:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128722#M1189041</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-27T07:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Read table binary search vs indexed loop inside loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128723#M1189042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I might be in need of this but i am using like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab1&lt;/P&gt;&lt;P&gt;   read table &amp;lt;it3&amp;gt; with key &amp;lt;field&amp;gt; binary search&lt;/P&gt;&lt;P&gt;   read table &amp;lt;it4&amp;gt; with key &amp;lt;field&amp;gt; binary search.&lt;/P&gt;&lt;P&gt;   read table &amp;lt;it2&amp;gt;  with key &amp;lt;field&amp;gt; binary search.&lt;/P&gt;&lt;P&gt;   indexofit = sy-tabix.&lt;/P&gt;&lt;P&gt;   while exit is true.&lt;/P&gt;&lt;P&gt;   read table &amp;lt;it2&amp;gt; with index indexofit.&lt;/P&gt;&lt;P&gt;   check if conditions met or exit from this while loop.&lt;/P&gt;&lt;P&gt;   read table &amp;lt;it5&amp;gt; with key &amp;lt;field&amp;gt; binary search.&lt;/P&gt;&lt;P&gt;   create final table from all entries in it1, it2, it3, it4,it5.&lt;/P&gt;&lt;P&gt;   endwhile.&lt;/P&gt;&lt;P&gt;   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  i think ur looping as below is called nested loop but above one is called indexed loop.&lt;/P&gt;&lt;P&gt;   LOOP   AT   itab2  WHERE key1 = wa1-key&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;   READ TABLE itab3 WITH key = wa1-key.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;   LOOP   AT   itab4  WHERE key1 = wa1-key&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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;actually i want to avoid loop(or indexed loop) inside loop. So according to you nested loop or Indexed loop are better than to loop on big table then read with binary right???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mani&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2009 14:04:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128723#M1189042</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-27T14:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read table binary search vs indexed loop inside loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128724#M1189043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I does not really matter how you call it,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab1
  LOOP AT sort2 WHERE 
  ENDLOOP.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is the simpelst solution for your task, and it is as good in performance as any other&lt;/P&gt;&lt;P&gt;solution, see blog&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT itab1
   READ TABLE itab2 .... BINARY SEARCH.
   idx2 = sy-tabix.

   LOOP AT itab2 FROM idx2.
      IF ( condition .... not fullfilled).
        EXIT.
      ENDIF.
   ENDLOOP.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can always read recommendations such as 'Avoid nested loop', but they are as useful&lt;/P&gt;&lt;P&gt;as recommendation 'Avoid eating, the food can be poisoned'.  Either you must compare the tables are you don't have to compare them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no fundatmental difference between a READ inside a LOOP and a LOOP with a condition inside a LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2009 14:16:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-binary-search-vs-indexed-loop-inside-loop/m-p/5128724#M1189043</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-01-27T14:16:51Z</dc:date>
    </item>
  </channel>
</rss>

