后台跑程序(仿SM36)
REPORT SM36.
DATA: global_job LIKE tbtcjob.
DATA: global_start_date LIKE tbtcstrt.
DATA: global_step_tbl LIKE tbtcstep OCCURS 0 WITH HEADER LINE.
DATA:tim LIKE sy-uzeit.
DATA:rep LIKE sy-repid, "执行后台作业程序
var LIKE raldb-variant. "执行变式
GET TIME.
tim = sy-uzeit + 20. "系统当期时间后2分钟
global_job-jobname = 'ZP01'. "作业名
global_job-sdlstrtdt = sy-datum. "作业开始日期
global_job-sdlstrttm = tim. "作业开始时间
global_job-jobclass = 'A'.
global_job-newflag = 'O'.
global_job-sdluname = sy-uname.
global_step_tbl-program = 'ZPP301'. "ABAP程序名
global_step_tbl-parameter ='TEST'. "变式
global_step_tbl-typ = 'A'.
global_step_tbl-status = 'P'.
global_step_tbl-authcknam = sy-uname.
APPEND global_step_tbl.
global_start_date-sdlstrtdt = sy-datum.
global_start_date-sdlstrttm = tim.
rep = 'ZP01'.
var = 'TEST'.
*定义后台作业
CALL FUNCTION 'BP_JOB_CREATE'
EXPORTING
job_cr_dialog = 'N'
job_cr_head_inp = global_job
IMPORTING
job_cr_head_out = global_job
job_cr_stdt_out = global_start_date
TABLES
job_cr_steplist = global_step_tbl
EXCEPTIONS
cant_create_job = 1
invalid_dialog_type = 2
invalid_job_data = 3
job_create_canceled = 4
OTHERS = 5.
*执行后台作业
*CALL FUNCTION 'JOB_SUBMIT'
* EXPORTING
* authcknam = sy-uname
* jobcount = global_job-jobcount
* jobname = global_job-jobname
* report = REP
* variant = 'TEST'
* EXCEPTIONS
* bad_priparams = 1
* bad_xpgflags = 2
* invalid_jobdata = 3
* jobname_missing = 4
* job_notex = 5
* job_submit_failed = 6
* lock_failed = 7
* program_missing = 8
* prog_abap_and_extpg_set = 9
* OTHERS = 10.
*