后台作业执行程序;
*&---------------------------------------------------------------------*
*& Report Y_CLY_101
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT y_cly_101.
DATA:
lv_job_name LIKE tbtco-jobname VALUE 'YCLY_B01', "
lv_job_name_a LIKE tbtco-jobname VALUE '', "
lv_prj_name TYPE sy-repid VALUE 'Y_CLY_102',
lv_job_nr LIKE tbtco-jobcount VALUE '', "
lv_job_released TYPE c.
DATA:lt_rspar TYPE TABLE OF rsparams,
lw_line LIKE LINE OF lt_rspar.
" 如果是要传给PARAMETER 根据需求设置屏幕参数
lw_line-selname = 'P_MONAT'.
lw_line-kind = 'P'.
lw_line-sign = 'I'.
lw_line-option = 'EQ'.
lw_line-low = sy-uname && sy-datum.
APPEND lw_line TO lt_rspar.
lv_job_name_a = lv_job_name && '_'
&& sy-uname && '_'
&& sy-datum && '_'
&& sy-uzeit.
" 打开JOB 通过JOB name 获得JOB号
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_job_name_a
IMPORTING
jobcount = lv_job_nr
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF syst-subrc = 0.
" 调用需要跑JOB的程序
SUBMIT (lv_prj_name) WITH SELECTION-TABLE lt_rspar
USER syst-uname VIA JOB lv_job_name_a NUMBER lv_job_nr AND RETURN.
" 运行结束 关闭JOB
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_job_nr
jobname = lv_job_name_a
sdlstrtdt = '20190821' " 计划开始日期
sdlstrttm = '091501' " 计划结束时间
strtimmed = abap_true
prdmins = 5 " NUMC 2 以分钟计算
" PRDHOURS = 1 = 1 " NUMC 2 以小时计算
" PRDDAYS = 1 " NUMC 3 以天计算
" PRDWEEKS = 1 " NUMC 2 以星期计算
" PRDMONTHS = 1 " NUMC 2 以月计算
" PERIODIC = 1 " 周期性作业标识 CHAR 1
IMPORTING
job_was_released = lv_job_released
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 syst-subrc <> 0.
MESSAGE '关闭后台作业出错' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
MESSAGE '后台JOB开始运行' TYPE 'S'.
ENDIF.
ENDIF.
ENDIF.
后台作业被调用程序;
*&---------------------------------------------------------------------*
*& Report Y_CLY_102
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Y_CLY_102.
TABLES: YCLY_TEST_01.
PARAMETERS: P_USER TYPE USR02-BNAME DEFAULT sy-uname.
START-OF-SELECTION.
YCLY_TEST_01-CDATE = SY-DATUM.
YCLY_TEST_01-CTIME = SY-UZEIT.
YCLY_TEST_01-CNAME = P_USER.
INSERT YCLY_TEST_01.
IF SY-SUBRC = 0.
COMMIT WORK AND WAIT.
ENDIF.