Using an Event to Trigger a Background Job

SAP provides the capability to trigger background jobs through event initiation. These events must be configured in advance and can later be triggered, for example, from an ABAP program. Below is a small example demonstrating this capability.

0. Theoretical Background

See:  Events in Background Processing Explained

1. Objective

Trigger a background job by initiating an event. The event should be triggered from an ABAP program.

2. Initial Data

For this example, I’ll run a report in the background that is available via transaction S_PH0_48000450. A variant has already been configured for this report.

See: Monitoring of Tasks (Infotype 0019)
0:00
/0:11

3. Creating an Event

Create a new event using transaction SM62.

0:00
/0:26

4. Scheduling the Background Job

The following video shows the step-by-step process for scheduling a background job that waits for the preconfigured event (see Step #3).

0:00
/0:52

5. Triggering the Event from an ABAP Program

To trigger the event, I’ll create a program that calls the function module BP_EVENT_RAISE.

See: BP_EVENT_RAISE: Trigger an Event from an ABAP Program
0:00
/1:50
REPORT zdemo_job_schedule.
 
DATA: lv_start TYPE boolean VALUE abap_false.
 
IF lv_start EQ abap_true.
  CALL FUNCTION 'BP_EVENT_RAISE'
    EXPORTING
      eventid                = 'ZDEMO_EVENT'
*     EVENTPARM              = ' '
*     TARGET_INSTANCE        = ' '
*     TARGET_MODE            = ' '
    EXCEPTIONS
      bad_eventid            = 1
      eventid_does_not_exist = 2
      eventid_missing        = 3
      raise_failed           = 4
      OTHERS                 = 5.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
ENDIF.

I launch the program after first verifying in transaction SM37 that there are no jobs scheduled under my user.

0:00
/1:25

Note: If you don’t activate the Periodic Job parameter during scheduling,
the background job will run only once.

And here’s a clear example of that.

0:00
/1:19

6. Program BTC_EVENT_RAISE

You can also trigger the created event using the standard program BTC_EVENT_RAISE. A short video below demonstrates this.

0:00
/0:36

7. Event Call Logging

You can enable logging of event calls if needed.

0:00
/0:46

Give it a try.

0:00
/1:27

If logging isn’t necessary, it can be disabled. Thanks for your attention. Sending you New Year hugs. With love, ignatov.