|
To schedule/create a background job, use the Define Background Job function - menu path “System -> Services -> Jobs -> Define Job” (or transaction “SM36”). When creating a background job, you must specify a job name. Job name can have a maximum length of 32 characters. Try to give a meaningful name. For example: To schedule a weekly accounting report, job name should be like “Weekly accounting report”. When creating a background job, you must also specify a job class. This job class indicates the priority level of the background job (A - High, B - Middle & C - Low). This priority level determines the processing order of jobs with the same start criteria. The target host is not required. Normally, you will just leave this field blank. However, if you are using an SAP system that has multiple application servers (and each of these servers has background work processes), you can specify the specific application server on which the background job should be processed. Next, you should enter the steps (i.e., programs) to be included in the background job (see next slide). To indicate these steps, click on the ‘Step’ pushbutton.
Create Step for Background Job To include an ABAP program in a background job, you must specify the program name and, if necessary, its variant. A variant is a set of parameter values needed for the execution of a particular program. If a program has a selection screen, it will need a variant for background processing. To create a variant, you need to execute the program (Transaction SE38) and enter the appropriate values on the selection screen. Instead of executing the program, you will save these values as a variant by using the menu path “ GoTo -> Variants -> Save as variant ” or clicking on the ‘Save’ pushbutton. You need to give the variant a name and a description. This description should describe the parameter values of the variant. You will also want to change the print specifications so that the report is not sent to the printer immediately, but instead is placed in the print spool. After adding all the steps to the background job, you can indicate the start criteria for the job.
Start Criteria From the initial define background job screen, click on the ‘Start date’ pushbutton to indicate the start criteria for the background job. The options available for scheduling jobs are: - Immediate - allows you to start a job immediately.
- Date/Time - allows you to start a job at a specific date/time.
- After Job - allows you to start a job provided that another job has completed.
- After Event - allows you to specify the event when you want your job to run.
- At Operation Mode - allows you to start a job when the system switches to a particular operation mode.
Periodic Jobs You can schedule jobs to run at regular intervals, not just one time, by specifying a frequency. If you specify Immediate or a specific Date/Time, a job can run at regular intervals by checking the Periodic Job option. The ‘Period Values’ pushbutton allows you to specify how often you want the job to run (i.e., daily, weekly, monthly, etc.). You can also add certain restrictions by clicking on the ‘Restrictions’ pushbutton.
Scheduling Job after another Job The ‘After Job’ pushbutton allows you to start a job provided that another job has been completed. With this option, you must specify the name of the job that must be completed for the current job to run. If the “Start status-dependent” option is checked, the current job will only run if the specified job ends successfully. This option is useful in cases where the current job depends on the outcome of the specified job.
Scheduling Job after an Event The ‘After Event’ pushbutton allows you to specify the event when you want your job to run (i.e., your job will run only when the specified event is raised/triggered). With this option, you must specify the name of the event that must be triggered. You can distinguish between different occurrences of a particular event by specifying an event parameter (this concept is covered in a later slide). If you check the Periodic Job option, a new job will run each time the specified event is raised,not just the first time. Note: Before you can schedule a job to run after an event, the appropriate event must already exist (you can use the drop-down arrow to see existing events). There are two types of events: - System Events - events that are defined by SAP and triggered automatically when the system changes (i.e., SAP-defined event ‘SAP_OPMODE_SWITCH’ is triggered when the system’s operation mode changes).
- User Events - events that you define and trigger yourself. Create a user event with transaction “SM62”.
These types of events can only be used to trigger background jobs.
Triggering and Raising Events System events are triggered automatically by the system; we have no control over a job that is scheduled to run after a system event will occur. User events are not triggered automatically by the system; We can control a job (that is scheduled to run after a user event occurrence) to run by explicitly triggering the specified user event from some other program. User events can be triggered from: - ABAP program - use the function module ‘BP_EVENT_RAISE’ (see code above).
- External program - use the program SAPEVT.
- By “calling” the function module “BP_EVENT_RAISE” in an ABAP program, you trigger an event in the background processing system and all jobs that were based upon that event are started.
The only required exporting parameter is the eventid (name) of the event to raise. A job can be scheduled to wait for just a specific event to be triggered, or it can be scheduled to wait for a combination of an event and a specific event parameter. The optional eventparm exporting parameter is used for this event parameter.
|