通过ABAP程序,布置后台Job一般步骤:
- 打开作业队列(JOB_OPEN)
- 调用(SUBMIT)想在此作业进程中,执行的程序
- 关闭作业进程(JOB_CLOSE)
"创建后台JOB,调用ZPPR0010_C
DATA: lv_jobname TYPE tbtcjob-jobname,
lv_jobcount TYPE tbtcjob-jobcount.
lv_jobname = sy-datum && sy-uzeit && '_' && 'ZPPR0010' && '_' && sy-uname.
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.
DATA: lt_rsparams LIKE TABLE OF rsparams,
ls_rsparams LIKE rsparams.
LOOP AT s_pcode.
MOVE-CORRESPONDING s_pcode TO ls_rsparams.
ls_rsparams-selname = 'S_PCODE'.
ls_rsparams-kind = 'S'.
APPEND ls_rsparams TO lt_rsparams.
CLEAR ls_rsparams.
ENDLOOP.
SUBMIT zppr0010_c WITH SELECTION-TABLE lt_rsparams
VIA JOB lv_jobname
NUMBER lv_jobcount
AND RETURN.
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
strtimmed = 'X'
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc EQ 0.
MESSAGE s715(db) WITH lv_jobname.
LEAVE TO SCREEN 0.
ENDIF.
ELSE.
DATA(msg) = cl_abap_submit_handling=>get_error_message( ).
MESSAGE ID msg-msgid
TYPE 'I'
NUMBER msg-msgno
WITH msg-msgv1 msg-msgv2 msg-msgv3 msg-msgv4
DISPLAY LIKE msg-msgty.
ENDIF.
ENDIF.
注意:
- 函数JOB_OPEN,需要传入Job名字(JOBNAME),函数返回Job编号(JOBCOUNT)
- 调用(SUBMIT)程序时,通过(VIA JOB)和(NUMBER)关键字,告诉系统在哪个Job下执行此程序
- 关闭Job时,函数JOB_CLOSE需传入Job名字(JOBNAME)和Job编号(JOBCOUNT),告诉系统关闭哪个Job
布置Job的起始时间: 正常,我们前台SM36布置Job时,是可以控制Job开始时间的。
程序里是通过(JOB_CLOSE)的参数来实现的:
- 参数STRTIMMED = 'X',表示立即执行此Job,默认为空
- 参数SDLSTRTDT和SDLSTRTTM,可以传入Job执行的日期和时间