Skip to main content

Module 24: Background Jobs & Scheduling

Background jobs allow ABAP programs to run without user interaction, typically for batch processing, interfaces, data loads, and housekeeping tasks.

In real systems, most critical processing happens in background.


1. Why Background Jobs?

Background jobs are used when:

  • Processing is long-running
  • Large data volumes are involved
  • No UI interaction is required
  • Execution must be scheduled (daily, weekly, etc.)
Production Reality

Well-designed background jobs are stable, restartable, and monitored.


2. Job Creation

Jobs are created and managed using transaction SM36 (create) and SM37 (monitor).


2.1 Job Lifecycle

Created → Released → Ready → Active → Finished / Cancelled

2.2 Creating a Job (Conceptual Flow)

  • Define job name

  • Assign job steps (ABAP program / external command)

  • Define start condition

  • Release the job

2.3 Programmatic Job Creation (ABAP)

CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
report = 'Z_BATCH_PROGRAM'.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
strtimmed = abap_true.
Modern Practice

Most jobs are created via SM36, not programmatically—ABAP job creation is used only in special cases.

3. Job Classes

Job classes define priority and resource usage.

3.1 Job Class Types

Job ClassPriorityUsage
AHighCritical / urgent jobs
BMediumNormal business jobs
CLowHousekeeping / reports
Governance Rule

Job class A must be approved by BASIS.

3.2 Choosing the Right Job Class

Decision Rule
  • Financial close → Class A (rare)

  • Daily batch jobs → Class B

  • Reports / cleanup → Class C

4. Spool Handling

Background jobs typically generate spool requests.

4.1 What is a Spool?

A spool is:

  • Output generated by a background job

  • Stored on the application server

  • Viewable via SP01 / SM37

4.2 Accessing Spool Programmatically

NEW-PAGE PRINT ON.
WRITE: 'Batch job output'.
NEW-PAGE PRINT OFF.

4.3 Controlling Spool Behavior

SUBMIT z_report
TO SAP-SPOOL
WITHOUT SPOOL DYNPRO
WITH p_param = lv_value.
Best Practice

Suppress spool output unless business users explicitly need it.

5. Error Handling in Background Jobs

5.1 Why Error Handling is Critical

Background jobs:

  • Have no user interaction

  • Must detect and report errors automatically

  • Must be restartable

Production Rule

A failing job with no error logging is worse than no job.

5.2 Detecting Errors

Common techniques:

  • SY-SUBRC checks

  • TRY…CATCH blocks

  • Return codes

  • Application logs (SLG1)

TRY.
lo_service->process( ).
CATCH cx_root INTO DATA(lo_exc).
" Log error
ENDTRY.

Use Application Log (SLG1) for job errors.

CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_log_handle
i_msgty = 'E'
i_msgid = 'ZMSG'
i_msgno = '001'.
Modern Standard

Use SLG1 logs, not WRITE statements, for background jobs.

5.4 Job Status on Errors

  • Unhandled exception → Job Cancelled

  • Controlled error → Job Finished, error logged

Interview Insight

A job should finish gracefully whenever possible.

6. Restartability & Idempotency

6.1 Restartable Jobs

A good job:

  • Can be restarted without data corruption

  • Handles partial execution

  • Uses checkpoints or status tables

Design Rule

Design jobs to be idempotent wherever possible.

7. Common Mistakes

Avoid These
  • Using WRITE instead of logs

  • No error handling

  • Long-running dialog programs

  • Hard-coded job parameters

  • Excessive spool generation

8. Interview-Grade Answer

Q: How do you design a reliable background job?

Answer:

I ensure the job runs in background-safe mode, uses proper error handling and application logging, minimizes spool output, selects the appropriate job class, and is designed to be restartable without data inconsistencies.

This Answer Works

This shows real production experience, not just theory.

9. Summary

  • Background jobs run without user interaction

  • Created via SM36 or ABAP APIs

  • Job classes control priority

  • Spool handles output

  • Error handling and logging are critical

  • Jobs must be restartable

10. Practice Exercises

  • Create a background job using SM36.

  • Run and monitor it in SM37.

  • Suppress unnecessary spool output.

  • Log errors using SLG1.

  • Simulate a job failure and analyze logs.

11. What’s Next?

➡️ Module 25: RFC, BAPI & Integration

Learning Tip

Background jobs are the heartbeat of enterprise SAP systems.