In this post let us see how we can write a parallel processing report. I explained here and the code is at end of the post.
The usual way of programming is serial processing. The program executes one line at a time and if you call a function that will wait until the control returns from the function and executes the rest of the code. In some case you might be calling the same function again and again for different set of master data. You know that there wont be any conflict between the data and you would like to execute the same function multiple times with different set of data. We need to do this in parallel processing this way the process will be completed much faster with multiple processes in different servers. Let us see how we can achieve this with an example.
Let us assume that we have 1 million BP and we need to check some condition and set a value Y or N according to that condition and this code is in a Z function which get input of 1000 BP at a time. Let write a program which can execute the same function multiple time until the process is ready.
I created a report in SE38 with name as Z_TEST_PARALLEL .
First we need to get the number of max resources available and number of resources free using the following sap standard function. Only initialize only once and next times use the SPBT_GET_CURR_RESOURCE_INFO function to get the available resources.
SAP Function ‘SPBT_INITIALIZE’
This will give you the information that we need to do the parallel processing. Now loop thru the data and gather the information that you want to process let us say like 1000 bp at a time and execute the z function with 1000 bp at a time. once you reached the max number of resource you need to wait until some resource is available and if the resource is available then continue and wait until all the process is completed.
You have to call the function not using the regular call but using the new task call. See the following
CALL FUNCTION ‘Z***(your function name)’
STARTING NEW TASK taskname
DESTINATION IN GROUP srv_grp
PERFORMING return_back_this_task
ON END OF TASK
EXPORTING
…………………..
TABLES
………………….
EXCEPTIONS
resource_failure = 1
system_failure = 2
communication_failure = 3
OTHERS = 4.
The above function is called in the new task which process in a separate session. You call the above function multiple times with 1000 records at a time and wait for the process to be completed. On each task is completed the return_back_this_task perform is executed and the result will be received from that task. Once all the results are collected the process will be completed and the control will return back to the main program. See the following sample code for parallel processing.
I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work. Look forward to reading more from you in the future.
Comment by mySAP — June 27, 2009 @ 10:33 pm
Pretty good post. I just came across your site and wanted to say that I’ve really enjoyed reading your posts. In any case I’ll be subscribing to your feed and I hope you will keep a good work!
Comment by SAP Solution — June 27, 2009 @ 10:35 pm
Hi,
I am also an ABAP CRM developer and have received via friend indication your blog link.
I really have appreciate your initiative to share with the globe what you have learned.
Congratulations.
Your blog is preatty cool !
Regards,
Rodolfo Miao
Sao Paulo – Brazil.
Comment by Rodolfo — July 6, 2009 @ 6:54 am
Hi Rodolfo Miao,
Thanks.
Kumar.
Comment by kumar — July 6, 2009 @ 3:00 pm
Hi, after read your code, I cant’t understand the variant of ‘running’
you do not give value to it, but only use ‘running = running – 1.’
how can this work?
Comment by Jeffrey — July 7, 2009 @ 12:23 am
You are right you need to add the running = running + 1 in the FORM spawn_arfc_bp_process module. I corrected that. Thanks.
Comment by kumar — July 7, 2009 @ 7:58 am
Good post. does that also work on servers with one core?
Comment by james — September 20, 2009 @ 4:37 pm
Nice post, keep it up, thanq
Comment by Shiva — October 6, 2009 @ 11:48 am