DATA: lt_rspar TYPE TABLE OF rsparams,
ls_rspar TYPE rsparams,
lv_jobname TYPE btcjob VALUE ‘Z_BACKJOG’, "设置作业名称
lv_jobcount TYPE btcjobcnt.
"设置宏,批量写入执行条件
CLEAR lt_rspar[].
DEFINE add_rspars.
CLEAR ls_rspar.
ls_rspar-selname = &1.
ls_rspar-kind = ‘S’.
ls_rspar-SIGN = ‘I’.
ls_rspar-option = ‘EQ’.
ls_rspar-low = &2.
APPEND ls_rspar TO lt_rspar.
END-OF-DEFINITION.
add_rspars ‘执行条件字段1’ ‘值1’ .
add_rspars ‘执行条件字段’2 ‘值’2 .
CALL FUNCTION ‘JOB_OPEN’
EXPORTING
jobname = lv_jobname "作业名称
IMPORTING
jobcount = lv_jobcount “作业ID
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE ‘计划后台作业时出错;程序已取消’ TYPE ‘S’ display LIKE ‘E’.
RETURN.
ENDIF.
SUBMIT 后台程序名
WITH selection-TABLE lt_rspar
via job lv_jobname
NUMBER lv_jobcount
AND RETURN.
CALL FUNCTION ‘JOB_CLOSE’
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
invalid_target = 8
OTHERS = 9.
IF sy-subrc NE 0.
MESSAGE ‘计划后台作业时出错;程序已取消’ TYPE ‘S’ display LIKE ‘E’.
RETURN.
ENDIF.
MESSAGE ‘已计划后台作业,请稍后查询下达状态’ TYPE ‘S’ .
温馨提示:设置后台作业时,需要对执行单据做状态判断 避免重复点击时重复作业