Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Enesyavuz
Explorer
1,047

Hi everyone,

In this blog, I will explain the use of background jobs in Parallel Processing.

First, let's answer the question, "What is a Background Job and Why Should We Use It?"

When performing parallel processing in SAP systems, dialog processes often hit the runtime timeout limit. In other words, when a process exceeds its time limit, the system terminates it. This can be a significant challenge for tasks that require longer execution times. However, using Background Jobs allows these processes to run in the background. Background jobs have much higher time limits, which means longer processes can be completed without any interruptions. This not only boosts the system's overall performance but also elevates the user experience by ensuring an uninterrupted workflow.

Scenario Overview

Let's query the 200,000 rows of sales order data using the BAPI_SALESORDER_GETSTATUS  for each order, both by using a loop and background jobs, and compare the execution times of both methods.

Retrieving Data from VBAK Table

The first step is to fetch sales order data from the VBAK table. We  limit the number of records to 200,000 and store them in internal table.

Enesyavuz_0-1738243391213.png

Running BAPI in LOOP

Enesyavuz_1-1738243426497.png

Running BAPI in a Background Job

The EXECUTE_BACKGROUND_JOB method splits the retrieved data into chunks of 10,000 records each and submits them to the SUBMIT_SALES_ORDER_JOB method, which starts background jobs for processing.

Enesyavuz_0-1738246418500.png

 

When the user triggers the program , The SUBMIT_SALES_ORDER_JOB method creates background jobs in the SAP system for processing the split sales order data.

Enesyavuz_3-1738243483347.png

 

When executed via a program job, the GET_SALES_STATUS method is triggered, allowing the system to retrieve the status of a sales order.

Enesyavuz_4-1738243483349.png

 

Running a Program with a LOOP

Enesyavuz_5-1738243538171.png

Enesyavuz_6-1738243538174.png

 

Running a Program with a Background Job

Enesyavuz_7-1738243538175.png

Enesyavuz_8-1738243538185.png

Enesyavuz_9-1738243538197.png

 

Results

When processing large data sets, using parallel processing with background jobs improves system performance and ensures business continuity. Unlike a single process that might fail and cause a dump, background jobs run independently, ensuring that critical operations are completed successfully.

You can visit my GitHub repository at https://github.com/EnesFYavuz/Background_Job to review the complete code.

 

2 Comments
Jelena_Perfiljeva
Active Contributor

Thanks for sharing!

I'm quite confused what is the use of this program. It reads 200k records from VBAK, then calls BAPI 200k times and then what? What would this achieve?

This "poor man's parallel processing" is usually used not for reading data but rather for posting / updating something. In the old systems like ECC, some postings required very long time. 3 seconds to post a document (unusual when BDC is involved) results in hours and even days when you need to post massive amount of them. So that's where you'd start spinning off multiple background jobs. Such activities would happen typically at the end of the month, during migration, initial data upload, etc.

Just to read the data we can obviously start multiple jobs too, but I don't see what purpose this could possibly serve. What would you do with the data in the end? How would you collect it from the multiple jobs?

There also don't seem to be any safeguards in place to prevent too many jobs from being generated. Basis folks won't be happy about this. 🙂 Sorry, I think this example choice is just not good. And the code is... not great either, sorry. You might want to check out Clean ABAP when you have time.

And one important correction. It says "Unlike a single process that might fail and cause a dump, background jobs run independently[...]". What caused a dump was not just a "single process", it was a dialog process. If you just ran the same thing as 1 job vs N jobs, it'd take more time but wouldn't cause a time-out dump.

There was another blog post about different approach to parallel processing. That post itself is not the best, but there were some good comments and links to other posts: https://community.sap.com/t5/technology-blogs-by-members/parallel-processing-on-oabap-using-classes-...

Enesyavuz
Explorer
0 Kudos

@Jelena_Perfiljeva  Thank you for your valuable feedback!

Actually, the purpose of the program is to demonstrate how parallel processing can be used for long-running operations (such as record creation, data updates, etc.). Here, I simply presented the method; it is entirely up to the users to determine how and in which scenarios they will use it.

Of course, parallel processing may not be necessary for data reading alone. However, in scenarios involving large-scale data processing, document creation, or updates, this method can be highly beneficial for improving performance. At this point, to minimize the impact of spawning too many jobs on system performance, precautions such as job limits or queue management can be implemented.

Labels in this area