How to increase performance using Parallel Cursor in SAP ABAP ?

Using parallel cursor to increase performance of SAP ABAP programs, parallel cursor in SAP ABAP

+ -

The first thing that comes into the mind of a good ABAPer is performance of his object, the main problem for performance issues are bad Select statements ex: select joins for more than 3 tables, nested Loops, how ever there is a concept of parallel cursor in SAP ABAP to avoid performance issues with nested loops with where condition.

To understand parallel cursor, follow and understand the below programs.

Program without parallel cursor

REPORT ZSAN_PARALLEL_CURSER.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
       WA_MARA TYPE TY_MARA.
TYPES: BEGIN OF TY_MVKE,
        MATNR TYPE MVKE-MATNR,
        VKORG TYPE MVKE-VKORG,
        VTWEG TYPE MVKE-VTWEG,
      END OF TY_MVKE.
DATA : IT_MVKE TYPE TABLE OF TY_MVKE,
       WA_MVKE TYPE TY_MVKE.
SELECT
  MATNR
  MTART
  MBRSH
  MATKL
  MEINS FROM MARA INTO TABLE IT_MARA UP TO 500 ROWS.
SORT IT_MARA.
DELETE ADJACENT DUPLICATES FROM IT_MARA COMPARING ALL FIELDS.
SELECT MATNR
       VKORG
       VTWEG FROM MVKE INTO TABLE IT_MVKE
       FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
LOOP AT IT_MARA INTO WA_MARA.
  LOOP AT IT_MVKE INTO WA_MVKE WHERE MATNR = WA_MARA-MATNR.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MVKE-VKORG, WA_MVKE-VTWEG.
  ENDLOOP.
ENDLOOP.

Program with parallel cursor.

REPORT ZSAN_PARALLEL_CURSER.
TYPES: BEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
       WA_MARA TYPE TY_MARA.
TYPES: BEGIN OF TY_MVKE,
        MATNR TYPE MVKE-MATNR,
        VKORG TYPE MVKE-VKORG,
        VTWEG TYPE MVKE-VTWEG,
      END OF TY_MVKE.
DATA : IT_MVKE TYPE TABLE OF TY_MVKE,
       WA_MVKE TYPE TY_MVKE.
SELECT
  MATNR
  MTART
  MBRSH
  MATKL
  MEINS FROM MARA INTO TABLE IT_MARA UP TO 500 ROWS.
SORT IT_MARA.
DELETE ADJACENT DUPLICATES FROM IT_MARA COMPARING ALL FIELDS.
SELECT MATNR
       VKORG
       VTWEG FROM MVKE INTO TABLE IT_MVKE
       FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
SORT: IT_MARA, IT_MVKE.
DATA V_INDEX TYPE SY-TABIX.
LOOP AT IT_MARA INTO WA_MARA.
  READ TABLE IT_MVKE INTO WA_MVKE WITH KEY MATNR = WA_MARA-MATNR BINARY SEARCH.
  IF SY-SUBRC = 0.
    V_INDEX = SY-TABIX.
    LOOP AT IT_MVKE INTO WA_MVKE FROM V_INDEX. "no where condition for loop
      IF WA_MVKE-MATNR <> WA_MARA-MATNR.
        EXIT.
      ENDIF.
      WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MVKE-VKORG, WA_MVKE-VTWEG.
    ENDLOOP.
  ENDIF.
  CLEAR: WA_MARA, WA_MVKE.
ENDLOOP.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 74 People out of 75 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →