<?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: LOOP and Inner LOOP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221602#M1379222</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; How would I get multiple occurrences where the conditions are the same - meaning 3 record in INNER that have the same key as shown in the WHERE clause?&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You read the first occurence using a binary search and then get the next records by increasing the index and getting the next record(s).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See [The Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]. It's kind of dated, but it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Sep 2009 18:21:42 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-09-25T18:21:42Z</dc:date>
    <item>
      <title>LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221593#M1379213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Is one of these faster than the other?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: Outer_tab type table of some_type.&lt;/P&gt;&lt;P&gt;data: Inner_tab type table of some_other_type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP at Outer_Tab into some_struct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SORT Inner_tab by some_cond some_cond2.&lt;/P&gt;&lt;P&gt;  LOOP at Inner_Tab WHERE some_cond = Outer_TAB-some_cond&lt;/P&gt;&lt;P&gt;                                  AND some_comd2 = Outer_Tab-some_cond2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; some logic here&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; ENDLOOP.  " Inner&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP. "Outer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: Outer_tab type table of some_type.&lt;/P&gt;&lt;P&gt;data: Inner_tab type SORTED table of some_other_type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP at Outer_Tab into some_struct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP at Inner_Tab WHERE some_cond = Outer_TAB-some_cond&lt;/P&gt;&lt;P&gt;                                  AND some_comd2 = Outer_Tab-some_cond2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; some logic here&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; ENDLOOP.  " Inner&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP. "Outer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am curious if the SORTED table prevents a full table access to the INNER_Tab - and if the STANDARD table does not prevent it and it compares ALL records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;Moderator message - Moved to the correct forum&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Sep 25, 2009 2:10 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 17:11:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221593#M1379213</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T17:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221594#M1379214</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;If you use the SORTED table you'll improve the performance, but this table has to have the fields used in WHERE condition as fields for sort criteria&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 17:21:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221594#M1379214</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T17:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221595#M1379215</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;Using sorted table i,e the second method is better compared to the first one. By using SORTED TABLE, when ever records are added into the internal table, immediately they will be sorted. This will increase the performance particularly when you use where condition in the loop of the sorted internal table. &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;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 17:28:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221595#M1379215</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T17:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221596#M1379216</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;Using SORT table however increases the performance. When considering with LOOp and Endloop, seems to have the nested loop.  Never use loop inside another loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at outer_table.&lt;/P&gt;&lt;P&gt;Use Read Table inner_table with key field = outer_table-field.&lt;/P&gt;&lt;P&gt; if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; few... required.. steps&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;Thanks,&lt;/P&gt;&lt;P&gt;Prasad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 17:58:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221596#M1379216</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T17:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221597#M1379217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Prasad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your statement would be correct if I needed one and only one record from the INNER table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in my case, there are many records that match the WHERE condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your statement is a good policy for unique record situations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 18:06:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221597#M1379217</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T18:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221598#M1379218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Both examples are bad.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can get all records using only READs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally, there are other options for the LOOP statement that you can use to increase performance if you don't want sorted or hashed tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Sep 25, 2009 2:11 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 18:10:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221598#M1379218</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T18:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221599#M1379219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"You can get all records using only READs."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How would I get multiple occurrences where the conditions are the same - meaning 3 record in INNER that have the same key as shown in the WHERE clause?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 18:15:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221599#M1379219</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T18:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221600#M1379220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there exists a many:many relationship between the two internal tables records, dont you think nested loops are unavoidable? Is there anyway to avoid nested loops in such scenarios since read table will only pick one value. How is it possible with a loop and a read statement alone?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 18:16:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221600#M1379220</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T18:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221601#M1379221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Vik,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Exactly my question.... nicely stated by you.  Good job.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 18:19:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221601#M1379221</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T18:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221602#M1379222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; How would I get multiple occurrences where the conditions are the same - meaning 3 record in INNER that have the same key as shown in the WHERE clause?&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You read the first occurence using a binary search and then get the next records by increasing the index and getting the next record(s).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See [The Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]. It's kind of dated, but it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2009 18:21:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221602#M1379222</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-25T18:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221603#M1379223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good one Rob..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We can use the index read instead of nested loop. However i guess it is more useful in case we have expectation of large volume of records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Amit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Sep 2009 05:49:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221603#M1379223</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-28T05:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221604#M1379224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John. In situations like this, instead of being curious you can just read the Help. Contrary to popular belief, it can be quite helpful:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is always required. 

If you are working with a SORTED TABLE, the partial sequential processing can be optimized so that only the entries that actually satisfy the WHERE condition are processed. 
This optimization requires that each sub-condition is linked with AND; that no parentheses are used; that at least one sub-condition is in the form k = v; and that the conditions in the form k1 = v1 ... kn = vn cover at least the first part of the table key.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, your 1st example (standard table) will make a full table scan. Your 2nd example (sorted table) would be optimized (so no nead to replace it by READ), provided you define the key correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you &lt;EM&gt;do&lt;/EM&gt; use READ then you can use a standard table, because you can force BINARY SEARCH explicitly. However, you &lt;STRONG&gt;&lt;U&gt;must not&lt;/U&gt;&lt;/STRONG&gt;, of course, make the SORT inside the LOOP as you have in your code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP at Outer_Tab into some_struct.

  SORT Inner_tab by some_cond some_cond2.         "&amp;lt;&amp;lt; this should go before the LOOP  
      LOOP at Inner_Tab WHERE some_cond = Outer_TAB-some_cond    
                                  AND some_comd2 = Outer_Tab-some_cond2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Sep 2009 08:35:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221604#M1379224</guid>
      <dc:creator>Rui_Dantas</dc:creator>
      <dc:date>2009-09-28T08:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221605#M1379225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;there is a solution with the standard table and the LOOP WHERE which is based on READ BINARY SEARCH LOOP FROM INDEX,&lt;/P&gt;&lt;P&gt;see here&lt;/P&gt;&lt;P&gt;&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;The same thing what is done here manually is done by the SORTED TABLE automatically, but be aware not in all old releases!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*The LOOP with READ is as bad as the Nested Loop if no BINARY SEARCH is used !!! * This is not so hard too understand, but recommended so often.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course the SORT MUST be done once, i.e. not inside the LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In rare cases where the LOOP has condition other than '=', only the manual optimization works, the SORTED table is then not optimized!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Sep 2009 08:54:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221605#M1379225</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-28T08:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221606#M1379226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;if your to internal table satisfy the bellow requirements&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To use this following should be true&lt;/P&gt;&lt;P&gt;1)      Both tables should be sorted with the same key ( in the above case field1 and field2 )&lt;/P&gt;&lt;P&gt;2)      The mapping between primary to secondary tables should be&lt;/P&gt;&lt;P&gt;a.       one to many ( for one record in primary there are multiple records in secondary )&lt;/P&gt;&lt;P&gt;b.      one to one (for one record in primary there is only one in secondary )&lt;/P&gt;&lt;P&gt;Please note that other than the above 2 other 2 scenarios (many to many &amp;amp; many to one) will not work with the above logic and make sure you donu2019t use in such case.&lt;/P&gt;&lt;P&gt;3)      The secondary table should not contain a record which does not map to the primary table ( this will not happen if the secondary is fetched using for all entries from primary )&lt;/P&gt;&lt;P&gt;4)      Please make sure you do not delete any record from primary before using the logic which will make the point 3 false  &lt;/P&gt;&lt;P&gt;5)      If you were to use a 'AND' in where statement of the inner loop you should use or in the inner loop if condition in the above logic.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then you can use the&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Loop AT i_primary into wa_primary.

Loop AT i_secondary into wa_secondary from lv_index.
If ( wa_primary-field1 NE wa_secondary-field1 ) or
( wa_primary-field2 NE wa_secondary-field2 ).
Lv_index = sy-tabix.
Endif.
u201C your code comes here u201C
Endloop.
Endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which is very fast i have check it in most of the reports gave performance issues&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can check the link for detail&lt;/P&gt;&lt;P&gt;[http://nafran.blogspot.com/2009/09/when-and-where-we-can-use-parallel.html|http://nafran.blogspot.com/2009/09/when-and-where-we-can-use-parallel.html]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[ &lt;A href="http://nafran.blogspot.com/2009/05/best-way-to-code-nested-loops-sap.html|http://nafran.blogspot.com/2009/05/best-way-to-code-nested-loops-sap.html]" target="test_blank"&gt;http://nafran.blogspot.com/2009/05/best-way-to-code-nested-loops-sap.html|http://nafran.blogspot.com/2009/05/best-way-to-code-nested-loops-sap.html]&lt;/A&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Sep 2009 06:10:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221606#M1379226</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-29T06:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP and Inner LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221607#M1379227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;don't use sort command within the loop.&lt;/P&gt;&lt;P&gt;use it before making loop within loop...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;its better u use read table command within loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks and regards&lt;/P&gt;&lt;P&gt;dhruv&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Sep 2009 08:14:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-and-inner-loop/m-p/6221607#M1379227</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-29T08:14:58Z</dc:date>
    </item>
  </channel>
</rss>

