Sunteți pe pagina 1din 18

Parallel Processing in SAP ABAP

A White Paper
On
Parallel Processing in
SAP ABAP

BY
Pradeep Kumar Nathmal
(pradeep.nathmal@wipro.com)
Wipro Technologies
SAP ABAP Practice

Pradeep Kumar Nathmal

Page 1 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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

Pradeep Kumar Nathmal

Page 2 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

Introduction:

We use parallel processing when we have to process large amount of data.

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.

Parallel Processing means Asynchronous Type of 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.

Pre-requisites to use parallel processing:


Before you implement parallel processing, make sure that your background processing
application and your SAP system meet these requirements:
ABAP requirements (see also the online documentation for the CALL FUNCTION STARTING NEW
TASK DESTINATION IN GROUP keyword):
The function module that you call must be marked as externally callable. This attribute is specified
in the Remote function call supported field in the function module definition (transaction SE37)).
The called function module may not include a function call to the destination BACK.
The calling program should not change to a new internal session after making an asynchronous
RFC call. That is, you should not use SUBMIT or CALL TRANSACTION in such a report after using
CALL FUNCTION STARTING NEW TASK.
You cannot use the CALL FUNCTION STARTING NEW TASK DESTINATION IN GROUP keyword to
start external programs.
In calls between SAP systems, both systems must be of Release 3.0A or higher.
Logically-independent units of work: The data processing task that is to be carried out in parallel
must be logically independent of other instances of the task. That is, the task can be carried out
without reference to other records from the same data set that are also being processed in
parallel, and the task is not dependent upon the results of others of the parallel operations. For
example, parallel processing is not suitable for data that must be sequentially processed or in
which the processing of one data item is dependent upon the processing of another item of the
data.

Pradeep Kumar Nathmal

Page 3 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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 Modules and ABAP Keywords:


Parallel processing is implemented in the application reports that are to run in the background. You
can implement parallel processing in your own background applications by using the following function
modules and ABAP keywords:

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.

Function module SPBT_GET_PP_DESTINATION: Optional. Call immediately after the CALL


FUNCTION keyword to get the name of the server on which the parallel processing task will be
run.
Function module SPBT_DO_NOT_USE_SERVER: Optional. Excludes a particular server from further
use for processing parallel processing tasks. Use in conjunction with SPBT_GET_PP_DESTINATION
if you determine that a particular server is not available for parallel processing (for example,
COMMUNICATION FAILURE exception if a server becomes unavailable).

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.

Pradeep Kumar Nathmal

Page 4 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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.

Managing Resources with RFC Server Groups:


The parallel processing system has built-in safeguards that eliminate the possibility that a parallel job
can soak up all of the resources in an SAP system and cause performance problems for other jobs or
other users.
In addition to these built-in safeguards, you can optimize the sharing of resources through RFC server
groups. In the context of parallel processing, a group specifies the set of SAP application servers that
can be used for executing a particular program in parallel. By default (CALL FUNCTION STARTING
NEW TASK with the addition DESTINATION IN GROUP DEFAULT), the group is all servers that meet
the resource criteria. But you can also create your own more limited groups. You can view and
maintain groups with transaction RZ12 (Tools Administration Administration Network RFC
destinations and then RFC RFC groups).
You must specify the group to use in both the SPBT_INITIALIZE function module (if used) and in the
ABAP CALL FUNCTION STARTING NEW TASK keyword. Only one group is allowed per parallel ABAP
report or program (job step).

Messages and Exceptions:


In the function modules that you call, you should use exceptions for any error reporting, and not the
MESSAGE keyword. Exception handling is fully under your control in asynchronous RFC. You simply
add the exceptions generated by the function module to the reserved SYSTEM_FAILURE and
COMMUNICATIONS_FAILURE exceptions of the CALL FUNCTION keyword. You can then handle the
exceptions in the program that launches the parallel programming tasks.

Pradeep Kumar Nathmal

Page 5 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

Hands On Example Program:


1. Report: ZTEST_PARALLEL
REPORT ztest_parallel.
parameters: p_kunnr type kna1-kunnr.
data: functioncall1(1) type c,
cstgdetail1 type bapicustomer_kna1.
constants: done(1) type c value 'X'.

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.

* Receive remaining asynchronous replies


wait until functioncall1 = done.
write:/ cstgdetail1.
************************************************************************
*

FORM FUNCTION1_DONE

************************************************************************
form set_function1_done using taskname.
receive results from function 'BAPI_CUSTOMER_GETDETAIL2'
importing
customergeneraldetail

= cstgdetail1.

functioncall1 = done.
endform.

Pradeep Kumar Nathmal

Page 6 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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.

Pradeep Kumar Nathmal

Page 7 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

DATA: i_marc TYPE TABLE OF ty_marc INITIAL SIZE 0,


im_marc TYPE TABLE OF zty_marc INITIAL SIZE 0,
i_makt TYPE TABLE OF makt INITIAL SIZE 0,
i_final TYPE TABLE OF zmaraktx INITIAL SIZE 0,
wa_marc TYPE ty_marc,
wa_makt TYPE makt,
wa_final TYPE zmaraktx,
sr_werks TYPE RANGE OF t001w-werks.
*&---------------------------------------------------------------------*
*
S E L E C T I O N - S C R E E N
*
*&---------------------------------------------------------------------*
SELECT-OPTIONS: s_werks FOR g_werks OBLIGATORY.
*&---------------------------------------------------------------------*
*
I N I T I A L I Z A T I O N
*
*&---------------------------------------------------------------------*
INITIALIZATION.
*&---------------------------------------------------------------------*
*
A T S E L E C T I O N - S C R E E N
*
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*Validations
* PERFORM validate_data.
*&---------------------------------------------------------------------*
*
A T S E L E C T I O N - S C R E E N O U T P U T
*
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
*&---------------------------------------------------------------------*
*
S T A R T - O F - S E L E C T I O N
*
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Refresh Data
PERFORM refresh_data.
*Fetch & Email SAP Stock Data
Pradeep Kumar Nathmal

Page 8 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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

Parallel Processing in SAP ABAP

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

Parallel Processing in SAP ABAP

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

Parallel Processing in SAP ABAP

im_makt = i_makt[].
WRITE: / g_taskname.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
" DATA_FETCH

Pradeep Kumar Nathmal

Page 12 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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

Parallel Processing in SAP ABAP

maktx TYPE makt-maktx, "Material Description (Short Text)


END OF ty_final.
DATA: wa_marc TYPE zty_marc,
wa_makt TYPE makt,
i_final TYPE TABLE OF zmaraktx INITIAL SIZE 0,
wa_final TYPE zmaraktx.
CLEAR: wa_marc, wa_makt, i_final[], wa_final.
IF im_marc[] IS NOT INITIAL AND im_makt[] IS NOT INITIAL.
LOOP AT im_marc INTO wa_marc.
READ TABLE im_makt INTO wa_makt WITH KEY matnr = wa_marc-matnr.
IF sy-subrc EQ 0.
wa_final-matnr = wa_marc-matnr.
wa_final-werks = wa_marc-werks.
wa_final-maktx = wa_makt-maktx.
APPEND wa_final TO i_final.
CLEAR: wa_final.
ENDIF.
ENDLOOP.
IF i_final[] IS NOT INITIAL.
MODIFY zmaraktx FROM TABLE i_final[].
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
ENDFUNCTION.

Pradeep Kumar Nathmal

Page 14 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

Test Results:

Pradeep Kumar Nathmal

Page 15 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

Pradeep Kumar Nathmal

Page 16 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

Pradeep Kumar Nathmal

Page 17 of 18

8/19/2016
8:15:21 PM

Parallel Processing in SAP ABAP

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.

ABOUT WIPRO TECHNOLOGIES:


Wipro is the first PCMM Level 5 and SEI CMMi Level 5 certified IT Services Company globally. Wipro
provides comprehensive IT solutions and services (including systems integration, IS outsourcing,
package implementation, software application development and maintenance) and Research &
Development services (hardware and software design, development and implementation) to
corporations globally.
Wipro's unique value proposition is further delivered through our pioneering Offshore Outsourcing
Model and stringent Quality Processes of SEI and Six Sigma.

Pradeep Kumar Nathmal

Page 18 of 18

8/19/2016
8:15:21 PM

S-ar putea să vă placă și