<?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 taking too long in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998939#M1343906</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 reason why its taking a long time is, because you are appending the same internal table on which you are looping. This results in a infinite loop. One suggestion would be to create another internal table and append in the loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try something like this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

data: begin of it_rrr occurs 0,
         act_grp like zactivities-act_grp.
         end of it_rrr.

data: it_rrr_copy type standatd table of it_rrr occurs 0 with header line.

select act_grp from zactivities into table it_rrr.
 
delete adjacent duplicates from it_rrr comparing act_grp.

it_rrr[] = it_rrr_copy[].
 
loop at it_rrr.
  at new act_grp.
    st_rrr = it_rrr.
    it_rrr_copy-act_grp = st_rrr-act_grp.
    it_rrr_copy-comp_text = 'Total Completed'.
    modify it_rrr_copy index sy-tabix.
    clear st_rrr.
    st_rrr-comp_text = 'Comp Within Target'.
    st_rrr-act_grp = act_grp.
    append st_rrr to it_rrr_copy.
    clear st_rrr.
    st_rrr-act_grp = act_grp.
    st_rrr-comp_text = 'Percentage Completed'.
    append st_rrr to it_rrr_copy.
  endat.
  clear act_grp.
  clear st_rrr.
endloop.
 
sort it_rrr_copy by act_grp.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Aug 2009 04:31:58 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-08-20T04:31:58Z</dc:date>
    <item>
      <title>Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998935#M1343902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have written the following code so that it extracts from a table (zactivities) into an internal table it_rrr so that the titles 'Total Completed', 'Comp Within Target', and 'Percentage Completed' appear for each ACT_GRP in the internal table. It seems it's taking too long to process the loop. Can you suggest how I can solve this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select act_grp from zactivities into it_rrr-act_grp.
  append it_rrr.
endselect.
 
delete adjacent duplicates from it_rrr comparing act_grp.
 
loop at it_rrr.
  at new act_grp.
    st_rrr = it_rrr.
    act_grp = st_rrr-act_grp.
    it_rrr-comp_text = 'Total Completed'.
    modify it_rrr.
    clear st_rrr.
    st_rrr-comp_text = 'Comp Within Target'.
    st_rrr-act_grp = act_grp.
    append st_rrr to it_rrr.
    clear st_rrr.
    st_rrr-act_grp = act_grp.
    st_rrr-comp_text = 'Percentage Completed'.
    append st_rrr to it_rrr.
  endat.
  clear act_grp.
  clear st_rrr.
endloop.
 
sort it_rrr by act_grp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&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;&lt;/P&gt;&lt;P&gt;Darlington&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 03:31:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998935#M1343902</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T03:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998936#M1343903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are looping at it_rrr and appending to the same table in the loop. This may result in infinite loop. Can you define another internal table copy it_rrr to that table and append new internal table in the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can avoid select endselect loop. Instead use select select act_grp from zactivities into table it_rrr.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 03:40:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998936#M1343903</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T03:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998937#M1343904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Darlington,&lt;/P&gt;&lt;P&gt;         You are making a loop on an internal table and you are retreiving data and appending it and modifying overthere only. so it might take long time to process the loop because the load becomes more. So try splitting the loop into two loops then it will work .&lt;/P&gt;&lt;P&gt;Hope it helps,&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pavan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 03:50:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998937#M1343904</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T03:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998938#M1343905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Pavan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the prompt reply. But can you be more specific? How do I split it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 04:11:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998938#M1343905</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T04:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998939#M1343906</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 reason why its taking a long time is, because you are appending the same internal table on which you are looping. This results in a infinite loop. One suggestion would be to create another internal table and append in the loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try something like this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

data: begin of it_rrr occurs 0,
         act_grp like zactivities-act_grp.
         end of it_rrr.

data: it_rrr_copy type standatd table of it_rrr occurs 0 with header line.

select act_grp from zactivities into table it_rrr.
 
delete adjacent duplicates from it_rrr comparing act_grp.

it_rrr[] = it_rrr_copy[].
 
loop at it_rrr.
  at new act_grp.
    st_rrr = it_rrr.
    it_rrr_copy-act_grp = st_rrr-act_grp.
    it_rrr_copy-comp_text = 'Total Completed'.
    modify it_rrr_copy index sy-tabix.
    clear st_rrr.
    st_rrr-comp_text = 'Comp Within Target'.
    st_rrr-act_grp = act_grp.
    append st_rrr to it_rrr_copy.
    clear st_rrr.
    st_rrr-act_grp = act_grp.
    st_rrr-comp_text = 'Percentage Completed'.
    append st_rrr to it_rrr_copy.
  endat.
  clear act_grp.
  clear st_rrr.
endloop.
 
sort it_rrr_copy by act_grp.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 04:31:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998939#M1343906</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T04:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998940#M1343907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Chiyamha&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do some change in you code please test the following Code hope will work for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: it2_rrr LIKE STANDARD TABLE OF it_rrr. " Declare on more INTERNAL Table Like it_rrr

SELECT act_grp FROM zactivities INTO CORRESPONDING FIELDS OF TABLE it_rrr. " Do Change Here
*  APPEND it_rrr. Remove this 
*ENDSELECT.       Remove this

SORT: it_rrr BY act_grp.
DELETE ADJACENT DUPLICATES FROM it_rrr COMPARING act_grp.

LOOP AT it_rrr.
  AT NEW act_grp.
    st_rrr = it_rrr.
    act_grp = st_rrr-act_grp.
    it_rrr-comp_text = 'Total Completed'.
    MODIFY it_rrr INDEX sy-tabix. " Add INDEX sy-tabix Here
    CLEAR st_rrr.
    st_rrr-comp_text = 'Comp Within Target'.
    st_rrr-act_grp = act_grp.
    APPEND st_rrr TO it2_rrr.     " Change here it_rrr with it2_rrr
    CLEAR st_rrr.
    st_rrr-act_grp = act_grp.
    st_rrr-comp_text = 'Percentage Completed'.
    APPEND st_rrr TO it2_rrr.     " Change here it_rrr with it2_rrr
  ENDAT.
  CLEAR act_grp.
  CLEAR st_rrr.
ENDLOOP.

SORT it_rrr BY act_grp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please Reply if any Issue,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Faisal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 04:40:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998940#M1343907</guid>
      <dc:creator>faisalatsap</dc:creator>
      <dc:date>2009-08-20T04:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998941#M1343908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;just keep passing/appending them to another table. that solves your problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 04:42:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998941#M1343908</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T04:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Loop taking too long</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998942#M1343909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all very much, this was a great learning experience for me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Aug 2009 05:40:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-taking-too-long/m-p/5998942#M1343909</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-20T05:40:29Z</dc:date>
    </item>
  </channel>
</rss>

