<?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: Reg: Loop in a loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643495#M1284352</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 use the parallel processing logic to avoid the performance issue &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.

  LOOP AT t_likp INTO likp.
   READ TABLE t_likp INTO likp WITH KEY VBELN = likp-VBELN BINARY SEARCH
   IF  SY-SUBRC EQ 0.
   LOOP AT t_lips INTO lips FROM sy-tabix.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
ENDIF.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 May 2009 08:32:45 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-05-15T08:32:45Z</dc:date>
    <item>
      <title>Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643483#M1284340</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;   I have a requirement which requires a loop in a loop, but the loop in a loop creating the performance issues. i need to avoid the nesting loops. Is there any other way which will avoid loop in a loop.please help in this regard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Harita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:36:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643483#M1284340</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643484#M1284341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if you can explain the scenario or send some sample code we can lokk into it for the solution&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:38:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643484#M1284341</guid>
      <dc:creator>former_member242255</dc:creator>
      <dc:date>2009-05-14T12:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643485#M1284342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sriharita,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop on item table and based on the condition READ TABLE of header with the BINARY SEARCH addition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the way to avoid loop in a loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ex &lt;/P&gt;&lt;P&gt;sort i_vbak by vbeln.&lt;/P&gt;&lt;P&gt;loop at i_vbap into wa_vbap.&lt;/P&gt;&lt;P&gt;read table i_vbak into wa_vbak with key vbeln = wa_vbap-vbeln BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Suvendu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:42:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643485#M1284342</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643486#M1284343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might be possible to create a JOIN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, it is not always said that LOOP within a LOOP can cause performance problems. This depends on the volume of both internal tables and how they are declared. For instance, when you create an internal SORTED table with UNIQUE KEY(S).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:45:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643486#M1284343</guid>
      <dc:creator>Sm1tje</dc:creator>
      <dc:date>2009-05-14T12:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643487#M1284344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;once case is chk if the loop is being exceuted again for a same record. if the loop is being repeated for the same record for a second time, u can skip this record by writing continue statement.if u can be more clear on the req, it would be helpful to answer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:45:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643487#M1284344</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643488#M1284345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sriharitha,&lt;/P&gt;&lt;P&gt;  i Think you are talking about Nested Loops, This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:47:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643488#M1284345</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643489#M1284346</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;it is possible....&lt;/P&gt;&lt;P&gt;give us the code which you have written within loop inside a loop...&lt;/P&gt;&lt;P&gt;will modify it and let u know...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Siddarth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:48:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643489#M1284346</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643490#M1284347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Follow the example given below and it will save the performance and execution time:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nested Loop using Parallel Cursor:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  zparallel_cursor2.

TABLES:
  likp,
  lips.

DATA:
  t_likp  TYPE TABLE OF likp,
  t_lips  TYPE TABLE OF lips.

DATA:
  w_runtime1 TYPE i,
  w_runtime2 TYPE i,
  w_index LIKE sy-index.

START-OF-SELECTION.
  SELECT *
    FROM likp
    INTO TABLE t_likp.

  SELECT *
    FROM lips
    INTO TABLE t_lips.

  GET RUN TIME FIELD w_runtime1.
  SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.

  LOOP AT t_likp INTO likp.

    LOOP AT t_lips INTO lips FROM w_index.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

  GET RUN TIME FIELD w_runtime2.

  w_runtime2 = w_runtime2 - w_runtime1.

  WRITE w_runtime2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:49:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643490#M1284347</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643491#M1284348</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; your problem is not clear ...well in my understanding:Usually we use Read statment instead of Loop&lt;/P&gt;&lt;P&gt;like\&lt;/P&gt;&lt;P&gt;loop gt into gs.&lt;/P&gt;&lt;P&gt; read ....&lt;/P&gt;&lt;P&gt;&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;or you can use loop inside another loop with condition where.. if you give the conditons in the second loop with maximum key fields .. it will act as a read statment.**..&lt;/P&gt;&lt;P&gt;but in some cases we cannot avoid nested loops to satisfy the requirment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;safel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:50:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643491#M1284348</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T12:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643492#M1284349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For each record in the first table you want to read the every record from the second table.&lt;/P&gt;&lt;P&gt;In this we need to go for the loop inside the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you think logically we can avoid it by combining them all entries into one internal table while fetching.&lt;/P&gt;&lt;P&gt;It looks much complex when compare with what you are doing now.&lt;/P&gt;&lt;P&gt;But its always better solution to avoid the loop in side the loop.&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;Write two select queries for the two tables and before comparing the entries with loop in side the loop,&lt;/P&gt;&lt;P&gt;You can move all these two table entries into one more internal table with one extra field for flag. This needs to be add much coding. Try to go with first one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Naveen Inuganti.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 12:54:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643492#M1284349</guid>
      <dc:creator>naveen_inuganti2</dc:creator>
      <dc:date>2009-05-14T12:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643493#M1284350</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;Sometimes loop inside loop cannot be avoided,as per requirements. If that is the case with you, you have to use them in a proper manner to enhance performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have to first read the other internal table on which you are putting loop and then use loop at itab2 from sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sharath&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2009 13:25:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643493#M1284350</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-14T13:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643494#M1284351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;your loop in loop can occur due to 2 requirements &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. one is to get a single value from the inner loop&lt;/P&gt;&lt;P&gt;2. is to get multiple records from a table ( in a header and item table case )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the first case i think you can uses &lt;/P&gt;&lt;P&gt;read table statement with a binary search ( remember the itab should be sorted accordingly)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on the other case you can use the below way&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.
 
  LOOP AT t_likp INTO likp.
 
    LOOP AT t_lips INTO lips FROM w_index.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here are some interesting links on this &lt;/P&gt;&lt;P&gt;[/people/rob.burbank/blog/2006/11/16/performance--what-will-kill-you-and-what-will-leave-you-with-only-a-flesh-wound|/people/rob.burbank/blog/2006/11/16/performance--what-will-kill-you-and-what-will-leave-you-with-only-a-flesh-wound]&lt;/P&gt;&lt;P&gt;if you check some &lt;/P&gt;&lt;P&gt;[ &lt;A href="http://nafran.blogspot.com/search/label/performance|http://nafran.blogspot.com/search/label/performance]" target="test_blank"&gt;http://nafran.blogspot.com/search/label/performance|http://nafran.blogspot.com/search/label/performance]&lt;/A&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Nafran Shiraz on May 15, 2009 10:07 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 08:05:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643494#M1284351</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T08:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reg: Loop in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643495#M1284352</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 use the parallel processing logic to avoid the performance issue &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.

  LOOP AT t_likp INTO likp.
   READ TABLE t_likp INTO likp WITH KEY VBELN = likp-VBELN BINARY SEARCH
   IF  SY-SUBRC EQ 0.
   LOOP AT t_lips INTO lips FROM sy-tabix.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
ENDIF.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 08:32:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reg-loop-in-a-loop/m-p/5643495#M1284352</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T08:32:45Z</dc:date>
    </item>
  </channel>
</rss>

