Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Loop taking too long

Former Member
0 Likes
1,317

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?

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.

Regards,

Darlington

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,237

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.

You can avoid select endselect loop. Instead use select select act_grp from zactivities into table it_rrr.

7 REPLIES 7
Read only

Former Member
0 Likes
1,238

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.

You can avoid select endselect loop. Instead use select select act_grp from zactivities into table it_rrr.

Read only

Former Member
0 Likes
1,237

Hi Darlington,

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 .

Hope it helps,

Regards,

Pavan.

Read only

0 Likes
1,237

Hello Pavan,

Thanks for the prompt reply. But can you be more specific? How do I split it?

Regards.

Read only

0 Likes
1,237

Hi, Chiyamha

I do some change in you code please test the following Code hope will work for you.

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.

Please Reply if any Issue,

Best Regards,

Faisal

Read only

0 Likes
1,237

just keep passing/appending them to another table. that solves your problem.

Read only

Former Member
0 Likes
1,237

Hi,

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.

Try something like this,



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.

Regards,

Vik

Read only

Former Member
0 Likes
1,237

Thank you all very much, this was a great learning experience for me.