Documente Academic
Documente Profesional
Documente Cultură
A White Paper
On
Parallel Processing in
SAP ABAP
BY
Pradeep Kumar Nathmal
(pradeep.nathmal@wipro.com)
Wipro Technologies
SAP ABAP Practice
Page 1 of 18
8/19/2016
8:15:21 PM
Table of Content
1.
2.
3.
4.
5.
6.
7.
Introduction 3
Pre-requisites to use parallel processing 3
Function Modules and ABAP Keywords 4
Managing Resources with RFC Server Groups.. 5
Messages and Exceptions 5
Hands On Example Program 6
Test Results 15
Page 2 of 18
8/19/2016
8:15:21 PM
Introduction:
Generally when we call a function module, it will stop the current program, execute another
(called) program and then returns control to original program and again original program
starts execution.
With asynchronous function module control will start parallelly without stopping the current
program from which you called the function module.
In parallel processing, a job step is started as usual in a background processing work process. A
program that runs in a job step can be programmed to use a special variant of asynchronous RFC to
have portions of the data to be processed run in parallel in other work processes. You can recognize
such a program by its use of the CALL FUNCTION STARTING NEW TASK DESTINATION IN GROUP
instruction to start the function modules that process the data.
While the job itself runs in a background process, the parallel processing tasks that it starts run in
dialog work processes. Such dialog work processes may be located on any SAP server.
Parallel processing has been implemented in some SAP applications that have long-running reports.
The parallel processing interface is also available directly to customers.
Page 3 of 18
8/19/2016
8:15:21 PM
by definition, there is no guarantee that data will be processed in a particular order in parallel
processing or that a particular result will be available at a given point in processing.
SAP system resources: In order to process tasks from parallel jobs, a server in your SAP system
must have at least 3 dialog work processes. It must also meet the workload criteria of the parallel
processing system: Dispatcher queue less than 10% full, at least one dialog work process free for
processing tasks from the parallel job.
Function module SPBT_INITIALIZE: Optional. Use to determine the availability of resources for
parallel processing.
You can do the following:
check that the parallel processing group that you have specified is correct.
find out how many work processes are available so that you can more efficiently size the packets of
data that are to be processed in your data.
ABAP keyword CALL FUNCTION <function> STARTING NEW TASK <taskname> with the
DESTINATION IN GROUP argument: Use this keyword to have the SAP system execute the
function module call in parallel. Typically, youll place this keyword in a loop in which you divide
up the data that is to be processed into work packets. You can pass the data that is to be
processed in the form of an internal table (EXPORT, TABLE arguments). The keyword implements
parallel processing by dispatching asynchronous RFC calls to the servers that are available in the
RFC server group specified for the processing.
Note that your RFC calls with CALL FUNCTION are processed in work processes of type DIALOG.
The DIALOG limit on processing of one dialog step (by default 300 seconds, system profile
parameter rdisp/max_wprun_time) applies to these RFC calls. Keep this limit in mind when you
divide up data for parallel processing calls.
ABAP keyword WAIT: Required if you wish to wait for all of the asynchronous parallel tasks created
with CALL FUNCTION to return. This is normally a requirement for orderly background processing.
May be used only if the CALL FUNCTION includes the PERFORMING ON RETURN addition.
Page 4 of 18
8/19/2016
8:15:21 PM
ABAP keyword RECEIVE: Required if you wish to receive the results of the processing of an
asynchronous RFC. RECEIVE retrieves IMPORT and TABLE parameters as well as messages and
return codes.
Page 5 of 18
8/19/2016
8:15:21 PM
start-of-selection.
call function 'BAPI_CUSTOMER_GETDETAIL2'
starting new task 'FUNC1'
destination 'NONE'
performing set_function1_done on end of task
exporting
customerno
= p_kunnr.
FORM FUNCTION1_DONE
************************************************************************
form set_function1_done using taskname.
receive results from function 'BAPI_CUSTOMER_GETDETAIL2'
importing
customergeneraldetail
= cstgdetail1.
functioncall1 = done.
endform.
Page 6 of 18
8/19/2016
8:15:21 PM
2. Report: ZPARALLEL_PROCESSING_JOB
*&---------------------------------------------------------------------*
*& Report ZPARALLEL_PROCESSING_JOB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
* Project
: Test
*
* Requested By : XXX
*
* Author
: Pradeep Kumar Nathmal
*
* Created on
: 03.08.2016 (dd.mm.yyyy)
*
* DCR Ref
: XXXX
*
* Description : Parallel Processing in SAP ABAP
*
************************************************************************
* Updates
*
* |-------------------------------------------------------------------|
* | Date
| Author
| Description or cross reference
|
* |DD.MM.YYYY|
|
|
* |-------------------------------------------------------------------|
REPORT zparallel_processing_job NO STANDARD PAGE HEADING MESSAGE-ID sy.
*&---------------------------------------------------------------------*
*
D A T A D E C L A R A T I O N S
*
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_marc,
matnr TYPE marc-matnr, "Material Number
werks TYPE marc-werks, "Plant
END OF ty_marc.
DATA: g_werks TYPE t001w-werks,
g_max_wps TYPE i,
g_free_wps TYPE i,
g_taskname TYPE string,
g_lines TYPE i,
g_count TYPE i,
g_1 TYPE i VALUE '1',
g_2 TYPE i,
g_mod TYPE i,
g_counter TYPE c.
Page 7 of 18
8/19/2016
8:15:21 PM
Page 8 of 18
8/19/2016
8:15:21 PM
PERFORM data_fetch.
*&---------------------------------------------------------------------*
*
E N D - O F - S E L E C T I O N
*
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&
Form REFRESH_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM refresh_data.
CLEAR: g_werks,
g_max_wps,
g_free_wps,
g_taskname,
g_lines,
g_count,
*
g_1,
g_2,
g_mod,
g_counter,
wa_marc,
wa_makt,
wa_final.
REFRESH: i_marc,
im_marc,
i_makt,
i_final,
sr_werks.
ENDFORM.
" REFRESH_DATA
*&---------------------------------------------------------------------*
*&
Form DATA_FETCH
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM data_fetch.
SELECT matnr
Pradeep Kumar Nathmal
Page 9 of 18
8/19/2016
8:15:21 PM
werks
FROM marc
INTO TABLE i_marc
WHERE werks IN s_werks.
IF sy-subrc EQ 0.
SORT i_marc BY matnr werks.
SELECT *
FROM makt
INTO TABLE i_makt
FOR ALL ENTRIES IN i_marc
WHERE matnr = i_marc-matnr.
IF sy-subrc EQ 0.
SORT i_makt BY matnr.
ENDIF.
ENDIF.
*Check no. of work processes currently free
CALL FUNCTION 'SPBT_INITIALIZE'
*
EXPORTING
*
GROUP_NAME
= ' '
IMPORTING
max_pbt_wps
= g_max_wps
free_pbt_wps
= g_free_wps
EXCEPTIONS
invalid_group_name
= 1
internal_error
= 2
pbt_env_already_initialized
= 3
currently_no_resources_avail
= 4
no_pbt_resources_found
= 5
cant_init_different_pbt_groups
= 6
OTHERS
= 7.
IF sy-subrc EQ 0.
IF g_free_wps LT 4.
*Do normal processing
IF i_marc IS NOT INITIAL.
LOOP AT i_marc INTO wa_marc.
READ TABLE i_makt INTO wa_makt WITH KEY matnr = wa_marc-matnr
BINARY SEARCH.
IF sy-subrc EQ 0.
wa_final-matnr = wa_marc-matnr. "Material Number
wa_final-werks = wa_marc-werks. "Plant
wa_final-maktx = wa_makt-maktx. "Material Description
APPEND wa_final TO i_final.
CLEAR: wa_final.
Pradeep Kumar Nathmal
Page 10 of 18
8/19/2016
8:15:21 PM
ENDIF.
ENDLOOP.
IF i_final[] IS NOT INITIAL.
MODIFY zmaraktx FROM TABLE i_final[].
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
ELSEIF g_free_wps GE 4.
*Do parallel processing
DESCRIBE TABLE s_werks[] LINES g_lines.
g_count = g_lines / 4.
g_2 = g_count. "c_4.
DO g_count TIMES.
APPEND LINES OF s_werks FROM g_1 TO g_2 TO sr_werks[].
im_marc[] = i_marc[].
DELETE im_marc[] WHERE werks NOT IN sr_werks[].
g_counter = g_counter + 1.
CONCATENATE 'Parallel Processing Job-' g_counter INTO g_taskname.
CALL FUNCTION 'ZMARAKTX_UPDATE'
STARTING NEW TASK g_taskname
DESTINATION 'NONE'
TABLES
im_marc = im_marc[]
im_makt = i_makt[].
WRITE: / g_taskname.
g_1 = g_2.
g_2 = g_2 + g_count. "c_4.
CLEAR: sr_werks[], im_marc[], g_taskname.
ENDDO.
g_mod = g_lines MOD 4.
IF g_mod NE 0.
APPEND LINES OF s_werks FROM g_mod TO g_lines TO sr_werks[].
im_marc[] = i_marc[].
DELETE im_marc[] WHERE werks NOT IN sr_werks[].
g_counter = g_counter + 1.
CONCATENATE 'Parallel Processing Job-' g_counter INTO g_taskname.
CALL FUNCTION 'ZMARAKTX_UPDATE'
STARTING NEW TASK g_taskname
DESTINATION 'NONE'
TABLES
im_marc = im_marc[]
Pradeep Kumar Nathmal
Page 11 of 18
8/19/2016
8:15:21 PM
im_makt = i_makt[].
WRITE: / g_taskname.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
" DATA_FETCH
Page 12 of 18
8/19/2016
8:15:21 PM
FUNCTION zmaraktx_update.
*"---------------------------------------------------------------------*"*"Local Interface:
*" TABLES
*"
IM_MARC TYPE ZTB_MARC
*"
IM_MAKT STRUCTURE MAKT
*"---------------------------------------------------------------------TYPES: BEGIN OF ty_final,
matnr TYPE marc-matnr, "Material Number
werks TYPE marc-werks, "Plant
Pradeep Kumar Nathmal
Page 13 of 18
8/19/2016
8:15:21 PM
Page 14 of 18
8/19/2016
8:15:21 PM
Test Results:
Page 15 of 18
8/19/2016
8:15:21 PM
Page 16 of 18
8/19/2016
8:15:21 PM
Page 17 of 18
8/19/2016
8:15:21 PM
Brief info on Example 2: Consider a Real Time scenario where the clients business for e.g. retail book
store, where there can be more than 12 lacs business materials. In SAP R3 a background job daily
updates huge records in a z table with all other material details like MRP, Stocks @ Store and DC level
etc. and only after the SAP R3 job completion, the latest z table data is made available in SAP BW/BI
system to generate business reports. Further these BW/BI reports can be linked for daily SAP R3
postings. Using parallel processing technique the job processing time can be drastically reduced thus
improving the performance of SAP R3 programs. Overall there is a significant improvement in
complete Business Process for the Client.
Page 18 of 18
8/19/2016
8:15:21 PM