Learn SAP — Parallel Processing in ABAP programing

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.

Advertisements

10 thoughts on “Learn SAP — Parallel Processing in ABAP programing

  1. 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.

  2. 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!

  3. 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.

  4. 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?

  5. 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
    This is correct this is parallel processing as in the new task will start in a new LUW with the main program running in another LUW this method is mainly used to combine different functionalities to run simultaneously when they are unrelated …

Leave a Reply to junior Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s