ERPClimb logoERPClimb

Code examples · Modern ABAP · Intermediate

Run a report in the background: JOB_OPEN, SUBMIT VIA JOB, JOB_CLOSE and check it in SM37

The problem

A report that takes ten minutes must not block a user's screen.

How we solve it

  1. 1The reportwhat runs
  2. 2OpenJOB_OPEN
  3. 3Add stepSUBMIT VIA JOB
  4. 4CloseJOB_CLOSE

The result

The program prints the job name and job count, and SM37 shows the job and its finished status.

Overview drawn by ERPClimb from this example. The steps are the same as in the code below.

1. The requirement

A report that takes ten minutes must not block a user's screen. A button or another program must start it as a background job with a parameter and report where the job can be watched.

2. How we design it

A background job is a list of steps that the system runs without a user at the screen. In code you create it in three moves: JOB_OPEN reserves a job name and returns a job count, SUBMIT ... VIA JOB adds the report as a step with its parameters, and JOB_CLOSE closes the job and tells the system when to start it. Job name plus job count identify the job in transaction SM37, where you see the status (scheduled, released, active, finished or cancelled) and the log.

Why we decided it this way

  1. 1A job in code instead of 'run in background' by handThe program decides the parameters and the time, and the same call works from a button, an enhancement or another report.
  2. 2Check SY-SUBRC after JOB_OPEN and JOB_CLOSEIf the job cannot be created or closed, there is no job. Printing success without checking would be false.
  3. 3Start immediately only for the demoSTRTIMMED = abap_true starts at once. A real job would set a start date and time or follow another job.

Before you start

  • A user who may schedule jobs (authorization object S_BTCH_JOB).
  • ADT and a package such as $TMP, or SAP GUI to create the report in SE38.

3. The code, step by step

Step 1 of 4: The report that will run

A small report with one parameter, so the job has something to run.

ABAP · Report · ZDEMO_JOB_REPORT
" A report with a parameter
REPORT zdemo_job_report.
PARAMETERS p_days TYPE i DEFAULT 7.

START-OF-SELECTION.
  WRITE: / |The report ran for { p_days } days|.
Part by part (plain text)
  1. A report with a parameter. PARAMETERS creates an input field with a default value. START-OF-SELECTION is where the report starts running. In a real job this is the long running work. Here it only writes one line, so you can see it in the job log.

Open in the portal

The SAP objects named in this code are linked in the code above and listed here. Each opens its page in the SAP Library.

Function modules

4. The final outcome

The program prints the job name and job count, and SM37 shows the job and its finished status.

What you should see

Job ZDEMO_JOB 12345678 started In SM37 (job name ZDEMO_JOB): status Finished, step with the program ZDEMO_JOB_REPORT and a temporary variant that holds P_DAYS = 7 The spool or job log shows: The report ran for 7 days

Try it and check the result

  • Create and activate the report ZDEMO_JOB_REPORT and the class, then run the class with F9.
  • Open transaction SM37, enter the job name ZDEMO_JOB and a date range of today, and execute. The job is listed. Press F5 until the status is Finished, then select it and open the job log or the spool list.
  • Comment out the SUBMIT statement and run again: JOB_CLOSE raises job_nosteps, and the program prints that the job could not be started.

Common mistakes

  • A job that was opened but never closed stays in status Scheduled without a start. Always close it, also after an error between open and close.
  • A background job runs as the user of the job, not as the user who clicked. The authorizations of that user decide what the report may read.
  • Never schedule the same job with the same name over and over without cleaning up: SM37 fills up. Use a unique name per purpose and delete finished jobs by a housekeeping job.
  • Do not use the old trick of a dialog screen inside a background report. A background job has no user to answer.

Keep learning

Checking status: Reviewed line by line against SAP documentation. Not executed on a live system. Reviewed 2026-11-25. Release: Classic ABAP on S/4HANA or ECC. These function modules and statements are not available in ABAP Cloud.

Original ERPClimb teaching code with illustrative names. Not taken from a customer system. Syntax can differ by release; check the references below and activate in a sandbox first. ERPClimb is independent of SAP SE.