You are on page 1of 9

Products

Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner

About
About


Home / Community / Blogs + Actions

Parallel Processing Example Code


August 20, 2012 | 9,763 Views |

Kishore Kumar Vemula


more by this author

ABAP Development

asynchronous processing | code exchange | end of task | new task | parallel group | parallel processing

share share tweet share

Follow

Most of the time when dealing with huge amount of data, the run time /
execution time of a program should be with in the specified time limit.
To overcome this, SAP has provided a wonderful tool called Parallel
processing.

My attempt to provide an example for parallel processing.


Requirement:
Get the list of Contracts (New, Terminated and Active as on date) for a
given period and retrieve the additional information using parallel
processing.

Solution:
Requirement is seems to be simple. But, yes scanning
CRMD_ORDERADM_H for all the contracts and retrieving the additional
data (Partner, Product, Customer etc..) for each contract is not an easy and
quick task.

Parallel processing has been introduced to complete the report with in the
specified time.

Selection Screen:

Parallel processing code:


1. Do the Initial selection of contracts based on the Period.

2. Call the FM SPBT_INITIALIZE to know the Maximum work process


and free work process by passing the server group name
(parallel_generators)

3.
4. Note: For server group details, the number of maximum work
process you can use under this group are best answered by your
BASIS team. In practice, BASIS will provide a dedicated application
sever group for parallel processing.

5. Based on the selection screen entry (number of records per call),


move these many records into an internal table for parallel
processing.

6. If you want to track the number of records processed, use below


statements to see the job log while the program is running.

7. CONCATENATE Total Records to be processed are lv_gtot INTO


lv_string.
MESSAGE lv_string TYPE I.

8. Here lv_gtot is the number of lines of the internal table which is


passed to parallel processing FM

9. Retrieve the resources info by calling FM


SPBT_GET_CURR_RESOURCE_INFO and check against the
selection screen entry Maximum no of work process to be used.

10. If the available work process is greater than specified, and the
running work process are within the max limit, call the RFC Function
module in Asynchronous mode. If not wait for the free work process
and try again.

11. When the RFC is called, please check the returned sy-subrc value. If
it is initial, count the number of submitted RFC.

12. Continue the submission of Asynchronous RFC till all the records are
processed.

13. The RFC is executed in the next available work process in the said
server group and the results are captured under Call back routine
ON END OF TASK.

14. In the receiving routine count the number of RFC received.

15. As this is asynchronous calls, we need to wait until the number of


sent calls and received should be equal.

Code snippet:
Perform f_init_server_group screen shot attached at the top of the page.

Here in below, we are calling the RFC Function module which does the
actual work. It retries the all the requested information for the passed chunk
of data.

Once the FM is executed fully, then the call back routine f_call_back* is
called.
In the below call back routine, we will capture the processed records with
all the information.

The final internal table gt_*_in2 will holds the all the information.

If any data base update is required then it should be done in the RFC
itself.
For tracking of the records processed, use MESSAGE statement
where ever required.

And last but not least, dont forget to wait till the sent RFC calls should
be equal to received RFC Calls.

Alert Moderator

8 Comments
You must be Logged on to comment or reply to a post.

Adam Krawczyk

February 27, 2013 at 12:48 pm

Hi Kishore,

Quite nice blog with good content, showing possibility of parallel processing. Good
examples are used and valid pattern with counting of send / received jobs. Thank
you.

Some hints for better presentation as it is not easy to read and understand:
Instead of splitting long code into different screenshots, it would be better to split
code into modules / class methods and present each of them and show the main
one as well. Then we would have clear picture of what is happening in program.
With current splitting I am not sure if there is still loop, which IF/CASE I am in etc.
Painting on some variables to make them unreadable disturbs code reading, as
we do not know if line of code refers to same or other variable. If data is critical,
why not to change names in code before posting screenshots?

Regards
Adam

nabheet madan

February 28, 2013 at 6:12 pm


Thanks for the blog.

Additional information can be found in below mentioned links

http://wiki.sdn.sap.com/wiki/display/ABAP/Parallel+Processing

http://help.sap.com/saphelp_nw70/helpdata/en/fa/096e92543b11d1898e0000e8322d
00/content.htm

Nabheet

Erlon Loureno

February 4, 2014 at 4:44 pm

Thanks for the blog.


Helped a lot.

Regards
Erlon Loureno

Arnab Das

February 8, 2014 at 11:02 am

good one

Kishore Kumar Vemula Post author

November 11, 2014 at 9:01 am

@Adam Krawczyk thank you for the feedback on the same. I will keep in mind your suggestions for
future work on SCN

@Erlon Loureno I have been encouraged by your feedback.Thank you


@Arnab Das Thank you

Erlon Loureno
November 16, 2014 at 3:55 pm

Congratulations for the blog.

Erlon Loureno

Rajesh Khande

January 20, 2015 at 4:29 pm

Hello Kishore,

This is a nice blog and very helpful.

However I agree if the code is one screenshot it would have been better to read and
follow the steps.

I have couple questions and I really appreciate your response:

1) I wonder what was returned from the receiving function module and how exactly
you have achieved.

2) I would like to write an application log after the parallel processing. not sure how
this can be done. did you do this before?

Thanks
Raj

Kishore Kumar Vemula Post author

January 24, 2015 at 7:40 am

Hi Rajesh, yes your are right. It would have been helpful if the code was
clear in the blog.
1. The code which needs to be executed in parallel processing will be
included in FM. This FM is triggered in different work process each time.
For example, you need to run the FM for 100 records each time. And
the FM will trigger parallel in 10 work process at a time(based on
setting).
If any of the FM execution is completed then End of Task event is
triggered. Based on the event the Export parameters of FM can be
captured under Receiving FM via statement RECEIVE RESULTS
FROM FUNCTION ZXXXXXXXXXX
IMPORTING
et_result = lt_result.
Here LT_RESULT is the export parameter in FM ZXXXXXXXX. You
need to declare the LT_RESULT as such that what information you
need in the output of the report.

2. Application Log is possible in one way.


While passing the records to Parallel processing, you can write a log
that what information you are passing using Writ statement. for
example, Billing documents number 1001 to 2000 are passed to
parallel processing for task/Job number 1.

And, when you are receiving the result, just capture how many records
you revived for which task/Job number

But parallel processing always has a risk of loosing some data if any of
work process is failed or restarted.

Share & Follow


Privacy Terms of Use Legal Disclosure Copyright Trademark Sitemap Newsletter

You might also like