Parallel Cursor is a technique to increase the performance
of the program when there are nested loops.
For example:-
if the code contains this type of logic:-
LOOP AT ITAB INTO WA.
LOOP AT ITAB1 INTO WA1.
ENDLOOP.
ENDLOOP.
LOOP AT ITAB1 INTO WA1.
ENDLOOP.
ENDLOOP.
In the above logic, for one record of the itab, again the
table itab1 loops many times. If itab contains
many records and also at the same time if itab1 contains
double the records, then this would result into performance issue. you can modify it as:-
LOOP AT ITAB INTO WA.
READ TABLE ITAB1 INTO WA1 WITH KEY FIELD1 = WA-FIELD1.
V_TABIX = SY-TABIX.
IF SY-SUBRC EQ 0.
LOOP AT ITAB1 INTO WA1 FROM V_TABIX. "It will loop from that index
ENDLOOP.
ENDIF.
ENDLOOP.
READ TABLE ITAB1 INTO WA1 WITH KEY FIELD1 = WA-FIELD1.
V_TABIX = SY-TABIX.
IF SY-SUBRC EQ 0.
LOOP AT ITAB1 INTO WA1 FROM V_TABIX. "It will loop from that index
ENDLOOP.
ENDIF.
ENDLOOP.
You forgot the 'BINARY SEARCH' in the 'READ' statement, and also to make sure that the inner loop exits when the conditions on FIELD1 is no longer match:
ReplyDeleteLOOP AT ITAB INTO WA.
READ TABLE ITAB1 INTO WA1 WITH KEY FIELD1 = WA-FIELD1
BINARY SEARCH.
V_TABIX = SY-TABIX.
IF SY-SUBRC EQ 0.
LOOP AT ITAB1 INTO WA1 FROM V_TABIX. "It will loop from that index
if ITAB1-FIELD1 <> WA-FIELD1.
EXIT.
endif.
ENDLOOP.
ENDIF.
ENDLOOP.
Yaa it make the processing much faster but sort the itab1 by field1 before the loop if you want to use binary search..
ReplyDeleteis it easier to use :
ReplyDeleteLOOP AT ITAB INTO WA.
LOOP AT ITAB1 INTO WA1 where field1 = wa-field1. "It will loop only on that key
ENDLOOP.
ENDLOOP.
Thanks for sharing this Information,
ReplyDeleteGot to learn new things from your Blog on Sap abap.
http://thecreatingexperts.com/sap-abap-training-in-chennai/
Both online and classroom training is provided.
Contact 8122241286
Nice Blog!!. Thanks For Sharing..
ReplyDeleteyou may also find useful information on below link
https://www.learnsapabap.com/2018/05/parallel-cursor.html
This comment has been removed by the author.
Delete