<?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: Delete in loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621342#M872411</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;describe table t_tab lines w_lines.&lt;/P&gt;&lt;P&gt;if w_int lt w_lines.&lt;/P&gt;&lt;P&gt;Read table t_tab with index w_int.&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;  delete t_tab from fs_tab.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;w_int = w_int + 1.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;I hope it will help u.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Mar 2008 11:31:00 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-20T11:31:00Z</dc:date>
    <item>
      <title>Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621338#M872407</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 a delete statement inside a loop like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;    lv_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;    clear gt_mattab.&lt;/P&gt;&lt;P&gt;    READ TABLE gt_mattab&lt;/P&gt;&lt;P&gt;    WITH KEY MATERIAL = DATA_PACKAGE-MATERIAL.&lt;/P&gt;&lt;P&gt;    IF SY-SUBRC NE 0.&lt;/P&gt;&lt;P&gt;      DELETE DATA_PACKAGE index lv_tabix.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;  ENLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please help me in deleting the data packages with out using it in the loop?&lt;/P&gt;&lt;P&gt;Will that increase the performance of the code and how?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:07:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621338#M872407</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T11:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621339#M872408</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;loop at itab.&lt;/P&gt;&lt;P&gt;delete itab where field = 'value'.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;venkat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:11:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621339#M872408</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T11:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621340#M872409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Prasad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No need to use read table statement, just delete it by using condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;lv_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;clear gt_mattab.&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;READ TABLE gt_mattab&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;WITH KEY MATERIAL = DATA_PACKAGE-MATERIAL.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;IF SY-SUBRC NE 0.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;DELETE DATA_PACKAGE with table keyMATERIAL = DATA_PACKAGE-MATERIAL .&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;ENDIF.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;ENLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will be some what efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subbu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:20:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621340#M872409</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T11:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621341#M872410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i dont see any necessity to change your code. it is fine like it is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what you would need is some inversion the FOR ALL ENTRIES statement.&lt;/P&gt;&lt;P&gt;Since this statement is known to be aof bad performnce (it forces a fuill table scan) it wont improve your performance doing it outside the loop, but using FOR ALL ENTRIES.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:26:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621341#M872410</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T11:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621342#M872411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;describe table t_tab lines w_lines.&lt;/P&gt;&lt;P&gt;if w_int lt w_lines.&lt;/P&gt;&lt;P&gt;Read table t_tab with index w_int.&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;  delete t_tab from fs_tab.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;w_int = w_int + 1.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;I hope it will help u.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:31:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621342#M872411</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T11:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621343#M872412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Prasad,&lt;/P&gt;&lt;P&gt;Yes u r right. &lt;STRONG&gt;Delete&lt;/STRONG&gt; inside loop is very bad coding practice. But in some of the places we cant avoid this. Few tips to improve the performance of ur code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SORT gt_mattab BY material.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;LOOP AT DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;lv_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;clear gt_mattab.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;READ TABLE gt_mattab&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;WITH KEY MATERIAL = DATA_PACKAGE-MATERIAL.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;IF SY-SUBRC NE 0.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;DELETE DATA_PACKAGE index lv_tabix.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;&lt;DEL&gt;ENDIF.&lt;/DEL&gt;&lt;/P&gt;&lt;P&gt;READ TABLE gt_matttab WITH KEY MATERIAL = DATA_PACKAGE-MATERIAL&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BINARY SEARCH&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TRANSPORTING NO FIELDS.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CHECK sy-subrc IS INITIAL.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;DELETE DATA_PACKAGE index lv_tabix.&lt;/P&gt;&lt;P&gt;ENLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use Binary search when ever ur table entries are more than 10.&lt;/P&gt;&lt;P&gt;If u want to check the existance of an entry then u can use addition TRANSPORTING NO FIELDS. Even u u can use this if u are using few fields of the read statement like TRANSPORTING f1 f2....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also avoid using header lines. Use explicit work areas.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vinod.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 11:36:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621343#M872412</guid>
      <dc:creator>vinod_vemuru2</dc:creator>
      <dc:date>2008-03-20T11:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621344#M872413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Every one ,Thanks for your spontaneous replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vinod,&lt;/P&gt;&lt;P&gt;So do you think that there is no other way to delete the data packages with out using it in the loop?&lt;/P&gt;&lt;P&gt;Can you also suggest me if  'do with in the loop'  increases the performance or not?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Pra.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 12:10:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621344#M872413</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T12:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621345#M872414</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;Data: v_tabix  LIKE sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT DATA_PACKAGE INTO w_DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;    v_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;    READ TABLE gt_mattab WITH KEY MATERIAL = w_DATA_PACKAGE-MATERIAL&lt;/P&gt;&lt;P&gt;                                  TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;    IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;      DELETE DATA_PACKAGE INDEX v_tabix.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;  CLEAR: w_DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this.May be this will help .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Harsha.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 12:22:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621345#M872414</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T12:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621346#M872415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi prasad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use continue statement. Because the deleted line will change the index. &lt;/P&gt;&lt;P&gt;Reward points if helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sankar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 12:46:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621346#M872415</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T12:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621347#M872416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Prasad,&lt;/P&gt;&lt;P&gt;Let me explain exactly what happens if u delete a record from the internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If u defined your internal table like TYPE STANDARD TABLE OF or TYPE SORTED TABLE OF then it will work on INDEX mechanism.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if have 100 records in ur internal table then each record will be identified with its position i.e &lt;STRONG&gt;INDEX&lt;/STRONG&gt;. When u delete a record from the table then it has to recreate the indexes for all other records(Except in case of deletion of last record) after that record. It is the majar disadvantage of delete statement. If u use delete statement inside loop this process has to happen equal to number of &lt;STRONG&gt;deletions&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So there is one more solution for this which will be faster than &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DELETE&lt;/STRONG&gt; inside the loop. Instead of deleting the records from the original table APPEND the records to another internal table.In this case it has to create INDEX for one time for one append in contrary to DELETE whcih has to recreate INDEXS for all rows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the logic below. Implement and use SQL trace to moniter the performance(transaction ST05).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;lv_tabix = sy-tabix.&lt;/P&gt;&lt;P&gt;clear gt_mattab.&lt;/P&gt;&lt;P&gt;READ TABLE gt_mattab&lt;/P&gt;&lt;P&gt;WITH KEY MATERIAL = DATA_PACKAGE-MATERIAL.&lt;/P&gt;&lt;P&gt;CHECK SY-SUBRC &lt;STRONG&gt;EQ&lt;/STRONG&gt; 0.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;APPEND DATA_PACKAGE TO DATA_PACKAGE1.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;ENLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also if u dont have else part and no code after ENDIF then always use &lt;STRONG&gt;CHECK&lt;/STRONG&gt; statement which is much faster than IF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vinod.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Vinod Kumar Vemuru on Mar 20, 2008 6:32 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 13:00:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621347#M872416</guid>
      <dc:creator>vinod_vemuru2</dc:creator>
      <dc:date>2008-03-20T13:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Delete in loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621348#M872417</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 are going for appending into another internal table then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort DATA_PACKAGE by material.&lt;/P&gt;&lt;P&gt;sort gt_matttab by material.&lt;/P&gt;&lt;P&gt;Refresh: DATA_PACKAGE1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;READ TABLE gt_mattab&lt;/P&gt;&lt;P&gt;WITH KEY MATERIAL = DATA_PACKAGE-MATERIAL&lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CHECK SY-SUBRC EQ 0.&lt;/P&gt;&lt;P&gt;APPEND DATA_PACKAGE TO DATA_PACKAGE1.&lt;/P&gt;&lt;P&gt;ENLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refresh: DATA_PACKAGE.&lt;/P&gt;&lt;P&gt;DATA_PACKAGE [  ] = DATA_PACKAGE1 [  ].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this will improve your performance issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please reward if useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ramesh.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ramesh Jakkula on Mar 20, 2008 2:23 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ramesh Jakkula on Mar 20, 2008 2:24 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Mar 2008 13:22:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-in-loop/m-p/3621348#M872417</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-20T13:22:21Z</dc:date>
    </item>
  </channel>
</rss>

