‎2007 Aug 23 7:19 AM
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
‎2007 Aug 23 7:28 AM
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>
‎2007 Aug 23 7:28 AM
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>
‎2007 Aug 23 7:33 AM
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.
‎2007 Aug 23 7:34 AM
try using
AT NEW EVENTS combined with READ statements rather using loop in a loop.
‎2007 Aug 23 7:34 AM
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
‎2007 Aug 23 7:34 AM
Hi,
you should use loop from index to improve performance here.
‎2007 Aug 23 7:34 AM
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
‎2007 Aug 23 7:35 AM
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.
‎2007 Aug 23 7:45 AM
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
‎2007 Aug 23 8:47 AM
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