Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 17

How to create Background Jobs in SAP using

SM36
Assumption
These steps are based on the assumption that you are familiar with
SAP BASIS technology and terminology for BASIS, Web AS (WAS) with
versions 610, 620, 640, 700 and 710 as well as SAP transaction codes
(SM36, SM37). Users should also know what are SAP Work Processes
specially Batch Work Process which are responsible to execute
Background Jobs in SAP.

Background
Batch jobs or Background Jobs are SAP programs (either Standard or
Custom programs) that run in the system without the user interaction
at a specified date/time which is given during the creation of the Jobs.
These jobs can be an ad-hoc job or can be run on a periodic basis
(daily, hourly, weekly, monthly and others) which is also specified
during the create step of the jobs. Any program(s) that you want to run
without any user interaction and/or at any time (periodic/non-periodic),
it is the best candidate for background job.
Some of the programs require user input before they can execute, and
if we are running the program in background (using background jobs)
we don’t want system to halt or wait for the input before it can
continue. To solve this issue we (usually developers) create a Variant
(which is an input value for the related program) and save this. While
creating/defining a background job we have to give the variant name
(if required) so the program can continue without user input and take
the values as given in the variant.

SAP Background jobs are created using transaction code SM36 and
monitored/changed using transaction code SM37. Background Jobs are
usually run after business hours as they are resource intensive and
also to avoid any business disruptions during the regular work hours.
Example:
A company may have written a program
(Z_SOME_PROGRAM_NAME) that collects all the shipment data
from their retail system database for the entire day and ships the
goods to the customer.
This program needs to be executed at a time when the regular
business hour is over hence a background job
(Z_SOME_JOB_NAME) needs to be created which can run
uninterrupted at a specified time or on periodic basis.

Important
Background Jobs are executed by SAP Batch Work Process. An SAP
System can be made of multiple SAP instances and each instance may
comprise one or many Batch Work Process. We have to make sure that
we keep that in mind when scheduling Background Jobs so we have
free batch work process to execute each Background Job.

Implementation Steps
1. Execute transaction SM36 to get to the initial screen of creating
Background job

2. Click on Button

3. Click on button
4. In the following screen enter the following details and click
Continue
a. Job Name : Z_FIRST_JOB (you can chose any name based
on your company’s naming convention policy)
b. Job Class : C – Low Priority (This is the default option)
c. TargetServer: If you want your background job to run on a
particular instance of SAP, select a value from drop down
else leave it blank
5. In our example we will be creating a background job for SAP
standard program (RSPFPAR), hence we will choose “ABAP
program step” as the option. Even if it is a custom program
(Z_ANY_NAME) you will still select “ABAP program step”. If you
want to execute an external OS command or an external
program outside of SAP, you will select the appropriate radio
button below.
Select “ABAP program step” and click Continue
6. Based on your select in step 5 above, you will get screen as
below where you will have to enter a program name (in our
example RSPFPAR) and the variant from drop down. Please
proceed with selecting the variant “Z_TEST_VAR” which we
created for this program and at the end of this tutorial, you will
see “How to create variants in SAP”.

7. Select Variant “Z_TEST_VAR” and click the green check mark


8. Click Continue

9. One background job can consists of one or many programs which


can run in sequence depending on which order they have defined
while creating the background job. If you want to execute any
other programs, select “Add additional steps” and click Continue
button. In our example, we do not want to add any more
program or step as part of this background job, so we select
Continue without click the radio button.

10.As explained earlier, a background job can be scheduled for a


specified time or can be scheduled to run on a periodic basis. In
our example we would like to schedule the job weekly on
Mondays at 2200. To give the date and time, we select the radio
button “Date/time” and click Continue
11. If you want to execute the job just once on a specified date/time,
do not select the checkbox “Period”. In our example case we
want it to run periodic every Monday at 2200 so we select the
Scheduled start date (13th April 2009 which is a Monday), time
(2200) and the checkbox “Period” and click Continue.
12.Select “Weekly” because we want to execute this job on weekly
basis

13.The below screen shows that we have successfully created the


background job. Click Complete to finish the job definition
14.Once you hit Complete, you will see the message in the task bar
as shown in the below screen

15.To see the job that you created, you have to run transaction code
SM37 and enter the green check mark of hit the Enter key on
your keyboard

16. In the selection screen below, enter the Job name “Z_FIRST_JOB”
and user name as “*”. Select all the checkboxes and make sure
you select the From/To date appropriately (in our example case
we scheduled the job to run on 13th April, so the To date is
selected as “2009.04.13”. Click Execute
17.The resulting Job Overview screen shows that your job is in
Released status (Released means waiting for the date and time
to arrive so it can execute)

18.If you double click on the line (Z_FIRST_JOB) it will take you to
the details of the job which indicates Weekly and Start date and
time of the job.
Click Back to come to the Job Overview screen.
19. In our example we changed the date and time of the job as we
want to run it immediately to see the result (this is done just for
example purpose. You may however have a need to change job
date and time if there is a need from business).
From screen in step 17, select the line “Z_FIRST_JOB” and go to
menu option Job  Change

20.Click on Start condition

21. Select Immediate and then the Save button.

22. As soon as we select Immediate we can see the job starts and
completes right away (the completion time of the job depends on
which program it is executing and how long the program runs
for).

23.Select the job and click the Spool button

24. Click the button to display the spool contents. Spool contents
are the actual content of the job

25.The below screen shows the contents of the Background Job


which is same as shown in step 31 below. It does not matter if
you execute the job in Dialog (Foreground) or Background mode.
the result always remains the same, only the method to execute
the job is different (foreground vs background).
How to create Variants in SAP
Assumption
These steps are usually performed by developers as they are the one
who creates programs. The steps shown below are for illustration
purpose and can be used as an example for program RSPFPAR. Each
program may have its own set of input screen(s) and need to be
handled differently hence needs caution. Our example shows variant
creation process for program RSPFPAR so the background job can run
without any user input by using the values from the variant
(Z_TEST_VAR). Users should also be familiar with ABAP transaction
code SE38.

Background
RSPFPAR is a standard SAP program which shows all the system profile
parameters and their values. Since there are hundreds of system
parameters in the system, we may only have a need to see a few
parameter values. For this reason, we have to give input values in the
screen so the system can only pull out limited values based on our
selection. Since we have to execute this program in background we
want the system to pick the values from the variant that we create so
the Job can run un-interrupted without user interaction. In our example
we want to create variant for the following 3 system profile parameters
– ipc/shm_psize_40, rdisp/msserv and ztta/parameter_area. You
will see in a moment how to create this.

Implementation Steps
26.Execute transaction code SE38 from your initial SAP screen and
hit Enter on your keyboard

27. Enter program name RSPFPAR and click Execute button


28. In the below screen if you click on Execute without entering any
values in the empty text fields, the system will give you all the
system profile parameter values. However in our case we only
want the values for 3 system profile parameters as mentioned in
the Background section. To do that, we will select the drop down
button

29. In this screen, enter the parameter names for which you would
like to see the values and click Execute button
30. You will be returned to the initial screen and this time there is a
value in the first text field; however the second text field is
blank. The green color in this button indicates that there are
values inside. You can click that button again to verify that your
parameters are specified correctly.

31. Click on Execute button to see the results in Dialog


(foreground)

32. Now we want to see the same result in background mode without
user interaction. For this reason we will go back to the initial
screen as per step 5 by clicking the Back button and save the
screen input as variant by using menu option Goto  Variants 
Save as Variant

33. Give the variant name as Z_TEST_VAR and Meaning Variant for
Profile Parameters and click Save to save the screen.

34.You will be returned to the initial screen with this message in the
task bar

35.This variant can now be used in the step 6 above.

You might also like