Parallel Cursor technique - Sap 4 All

Latest

Please enter your email and get the updates in your inbox.

Wednesday, 15 June 2016

Parallel Cursor technique

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.





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.

6 comments:

  1. 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:
    LOOP 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.

    ReplyDelete
  2. Yaa it make the processing much faster but sort the itab1 by field1 before the loop if you want to use binary search..

    ReplyDelete
  3. is it easier to use :
    LOOP AT ITAB INTO WA.
    LOOP AT ITAB1 INTO WA1 where field1 = wa-field1. "It will loop only on that key
    ENDLOOP.
    ENDLOOP.

    ReplyDelete
  4. Thanks for sharing this Information,

    Got 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

    ReplyDelete
  5. Nice Blog!!. Thanks For Sharing..

    you may also find useful information on below link

    https://www.learnsapabap.com/2018/05/parallel-cursor.html

    ReplyDelete