Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125
Beginner

Automating SAP Reports: How to Schedule Background Jobs via ABAP

Scenario:

  • Business wants to run a Sales Order Report (ZSD_SALES_ORDER_REPORT) every night automatically in the background.

  • Instead of manual execution, a background job is scheduled from the ABAP program.

CODE:

 

REPORT z_schedule_bg_job.

DATA: lv_jobname TYPE tbtcjob-jobname VALUE ‘Z_SALES_ORDER_JOB’,
lv_jobcount TYPE tbtcjob-jobcount,
lv_subrc TYPE sy-subrc.

PARAMETERS: p_variant TYPE variant OPTIONAL.

START-OF-SELECTION.

” 1. Open Job
CALL FUNCTION ‘JOB_OPEN’
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.

IF sy-subrc <> 0.
MESSAGE ‘Unable to create background job’ TYPE ‘E’.
ENDIF.

” 2. Submit Report to Job
CALL FUNCTION ‘JOB_SUBMIT’
EXPORTING
jobname = lv_jobname
jobcount = lv_jobcount
report = ‘ZSD_SALES_ORDER_REPORT’
variant = p_variant
EXCEPTIONS
bad_priparams = 1
jobname_missing = 2
job_notex = 3
program_missing = 4
variant_missing = 5
OTHERS = 6.

IF sy-subrc <> 0.
MESSAGE ‘Error submitting report to job’ TYPE ‘E’.
ENDIF.

” 3. Close Job (Schedule for immediate or background processing)
CALL FUNCTION ‘JOB_CLOSE’
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
strtimmed = ‘X’ ” Start immediately
language = sy-langu
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
OTHERS = 6.

IF sy-subrc = 0.
MESSAGE |Background Job { lv_jobname } scheduled successfully.| TYPE ‘S’.
ELSE.
MESSAGE ‘Error closing job’ TYPE ‘E’.
ENDIF.

 

How it works

  1. JOB_OPEN → Creates the background job and returns a job count.

  2. JOB_SUBMIT → Assigns a report (with optional variant) to the job.

  3. JOB_CLOSE → Schedules the job for execution (immediately or at a specified time).

Related Questions

Leave an answer

Leave an answer