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 performance

sudha_naik
Product and Topic Expert
Product and Topic Expert
0 Likes
870

Hello,

I have a nested loop like this which loops through two internal tables

SORT xxmsel-ymsel BY cuobj.

LOOP AT xwsel.

LOOP AT xxmsel.

CLEAR l_tabix.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc NE 0.

CONTINUE.

ELSE.

-- Do some processing

ENDIF.

ENDLOOP.

ENDLOOP.

Since the internal tables contain too many records, this loop is taking time. Is there any way in which this loop performance can be improved ??

Thanks in advance

Regards

Sudha

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
844

Hii. Sudha..

You must change the code as beow for better performance..

This will give much better performance since we are implementing partial loop

i.e LOOP AT ITAB FROM <ROW> TO <ROW>.

SORT xxmsel-ymsel BY cuobj.

LOOP AT xwsel.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc EQ 0.

L_TABIX = SY-TABIX.

LOOP AT xxmsel FROM L_TABIX.

IF xxmsel-cuobj ne xxmsel-ymsel.

EXIT.

ENDIF.

<<IMPLEMENT YOUR PROCESSING HERE>>.

ENDLOOP.

ENDIF.

ENDLOOP.

<b>Reward if Helpful</b>

9 REPLIES 9
Read only

varma_narayana
Active Contributor
0 Likes
845

Hii. Sudha..

You must change the code as beow for better performance..

This will give much better performance since we are implementing partial loop

i.e LOOP AT ITAB FROM <ROW> TO <ROW>.

SORT xxmsel-ymsel BY cuobj.

LOOP AT xwsel.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc EQ 0.

L_TABIX = SY-TABIX.

LOOP AT xxmsel FROM L_TABIX.

IF xxmsel-cuobj ne xxmsel-ymsel.

EXIT.

ENDIF.

<<IMPLEMENT YOUR PROCESSING HERE>>.

ENDLOOP.

ENDIF.

ENDLOOP.

<b>Reward if Helpful</b>

Read only

Former Member
0 Likes
844

Try the below code... This is actually called Parallel Cursor concept. This is actually suggested to be used for such performance bottlenecks... esp when u hv to do loop inside a loop...

SORT xxmsel-ymsel BY cuobj.

LOOP AT xwsel.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc = 0.

l_tabix = sy-tabix.

loop at xxmsel-ymsel into msel from l_tabix.

if xxmsel-ymsel-cuobj = xwsel-cuobj.

-- Do some processing

else.

clear: l_tabix.

exit.

endif.

endloop.

ENDIF.

ENDLOOP.

NB: Reward points if this reply found helpful.

Read only

Former Member
0 Likes
844

try using

AT NEW EVENTS combined with READ statements rather using loop in a loop.

Read only

Former Member
0 Likes
844

Hi

any way u r reading internal table xxmsel again y u r keeping loop to it no need of it .usally we should not got for loop in loops .

u can have the following code

SORT xxmsel-ymsel BY cuobj.

LOOP AT xwsel.

CLEAR l_tabix.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc NE 0.

CONTINUE.

ELSE.

-- Do some processing

ENDIF.

ENDLOOP.

Regards

sandhya

Read only

dev_parbutteea
Active Contributor
0 Likes
844

Hi,

you should use loop from index to improve performance here.

Read only

Former Member
0 Likes
844

Try This,

LOOP AT xxmsel.

CLEAR l_tabix.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc NE 0.

CONTINUE.

ELSE.

-- Do some processing

ENDIF.

ENDLOOP.

It will give better performance

Regards

sushil

Read only

former_member283648
Participant
0 Likes
844

Try doing like this....

SORT : xwsel, xxmsel BY cuobj.

LOOP AT xwsel.

LOOP AT xxmsel where cuobj = xwsel-cuobj.

-- Do some processing

ENDLOOP.

ENDLOOP.

This will surely improve the performance.

Read only

Former Member
0 Likes
844

Hi Sudha,

As per my understand of what you have written code is necessary use loop within loop.

See you can use the following code straight away with out using again loop, perhaps it meets your requirement.

SORT xxmsel-ymsel BY cuobj.

LOOP AT xwsel.

*******************LOOP AT xxmsel.

CLEAR l_tabix.

READ TABLE xxmsel-ymsel INTO msel WITH KEY

cuobj = xwsel-cuobj BINARY SEARCH.

IF sy-subrc NE 0.

CONTINUE.

ELSE.

-- Do some processing

ENDIF.

ENDLOOP.

*******************ENDLOOP.

In the above code any way u r using the READ statemen, then why should u r using loop with in loop.

it is bettor to aviod the inner loop according to performance wise

if you any doubts please reply.

rewards points if really helpful

Regards,

Vijay

Read only

Former Member
0 Likes
844

Hi,

Instead of Loop with in Loop is too expensive for performance, It is better to use Read Statement with in loop.

With regards,

K K V