parallel_cursor
parallel_cursor
ENDLOOP.
Now, this is the main pgm, we will do nested loop, parallel cursor and parallel processor and find
their execution time
REPORT znested_loop.
PERFORM nested_loop.
PERFORM parallel_cursor.
PERFORM parallel_processing.
WRITE: / '----------------------------------------------------|'.
WRITE: / '| Execution Method | Time (ms) |'.
WRITE: / '----------------------------------------------------|'.
WRITE: / '| Nested Loop |', nested_exec_time, '|'.
WRITE: / '| Parallel Cursor |', par_cur_exec_time, '|'.
WRITE: / '| Parallel Processing |', pp_exec_time , '|'.
WRITE: / '----------------------------------------------------|'.
ENDLOOP.
ENDLOOP.
ENDFORM.
This is the code for parallel cursor. Kindly note, there is no second loop (or inside loop).
Instead of the second loop, we are reading with a key. Before reading, both the tables VBAP &
VBAK should be sorted on the key ascending.
FORM parallel_cursor .
DATA: lt_vbap_data TYPE TABLE OF vbap, " Table for VBAP data
lt_vbak_data TYPE TABLE OF vbak, " Table for VBAK data
ls_vbap TYPE vbap, " Work area for VBAP
ls_vbak TYPE vbak, " Work area for VBAK
total_quantity TYPE kwmeng, " Total quantity accumulator
start_time TYPE i, " Start time
end_time TYPE i, " End time
vbak_pointer TYPE sy-tabix. " Pointer for VBAK.
IF sy-subrc = 0.
" Matching record found in VBAK
" 1. Accumulate Total Quantities
total_quantity = total_quantity + ls_vbap-kwmeng.
ENDIF.
ENDLOOP.
" Display Results After Processing
WRITE: / 'PC Total Quantity:', total_quantity.
GET RUN TIME FIELD end_time.
ENDFORM.
Now, coming to Parallel Processing. PP is splitting the data into smaller chunks (say 5 here)
and submitting 5 different jobs. Once all the 5 jobs complete, we have to consolidate the result.
Below is the logic for the code.
FORM parallel_processing .
TYPES:
BEGIN OF ty_vbak_vbap,
vbeln TYPE vbak-vbeln,
kwmeng TYPE vbap-kwmeng,
END OF ty_vbak_vbap.
WHEN 2.
lv_task_name = 'TASK_02'.
CALL FUNCTION 'ZPRC_SO'
STARTING NEW TASK lv_task_name
DESTINATION IN GROUP 'parallel_generators'
" PERFORMING final_data ON END OF TASK
TABLES
vbap_data = lt_vbap
vbak_data = lt_vbak2.
task_initiated = task_initiated + 1.
WHEN 3.
lv_task_name = 'TASK_03'.
CALL FUNCTION 'ZPRC_SO'
STARTING NEW TASK lv_task_name
DESTINATION IN GROUP 'parallel_generators'
" PERFORMING final_data ON END OF TASK
TABLES
vbap_data = lt_vbap
vbak_data = lt_vbak3.
task_initiated = task_initiated + 1.
WHEN 4.
lv_task_name = 'TASK_04'.
CALL FUNCTION 'ZPRC_SO'
STARTING NEW TASK lv_task_name
DESTINATION IN GROUP 'parallel_generators'
" PERFORMING final_data ON END OF TASK
TABLES
vbap_data = lt_vbap
vbak_data = lt_vbak4.
task_initiated = task_initiated + 1.
WHEN 5.
lv_task_name = 'TASK_05'.
CALL FUNCTION 'ZPRC_SO'
STARTING NEW TASK lv_task_name
DESTINATION IN GROUP 'parallel_generators'
" PERFORMING final_data ON END OF TASK
TABLES
vbap_data = lt_vbap
vbak_data = lt_vbak5.
task_initiated = task_initiated + 1.
*
ENDCASE.
ENDDO.
WRITE: / 'PP Total Quantity:', pp_qty.
GET RUN TIME FIELD pp_end_time.
pp_exec_time = ( pp_end_time - pp_start_time ) / 1000.
ENDFORM.
I have used VBAP_DATA & VBAK_DATA as Input tables and Table OUT_ZOVBAK as my output
table. But, there are many ways to get your output. Here, I have written my output to a record
in a configure kind of table.
FUNCTION zprc_so.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" VBAP_DATA STRUCTURE VBAP
*" VBAK_DATA STRUCTURE VBAK
*" OUT_ZOVBAK STRUCTURE ZOVBAK
*"----------------------------------------------------------------------
CLEAR: total_quantity.
LOOP AT lt_vbap_data INTO ls_vbap.
ENDLOOP.
UPDATE zovbak_fk
SET kwmeng = ls_kwmeng
WHERE vbeln = '0000000007'.
ENDIF.
ENDFUNCTION.
To find the execution of the Parallel Process (Tasks), use TCODE SM50 or SM66
Results:
Parallel Processing is far more efficient, but coding is cumbersome (but worth it).
Happy learning 🙂