Pages

Saturday 14 December 2013

SPTA Framework - Parallel Processing Technique in SAP ABAP


Now a day for some SAP program, the nights are getting too short to execute.
The CP industry, specially for distribution client the data volume is increasing very high day by day.


With the huge volume of data we are facing problems:
          Scheduled jobs are not finishing within the time frame.
          Dump for ABAP memory issue for huge data processing.
          Dump for timeout error for huge data processing.


SAP offers a solution for the problem: called parallel processing.
There are different frameworks available for parallel processing;
SPTA is the most popular one.


Let’s begin with one example of parallel processing with SPTA framework.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWXSaNKFL9uByrGPKyOUyfep-xV4rflPFF8O1DQjOaMlGtZzLQeXghKch7C8_ENjITEBv46aKmE8V5MVtMvkYaFaE3r9115s3jSQSu3MzSWDJb7tc3ECvsUlR2QAiNR1wh5SBUD8B9yZY/s640/1.jpg 


 We can predefined three parameters for SPTA framework.
  1. Server Group – Instances (maintained in RZ12).
  2. Maximum number of work packet per server instance.
  3. Maximum number of records per work packet.
Result:
Let’s assume one record takes 1 sec for processing.


Before implementing SPTA –
1000 records get processed one by one and it will take 1000 sec (16 min approx) to be processed.


After implementing SPTA –
All the 1000 records get processed into 10 different tasks and that runs parallel, so by this way it takes 100 records processing time to complete 1000 records process and that is 100 sec (2 min approx).


So the total performance improvement would be 800% which can turn around whole day running job into few minutes.


SPTA Framework in Details:


The SAP standard FM is SPTA_PARA_PROCESS_START_2.
There are three parameters by which we will call three subroutines to build our own logic for parallel processing.


  • BEFORE_RFC_CALLBACK_FORM: This routine is called by the function module before calling the RFC function module. Here we have to build different work packets which we want to process in the RFC function module.
  • IN_RFC_CALLBACK_FORM: This routine is called by the function module after work packets are created. In this routine we can use our own RFC enabled function module or custom code to process each work packets.
  • AFTER_RFC_CALLBACK_FORM: This routine is called at the end by the function module. After processing of all the work packets we have to collect all the processed data.


Other mandatory parameters are
·         SERVER_GROUP (we can pass our server group name which has been created from RZ12).
·         CALLBACK_PROG (The calling program name).
·         USER_PARAM (Data to be processed in SPTA process).


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUP76M05J6y2n3bDSydpinftEMtJoWVg8QU723eDtr5PxbYPqE0yXcYJ8YSs-8mpvlNflRtgOufr0wRLDRL4b0njTqU-53MOKSV-euK8lXyEgxOZWWgFAWMppzPFAikKmj_QaNPJvxhoA/s640/2.jpg


The main step in BEFORE_RFC_CALLBACK_FORM is WP (work packet) creation.
Here we are creating WP with maximum 10 records inside.


After finishing all the WP creation, all the WP will run in different tasks in parallel mode in IN_RFC_CALLBACK_FORM.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjechtABaw-9TrSGxWcyt6-3orOds4DMvVckryLwMO-LP0kCeK3yPlTrgq1MxE1TxWc2W21YTFBq1SbnonLiRTDq3KLqylsRTj6U8MCtvNedV_JXLQKIMx91KCMbOG9FKnTeXHTpTgYop0/s640/3.jpg


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiViaTi9CY_8G07eAuOW3WYSg9dNViVSMuJICicJ3Dng9vzq-IZrGD0vpOuLBm1HXisiTeoI_OJsyb9XF2Gq4CD6nzKE-XSHcksRPpxQ8MniJtAlowNTgYOAhywAcN5YCoraHvdSDr2BfU/s640/4.jpg


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh054ohm-NIV4l1GRhU2AvFumla4eEN1GKqytxHdbmDkLiKddO7NRgnrIbqY_mHpnRoxcWHw1EPAKCnwImh4uF6lgfeW_QtwmYYfvdR6cRdKCM7cmKbxMyZcP0-k5UffRYr-55EgGcLNsw/s640/5.jpg


Debugging SPTA using SRDEBUG:


It’s good to remember that sometime when different server instances being used in SPTA processing then only the external breakpoint would not work to go into debug mode. In this case we need to use SRDEBUG.



Parallel tasks (sessions) in SPTA:


Here I have tried to make a clear picture of all the WP creation and how all the WP run in different sessions or tasks.


I have putted a breakpoint in the IN_RFC subroutine and run the main program, all the WP being created in BEFORE_RFC and then all the task will run in parallel mode in IN_RFC.


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwdW2lqGxozTK2caet222ToH-vPwVAx88or5TbAupjfuw9GD_qGkwDLiv5Vmbe6kkJHj6yx4TYHOgz8MEOA5eag0kaIUDEVn00Yz5EZjeYbs6oHNmRdrJt4uCPSksc84AOXgZwUUf0FCg/s640/7.jpg

SAP has provided a sample demo program to understand SPTA Framework easily.
Program name -
SPTA_PARA_DEMO_1    Simple parallelization (without individual task dependence)






9 comments:

  1. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Regards,
    SAP Training in Chennai

    ReplyDelete
  2. Thanks, Useful information for me

    ReplyDelete
  3. Thanks for a the explanation.. It's nicely explained. I have used it couple of times but the explanation and visualization you have done is great.

    ReplyDelete
  4. Thanks for your explain. this blog is very usefull.

    ReplyDelete
  5. Thanks for sharing valuable information through your post. The information provided is of great use.
    SAP ABAP TRAINING IN HYDERABAD

    ReplyDelete
  6. Very useful information, thanks for sharing !!!

    ReplyDelete
  7. Great Post. The information provided is of great use as I got to learn new things. Keep Blogging.
    SAP ABAP TRAINING IN HYDERABAD

    ReplyDelete
  8. very usefull thanks, successfuly implemented SPTA in my ABAP Program

    SAP ABAP Tutorial

    ReplyDelete
  9. Great post....explanation is really very good...This information is impressive. Thanks Partha for sharing valuable information

    ReplyDelete