How to Avoid Overlapping Batch Jobs in SAP

Periodic Batch Jobs or Background Jobs have a possibility of overlapping in SAP, especially, when the Batch Job runs in a high frequency like 5 mins or less. If the active Job doesn’t finish in 5 mins next Batch Job will be started in parallel to the currently active Job. Therefore, you could end up having the same Background Jobs running in parallel. This behavior can result in wrong processing of data and locking issues.

To avoid having overlapping Batch Jobs use standard program RSBTONEJOB. You need to set up the program RSBTONEJOB as the first step of the Batch Job. Variant of this program should be setup in such a way that parameter ‘JOBNAME’ is the same Job name you are trying to avoid overlapping.

Let’s assume you need to set program ‘RBDMIDOC’ which processes change pointers every 15 minutes and the name of the Background Job is ‘PROCESS_CHANGE_POINTERS’.

If you want to learn more about Change Pointers in SAP and program RBDMIDOC, go to my previous post on Change Pointers and iDocs.

Usually, the Background Job is set up as below with one step.

Background job with one step. Program RBDMIDOC and varient COND_A.
Background Job with one step

If you suspect this Job can run for more than 15 minutes, follow the steps below to adjust the Background Job not to overlap.

SAP Versions used in the illustration:

  • SAP S4 HANA Fashion 1709

Steps to Avoid the Overlapping of Batch Jobs.

Step 1: Save Variant for RSBTONEJOB with the Background Job Name.

There are several ways to save Variants for programs using transaction se38. The easiest way is to execute the program in se38 and fill in the selection screen parameters, then save it. This is the most common;ly known method to save Variants. Below, I will show another, less common way to save Variants.

Go to transaction se38 and set the program name as RSBTONEJOB. Then, select ‘Variants’ option and go to ‘Change’ mode.

add variant to program through transaction se38.
Add the Variant to the program

In the next step, provide a Variant name and click on ‘create’. You can provide any meaningful name for the Variant.

Create a variant for program RSBTONEJOB using se38.
Assign the Variant name and click on “create”

Use the background Job name you are trying to avoid overlapping as the
‘JOBNAME’ selection parameter. In this example, we are trying to stop Batch Job ‘PROCESS_CHANGE_POINTERS’ being overlapped.

Set the parameter JOBNAME of program RSBTONEJOB and click on attribute.
set the parameter JOBNAME

Click on ‘attribute’.

Provide the Variant description in the next step and save.

Set the variant description
Add Variant description

Step 2: Find the Background Job in Status ‘Released’ using Transaction SM37.

If you have already created the Batch job, you can find currently running job through transaction sm37. If you have not yet created the Batch Job, create it using transaction sm36 with the step sequence as shown in Step 4.

Go to sm37 transaction and provide the Job Name, Job Status selection and From/To Date selection, then press ‘Execute’.

Step 3: Change the Status of the Released Batch Job to ‘Scheduled’.

This step is important as we need to stop the Batch Job till we correct the Batch Job steps.

Select the Job with ‘Released’ status. This is the next Job which is queued up to start. Then go to the menu ‘Job’ then select ‘Released->Scheduled’.

Step 4: Add Overlapping Avoidance Program RSBTONEJOB to Batch Job.

In this step, we add the program ‘RSBTONEJOB’ with Variant ‘PROCESS_CHANGE’ we created in Step 1 as the first Step of the Background Job ‘PROCESS_CHANGE_POINTERS’.

Now, edit the Job steps of the Job we put on hold in Step 3.

Go to sm37, select the Job in ‘Scheduled’ status, then select Change.

Select the Batch Job in Scheduled status and select 'Change'
Change the Background Job steps

Using the highlighted tools, add program RSBTONEJOB as the first step of the Background Job.

Change the steps of the Background Job and add the program
RSBTONEJOB as the first step.

Step 5: Monitor the Batch Job.

If a Job runs more than 5 mins subsequently created Job will be canceled from the 1st Step of the Job.

Job log of the 2nd instance of the batch job. It has been cancelled by the step 1.
2nd instance of the Job cancelled

If you have any questions on how to avoid overlapping Batch Jobs, please leave a comment below.

8 thoughts on “How to Avoid Overlapping Batch Jobs in SAP

  1. Alok Jaiswal says:

    Hello Isuru, Thanks for the blog. Is there a way where if more than one job is running, job is not cancelled. RSBTONEJOB cancels the job if more than one instance of job is running, but we don’t want it to be cancelled just finished.

  2. Humberto says:

    Hi Isuru, nice info. If the job runs every 15 minutes, and finished in 10 minutes, so the next execution will start in 5 minutes right?
    The execution of job will continue without overlapping in that case?

    Thank you!

  3. Ramesh says:

    Hi Isuru,
    Because the job cancelled, Users getting unnecessary false email notifications. Is there any way we can avoid that?

Leave a Reply

Your email address will not be published. Required fields are marked *