SAP ABAP : Parallel Cursor
*&---------------------------------------------------------------------*
*& Report Z_PARALEL_CURSOR
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_PARALEL_CURSOR.
DATA : LT_BKPF TYPE TABLE OF BKPF,
LT_BSEG TYPE TABLE OF BSEG,
LS_BKPF TYPE BKPF,
LS_BSEG TYPE BSEG.
DATA : LV_TIME1 TYPE I,
LV_TIME2 TYPE I,
LV_TIME3 TYPE I,
LV_TIME4 TYPE I,
LV_RES_TIME_GN_PROCESS TYPE I,
LV_RES_TIME_PA_PROCESS TYPE I,
INDX TYPE I.
DATA : LV_BKPF_RECS TYPE I.
DATA : LV_BSEG_RECS TYPE I.
START-OF-SELECTION.
SELECT * FROM BKPF INTO TABLE LT_BKPF UP TO 10000 ROWS.
SELECT * FROM BSEG INTO TABLE LT_BSEG UP TO 10000 ROWS.
DESCRIBE TABLE LT_BKPF LINES LV_BKPF_RECS.
DESCRIBE TABLE LT_BSEG LINES LV_BSEG_RECS.
GET RUN TIME FIELD LV_TIME1.
LOOP AT LT_BKPF INTO LS_BKPF.
LOOP AT LT_BSEG INTO LS_BSEG WHERE VBELN = LS_BKPF-BELNR.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD LV_TIME2.
LV_RES_TIME_GN_PROCESS = LV_TIME2 - LV_TIME1.
* APPLYING PARALLEL CURSOR TECHNIQUE
SORT LT_BKPF BY BELNR.
SORT LT_BSEG BY BELNR.
GET RUN TIME FIELD LV_TIME3.
LOOP AT LT_BKPF INTO LS_BKPF.
READ TABLE LT_BSEG INTO LS_BSEG WITH KEY BELNR = LS_BKPF-BELNR BINARY SEARCH.
IF SY-SUBRC = 0.
INDX = SY-TABIX.
LOOP AT LT_BSEG INTO LS_BSEG FROM INDX.
IF LS_BSEG-BELNR <> LS_BKPF-BELNR.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
GET RUN TIME FIELD LV_TIME4.
LV_RES_TIME_PA_PROCESS = LV_TIME4 - LV_TIME3.
WRITE:/ 'Total BKPF Rows = ', LV_BKPF_RECS.
WRITE:/ 'Total BSEG Rows = ', LV_BSEG_RECS.
WRITE :/ 'Nested loop Processing Time', LV_RES_TIME_GN_PROCESS.
WRITE :/ 'Parallel Cursor Processing Time', LV_RES_TIME_PA_PROCESS.
*& Report Z_PARALEL_CURSOR
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_PARALEL_CURSOR.
DATA : LT_BKPF TYPE TABLE OF BKPF,
LT_BSEG TYPE TABLE OF BSEG,
LS_BKPF TYPE BKPF,
LS_BSEG TYPE BSEG.
DATA : LV_TIME1 TYPE I,
LV_TIME2 TYPE I,
LV_TIME3 TYPE I,
LV_TIME4 TYPE I,
LV_RES_TIME_GN_PROCESS TYPE I,
LV_RES_TIME_PA_PROCESS TYPE I,
INDX TYPE I.
DATA : LV_BKPF_RECS TYPE I.
DATA : LV_BSEG_RECS TYPE I.
START-OF-SELECTION.
SELECT * FROM BKPF INTO TABLE LT_BKPF UP TO 10000 ROWS.
SELECT * FROM BSEG INTO TABLE LT_BSEG UP TO 10000 ROWS.
DESCRIBE TABLE LT_BKPF LINES LV_BKPF_RECS.
DESCRIBE TABLE LT_BSEG LINES LV_BSEG_RECS.
GET RUN TIME FIELD LV_TIME1.
LOOP AT LT_BKPF INTO LS_BKPF.
LOOP AT LT_BSEG INTO LS_BSEG WHERE VBELN = LS_BKPF-BELNR.
ENDLOOP.
ENDLOOP.
GET RUN TIME FIELD LV_TIME2.
LV_RES_TIME_GN_PROCESS = LV_TIME2 - LV_TIME1.
* APPLYING PARALLEL CURSOR TECHNIQUE
SORT LT_BKPF BY BELNR.
SORT LT_BSEG BY BELNR.
GET RUN TIME FIELD LV_TIME3.
LOOP AT LT_BKPF INTO LS_BKPF.
READ TABLE LT_BSEG INTO LS_BSEG WITH KEY BELNR = LS_BKPF-BELNR BINARY SEARCH.
IF SY-SUBRC = 0.
INDX = SY-TABIX.
LOOP AT LT_BSEG INTO LS_BSEG FROM INDX.
IF LS_BSEG-BELNR <> LS_BKPF-BELNR.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
GET RUN TIME FIELD LV_TIME4.
LV_RES_TIME_PA_PROCESS = LV_TIME4 - LV_TIME3.
WRITE:/ 'Total BKPF Rows = ', LV_BKPF_RECS.
WRITE:/ 'Total BSEG Rows = ', LV_BSEG_RECS.
WRITE :/ 'Nested loop Processing Time', LV_RES_TIME_GN_PROCESS.
WRITE :/ 'Parallel Cursor Processing Time', LV_RES_TIME_PA_PROCESS.
Comments
Post a Comment