JOB_OPEN / JOB_SUBMIT / JOB_CLOSE¶
The three-FM pattern — create, define, and release a background job programmatically.
Purpose¶
Use this pattern to schedule background jobs from ABAP code: after processing a file upload, from a user action, or to trigger asynchronous processing. The job appears in SM37 and runs under the standard background processing framework.
The three-FM pattern¶
1 — JOB_OPEN¶
Creates the job entry and returns a jobcount handle.
| Parameter | Direction | Description |
|---|---|---|
JOBNAME |
Importing | Job name (max 32 chars) |
JOBCOUNT |
Exporting | Unique job ID — pass to JOB_SUBMIT and JOB_CLOSE |
2 — JOB_SUBMIT¶
Defines the job step (report + variant, or ABAP class).
| Parameter | Direction | Description |
|---|---|---|
JOBNAME |
Importing | Job name |
JOBCOUNT |
Importing | Job ID from JOB_OPEN |
REPORT |
Importing | Report name to run |
VARIANT |
Importing | Selection screen variant (optional) |
LANGUAGE |
Importing | Logon language (default: sy-langu) |
AUTHCKNAM |
Importing | User whose authorizations are checked when the job runs |
3 — JOB_CLOSE¶
Releases the job for scheduling.
| Parameter | Direction | Description |
|---|---|---|
JOBNAME |
Importing | Job name |
JOBCOUNT |
Importing | Job ID |
STRTIMMED |
Importing | 'X' = start immediately |
SDLSTRTDT |
Importing | Scheduled start date (TYPE TBTCSTRT-SDLSTRTDT) |
SDLSTRTTM |
Importing | Scheduled start time (TYPE TBTCSTRT-SDLSTRTTM) |
AT_OPMODE |
Importing | Operation mode for time-based scheduling |
Example — start immediately¶
DATA: lv_jobname TYPE tbtcjob-jobname VALUE 'ZMATERIAL_SYNC',
lv_jobcount TYPE tbtcjob-jobcount.
" Step 1 — open
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
EXCEPTIONS
cant_create_job = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Could not create background job' TYPE 'E'.
RETURN.
ENDIF.
" Step 2 — define step
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
report = 'ZMATERIAL_SYNC_REPORT'
variant = 'STANDARD'
language = sy-langu
authcknam = sy-uname
EXCEPTIONS
cant_create_step = 1
OTHERS = 2.
IF sy-subrc <> 0.
" Delete the orphaned job header
CALL FUNCTION 'BP_JOB_DELETE'
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
EXCEPTIONS
OTHERS = 1.
MESSAGE 'Could not define job step' TYPE 'E'.
RETURN.
ENDIF.
" Step 3 — release immediately
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
strtimmed = abap_true
EXCEPTIONS
cant_start_immediate = 1
OTHERS = 2.
IF sy-subrc = 0.
MESSAGE |Job { lv_jobname } submitted| TYPE 'S'.
ELSE.
MESSAGE 'Could not release job' TYPE 'E'.
ENDIF.
Example — schedule at a specific date/time¶
DATA: lv_start_date TYPE tbtcjob-sdlstrtdt,
lv_start_time TYPE tbtcjob-sdlstrttm.
lv_start_date = sy-datum + 1. " tomorrow
lv_start_time = '060000'. " 06:00:00
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
sdlstrtdt = lv_start_date
sdlstrttm = lv_start_time
startdttyp = 'D' " D = date/time scheduled start
EXCEPTIONS
OTHERS = 1.
Common pitfalls¶
Clean up orphaned jobs on error
If JOB_OPEN succeeds but JOB_SUBMIT fails, the job header is left in an incomplete state. Call BP_JOB_DELETE (not JOB_CLOSE) in the error path to remove the orphaned entry — JOB_CLOSE has no delete flag parameter.
The report must have a matching variant
If VARIANT does not exist for the report, JOB_SUBMIT fails. Create the variant first in SE38 (Program → Variants → Save as Variant), or omit it to run with default selection screen values.
- Authorization: The calling user needs
S_BTCH_JOB(object typeJOBACTION = RELEto release) andS_BTCH_ADMif running under a different user. - Job log: Check SM37 → select job → Job Log for detailed step output.
See also¶
- How to create a background job programmatically — full tutorial
- Transaction SM36 — schedule background jobs manually
- Transaction SM37 — background job monitor
DYNPRO_SEND_IN_BACKGROUND— dump when background job calls UI