<?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: Issue with nested loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873716#M1594015</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;The code does look optimized to the best, so not sure on how much value my below suggestion would provide, check it out anyways&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT lt_zquota_item_skip INTO ls_zquota_item_val.
    READ TABLE i_zquota_item2 TRANSPORTING NO FIELDS
    WITH KEY product = ls_zquota_item_val-product
    source = ls_zquota_item_val-source
    destination = ls_zquota_item_val-destination
    BINARY SEARCH.
    IF sy-subrc IS INITIAL.
      v_tabix = sy-tabix.
      LOOP AT i_zquota_item2 INTO wa_zquota_item2 FROM v_tabix
      WHERE product = ls_zquota_item_val-product
      AND source = ls_zquota_item_val-source
      AND destination = ls_zquota_item_val-destination.
        v_tabx2 = sy-tabix.
        APPEND wa_zquota_item2 TO lt_zquota_keep.
        DELETE i_zquota_item2 INDEX v_tabx2.
* Check if the next entry satisfies the key search if not exit the loop.
* index will remain the same as you have deleted the previous entry
        READ TABLE i_zquota_item2 INTO wa_zquota_item2 INDEX v_tabx2.
        IF sy-subrc EQ 0.
          IF wa_zquota_item2-product     EQ ls_zquota_item_val-product AND
             wa_zquota_item2-source      EQ ls_zquota_item_val-source AND
             wa_zquota_item2-destination EQ ls_zquota_item_val-destination.
          ELSE.
            EXIT. "Exit loop - Dont have to validate the remaining recs
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDIF.
    READ TABLE i_zquota_item_val TRANSPORTING NO FIELDS
    WITH KEY product = ls_zquota_item_val-product
    source = ls_zquota_item_val-source
    destination = ls_zquota_item_val-destination
    BINARY SEARCH.
    IF sy-subrc IS INITIAL.
      v_tabix = sy-tabix.
      LOOP AT i_zquota_item_val INTO ls_zquota_item_val FROM v_tabix
      WHERE product = ls_zquota_item_val-product
      AND source = ls_zquota_item_val-source
      AND destination = ls_zquota_item_val-destination.
        DELETE i_zquota_item_val INDEX sy-tabix.
* Similarly for the this loop too, but are you sure you are passing the
* right parameters for the where clause
      ENDLOOP.
    ENDIF.
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 29 Apr 2011 07:38:18 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-04-29T07:38:18Z</dc:date>
    <item>
      <title>Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873715#M1594014</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;There is a nested loop in the program which is causing a performance issue. The first internal table loop contains 6700 entries and the second internal table loop contains more than 5,00,000 entries. Can somebody please have a look at the below code and suggest how i can modify it to avoid the performance issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT lt_zquota_item_skip  INTO ls_zquota_item_val.&lt;/P&gt;&lt;P&gt;        READ TABLE i_zquota_item2 TRANSPORTING NO FIELDS&lt;/P&gt;&lt;P&gt;          WITH KEY product     = ls_zquota_item_val-product&lt;/P&gt;&lt;P&gt;                   source      = ls_zquota_item_val-source&lt;/P&gt;&lt;P&gt;                   destination = ls_zquota_item_val-destination&lt;/P&gt;&lt;P&gt;                   BINARY SEARCH.&lt;/P&gt;&lt;P&gt;        IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;          v_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;          LOOP AT i_zquota_item2 INTO wa_zquota_item2 FROM v_tabix&lt;/P&gt;&lt;P&gt;            WHERE product     = ls_zquota_item_val-product&lt;/P&gt;&lt;P&gt;            AND   source      = ls_zquota_item_val-source&lt;/P&gt;&lt;P&gt;            AND   destination = ls_zquota_item_val-destination.&lt;/P&gt;&lt;P&gt;            v_tabx2 = sy-tabix.&lt;/P&gt;&lt;P&gt;            APPEND wa_zquota_item2 TO lt_zquota_keep.&lt;/P&gt;&lt;P&gt;            DELETE i_zquota_item2 INDEX v_tabx2.&lt;/P&gt;&lt;P&gt;          ENDLOOP.&lt;/P&gt;&lt;P&gt;        ENDIF.&lt;/P&gt;&lt;P&gt;        READ TABLE i_zquota_item_val TRANSPORTING NO FIELDS&lt;/P&gt;&lt;P&gt;          WITH KEY product     = ls_zquota_item_val-product&lt;/P&gt;&lt;P&gt;                   source      = ls_zquota_item_val-source&lt;/P&gt;&lt;P&gt;                   destination = ls_zquota_item_val-destination&lt;/P&gt;&lt;P&gt;                   BINARY SEARCH.&lt;/P&gt;&lt;P&gt;        IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;          v_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;          LOOP AT i_zquota_item_val INTO ls_zquota_item_val FROM v_tabix&lt;/P&gt;&lt;P&gt;            WHERE product     = ls_zquota_item_val-product&lt;/P&gt;&lt;P&gt;            AND   source      = ls_zquota_item_val-source&lt;/P&gt;&lt;P&gt;            AND   destination = ls_zquota_item_val-destination.&lt;/P&gt;&lt;P&gt;            DELETE i_zquota_item_val INDEX sy-tabix.&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 07:04:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873715#M1594014</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-29T07:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873716#M1594015</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;The code does look optimized to the best, so not sure on how much value my below suggestion would provide, check it out anyways&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT lt_zquota_item_skip INTO ls_zquota_item_val.
    READ TABLE i_zquota_item2 TRANSPORTING NO FIELDS
    WITH KEY product = ls_zquota_item_val-product
    source = ls_zquota_item_val-source
    destination = ls_zquota_item_val-destination
    BINARY SEARCH.
    IF sy-subrc IS INITIAL.
      v_tabix = sy-tabix.
      LOOP AT i_zquota_item2 INTO wa_zquota_item2 FROM v_tabix
      WHERE product = ls_zquota_item_val-product
      AND source = ls_zquota_item_val-source
      AND destination = ls_zquota_item_val-destination.
        v_tabx2 = sy-tabix.
        APPEND wa_zquota_item2 TO lt_zquota_keep.
        DELETE i_zquota_item2 INDEX v_tabx2.
* Check if the next entry satisfies the key search if not exit the loop.
* index will remain the same as you have deleted the previous entry
        READ TABLE i_zquota_item2 INTO wa_zquota_item2 INDEX v_tabx2.
        IF sy-subrc EQ 0.
          IF wa_zquota_item2-product     EQ ls_zquota_item_val-product AND
             wa_zquota_item2-source      EQ ls_zquota_item_val-source AND
             wa_zquota_item2-destination EQ ls_zquota_item_val-destination.
          ELSE.
            EXIT. "Exit loop - Dont have to validate the remaining recs
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDIF.
    READ TABLE i_zquota_item_val TRANSPORTING NO FIELDS
    WITH KEY product = ls_zquota_item_val-product
    source = ls_zquota_item_val-source
    destination = ls_zquota_item_val-destination
    BINARY SEARCH.
    IF sy-subrc IS INITIAL.
      v_tabix = sy-tabix.
      LOOP AT i_zquota_item_val INTO ls_zquota_item_val FROM v_tabix
      WHERE product = ls_zquota_item_val-product
      AND source = ls_zquota_item_val-source
      AND destination = ls_zquota_item_val-destination.
        DELETE i_zquota_item_val INDEX sy-tabix.
* Similarly for the this loop too, but are you sure you are passing the
* right parameters for the where clause
      ENDLOOP.
    ENDIF.
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 07:38:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873716#M1594015</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-29T07:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873717#M1594016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Benjamin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remove where clause&lt;/P&gt;&lt;P&gt;--WHERE product = ls_zquota_item_val-product&lt;/P&gt;&lt;P&gt;AND source = ls_zquota_item_val-source&lt;/P&gt;&lt;P&gt;AND destination = ls_zquota_item_val-destination--&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from loop and exit where there is mismatch in the values for product or source or destination. Also remember to set the value for v_tabix when exiting form the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT i_zquota_item2 INTO wa_zquota_item2 FROM v_tabix&lt;/P&gt;&lt;P&gt;if wa_zquota_item2-product &amp;lt;&amp;gt; ls_zquota_item_val-product&lt;/P&gt;&lt;P&gt;OR wa_zquota_item2-source &amp;lt;&amp;gt; ls_zquota_item_val-source&lt;/P&gt;&lt;P&gt;OR wa_zquota_item2-destination &amp;lt;&amp;gt; ls_zquota_item_val-destination.&lt;/P&gt;&lt;P&gt;EXIT.&lt;/P&gt;&lt;P&gt;ENDIF.&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;Shyam.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 07:39:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873717#M1594016</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-29T07:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873718#M1594017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Shyam has given you the right direction with his post above.&lt;/P&gt;&lt;P&gt;Here is the complete piece of code with the changes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

LOOP AT lt_zquota_item_skip INTO ls_zquota_item_val.

  READ TABLE i_zquota_item2 TRANSPORTING NO FIELDS
    WITH KEY product = ls_zquota_item_val-product
             source = ls_zquota_item_val-source
             destination = ls_zquota_item_val-destination
    BINARY SEARCH.

  IF sy-subrc IS INITIAL.
    v_tabix = sy-tabix.
    LOOP AT i_zquota_item2 INTO wa_zquota_item2 FROM v_tabix.
      if ( wa_zquota_item2-product NE ls_zquota_item_val-product ) OR
         ( wa_zquota_item2-source NE ls_zquota_item_val-source) OR
         ( wa_zquota_item2-destination NE ls_zquota_item_val-destination )
        exit.
      endif.

      APPEND wa_zquota_item2 TO lt_zquota_keep.
      DELETE i_zquota_item2. "index specification not necessary in loop

* v_tabx2 = sy-tabix. "commented out as I don't see the usage reason
    ENDLOOP.
  ENDIF.

  READ TABLE i_zquota_item_val TRANSPORTING NO FIELDS
    WITH KEY product = ls_zquota_item_val-product
             source = ls_zquota_item_val-source
             destination = ls_zquota_item_val-destination
    BINARY SEARCH.

  IF sy-subrc IS INITIAL.
    v_tabix = sy-tabix.
    LOOP AT i_zquota_item_val INTO ls_zquota_item_val FROM v_tabix.
      if ( ls_zquota_item_val-product NE ls_zquota_item_val-product ) OR
         ( ls_zquota_item_val-source NE ls_zquota_item_val-source) OR
         ( ls_zquota_item_val-destination NE ls_zquota_item_val-destination )
        exit.
      endif.
      DELETE i_zquota_item_val. "index specification not necessary in loop
    ENDLOOP.
  ENDIF.

ENDLOOP. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Yuri Ziryukin on Apr 29, 2011 11:23 AM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Yuri Ziryukin on Apr 29, 2011 11:25 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Apr 2011 09:22:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873718#M1594017</guid>
      <dc:creator>yuri_ziryukin</dc:creator>
      <dc:date>2011-04-29T09:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873719#M1594018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the release of your system? If newer than 6.2, then the solution is much much simpler:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use a sorted table and write a DELETE WHERE .... then you save READ BINARY, LOOP, EXIT it is all done for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without the exit there is of course no optimization at all, the entry is found fast, the improvement is a factor 2.&lt;/P&gt;&lt;P&gt;With exit you move from linear scaling to logarithmic scaling.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All explained 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;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2011 08:30:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873719#M1594018</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-02T08:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873720#M1594019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Siegfried,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the idea of the original code is not only to delete entries, but also to collect them into another internal table (see: APPEND wa_zquota_item2 TO lt_zquota_keep.)&lt;/P&gt;&lt;P&gt;It means that he cannot simply use the delete for a sorted table and get rid of all loops, etc. Loop has to be done anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing that can be spared is the IF comparison to exit the loop. If the table is defined as sorted, he can indeed use loop at ... where ... .&lt;/P&gt;&lt;P&gt;But who knows if this table can really be defined as a sorted table. Maybe he uses it in several places of code with the different sort order. We cannot be sure. &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;  Yuri&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2011 08:43:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873720#M1594019</guid>
      <dc:creator>yuri_ziryukin</dc:creator>
      <dc:date>2011-05-02T08:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873721#M1594020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use the hased internal table and then instead of loop .... endloop.&lt;/P&gt;&lt;P&gt;You can use do --endo inside that it there will read table and exit..&lt;/P&gt;&lt;P&gt;may solve your problems.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 12:10:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873721#M1594020</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-20T12:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873722#M1594021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Despite reading the full code in detail, I can comment on that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;You can use the hased internal table and then instead of loop .... endloop.&lt;/P&gt;&lt;P&gt;LOOP and hashed table do not really fit together, hashed tables should only be used if there is a unique key and if you address records with the full unique key. That means you work on single records, i.e with READs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 13:57:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873722#M1594021</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-20T13:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873723#M1594022</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;Another solution would be to use only sorted tables, which are quite good for solving those kind of issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it's possible, try to define your 2 main tables this way (I'm using DATA, it could  of course be some kind of parameter )&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: i_zquota_item2 TYPE SORTED TABLE OF ty_s_zquota_item2 
                     WITH NON-UNIQUE KEY product source  destination,
      i_zquota_item_val TYPE SORTED TABLE OF ty_s_zquota_item_val
                     WITH NON-UNIQUE KEY product source destination.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, you could simplify your program like that:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  LOOP AT lt_zquota_item_skip INTO ls_zquota_item_val.

    LOOP AT i_zquota_item2 INTO wa_zquota_item2  WHERE product     = ls_zquota_item_val-product
                                                   AND source      = ls_zquota_item_val-source
                                                   AND destination = ls_zquota_item_val-destination.
      APPEND wa_zquota_item2 TO lt_zquota_keep.
    ENDLOOP.

    DELETE i_zquota_item_val
       WHERE product     = ls_zquota_item_val-product
         AND source      = ls_zquota_item_val-source
         AND destination = ls_zquota_item_val-destination.
  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 May 2011 13:14:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873723#M1594022</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-05-24T13:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873724#M1594023</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;Here's an angle that (surprisingly) no one has mentioned yet: doing multiple DELETEs on a large internal table (esp. 5 million entries!) is &lt;STRONG&gt;very&lt;/STRONG&gt; expensive.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rather than doing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab &lt;/P&gt;&lt;P&gt;    where f1  = &amp;lt;something&amp;gt;&lt;/P&gt;&lt;P&gt;   delete itab.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab &lt;/P&gt;&lt;P&gt;    where f1  &amp;lt;&amp;gt; &amp;lt;something&amp;gt;&lt;/P&gt;&lt;P&gt;   append itab to itab_filtered.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;replace the original table with the filtered table&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;itab[] = itab_filtered[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;.. and your performance problems will disappear like snow on the equator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jun 2011 01:39:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873724#M1594023</guid>
      <dc:creator>paul_bakker2</dc:creator>
      <dc:date>2011-06-28T01:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873725#M1594024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Paul,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first of all, performance of delete statement practically DOES NOT depend on the size of the table.&lt;/P&gt;&lt;P&gt;Here is my test:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Statement	Executions		Net time		time per row
Delete LT_INDEX	314.575			343.429			1,091723754
Delete LT_INDEX	2.202.025		2.409.981		1,094438528
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First delete is on the table with 316.000 records&lt;/P&gt;&lt;P&gt;Second delete is on the table with around 2.250.000 records.&lt;/P&gt;&lt;P&gt;Time per row is absolutely identical.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, your approach is not always applicable. What you advise is actually make fewer loop passes and delete actions. This does not work when:&lt;/P&gt;&lt;P&gt;a) you have to do something with the records left in the table after deletion. And this might be the case here, as we don't see what happens with i_zquota_item2 after the main loop.&lt;/P&gt;&lt;P&gt;b) in your proposal "loop at itab where f1 &amp;lt;something&amp;gt;", this &amp;lt;something&amp;gt; will change. For example, if I want to throw out all values where field A = 'X', after rewriting the code according to your proposal, one will have to make LOOP AT ... WHERE FIELD_A NE 'X'.&lt;/P&gt;&lt;P&gt;As you can imagine, this may destroy the performance improvement if you work with sorted table in the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, you have to see first if your "magic" improvement is applicable here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;  Yuri&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Jun 2011 07:24:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873725#M1594024</guid>
      <dc:creator>yuri_ziryukin</dc:creator>
      <dc:date>2011-06-28T07:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873726#M1594025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yuri,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for that.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was shocked to see your test results, so I tried some of my own... and you are right!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had discovered quite a few years ago that DELETE was an expensive operation, and I have been using that assumption ever since. In my notes, I even recorded a quote from SAP Help at the time:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Any operations that insert into, or delete from, internal tables come at a certain cost because the index has to be updated. The amount of time needed for this &lt;STRONG&gt;increases proportionally&lt;/STRONG&gt; according to the number of lines that remain after the insert or delete position. Any changes you make at the beginning of the table thus require more runtime than changes at the end of the table. &lt;/P&gt;&lt;P&gt;The line width of the table is of no consequence in this context"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this still true? No. I can no longer find this quote in SAP Help, and the DELETE command no longer seems to have this overhead. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps it was a recent improvement - we are on ECC 6.0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Jun 2011 04:04:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873726#M1594025</guid>
      <dc:creator>paul_bakker2</dc:creator>
      <dc:date>2011-06-29T04:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873727#M1594026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; "Any operations that insert into, or delete from, internal tables come at a certain cost because the index has to be updated. The amount of time needed for this &lt;STRONG&gt;increases proportionally&lt;/STRONG&gt; according to the number of lines that remain after the insert or delete position. Any changes you make at the beginning of the table thus require more runtime than changes at the end of the table. &lt;/P&gt;&lt;P&gt;&amp;gt; The line width of the table is of no consequence in this context"&lt;/P&gt;&lt;P&gt;&amp;gt; Is this still true? No. I can no longer find this quote in SAP Help, and the DELETE command no longer seems to have this overhead. &lt;/P&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it IS still true, but not very important any more. What is described above is a linear index. This index is only used for small tables up to a certain size. Then the system switches to a tree-like index. Once we have that, the copy costs in the index only occur at leaf level.&lt;/P&gt;&lt;P&gt;That's why it is not very important anymore. Im not sure when this tree like index was introduced. The quote from above sounds from times before we had that tree like index structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can finde some description about it here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sap-press.de/download/dateien/1880/sappress_abap_performance_tuning.pdf" target="test_blank"&gt;http://www.sap-press.de/download/dateien/1880/sappress_abap_performance_tuning.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Jun 2011 06:54:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873727#M1594026</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2011-06-29T06:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with nested loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873728#M1594027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Herman, that clears it up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have your book here - I should read it more carefully!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Jun 2011 01:49:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/issue-with-nested-loop/m-p/7873728#M1594027</guid>
      <dc:creator>paul_bakker2</dc:creator>
      <dc:date>2011-06-30T01:49:32Z</dc:date>
    </item>
  </channel>
</rss>

