*&---------------------------------------------------------------------*
*& Report ZFIX_LIST_JOB
*&---------------------------------------------------------------------*
*&更多信息请参考 函数组 BTCH
*&根据刚才每半个小时设定一个执行JOB
*&---------------------------------------------------------------------*
REPORT zfix_list_job.
TABLES t001w.
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS p_pgmna TYPE reposrc-progname DEFAULT 'ZTEST'.
SELECT-OPTIONS s_werks FOR t001w-werks NO INTERVALS .
SELECTION-SCREEN END OF BLOCK b1.
DATA: lt_valutab TYPE STANDARD TABLE OF rsparams,
lv_jobname TYPE tbtcjob-jobname,
lv_jobcount TYPE tbtcjob-jobcount,
lv_info TYPE i,
lv_ret TYPE i,
lv_jobstatus TYPE tbtco-status,
ls_tbtcv TYPE tbtcv,
lv_count TYPE i.
DATA: lt_rspar TYPE TABLE OF rsparams,
lw_line LIKE LINE OF lt_rspar.
DATA lv_uname TYPE sy-uname.
DATA lv_uz TYPE string.
DATA lv_uz2 TYPE string.
DATA lv_datum TYPE sy-datum.
DATA lv_uzeit TYPE sy-uzeit.
DATA lv_datum2 TYPE sy-datum.
DATA lv_uzeit2 TYPE sy-uzeit.
SELECT * INTO TABLE @DATA(lt_t001w) FROM t001w WHERE werks IN @s_werks.
DELETE lt_t001w WHERE werks = '0001'.
DELETE lt_t001w WHERE werks = '0003'.
CLEAR lv_uname.
SELECT SINGLE * INTO @DATA(lw_t000) FROM t000 WHERE mandt = @sy-mandt.
IF lw_t000-cccategory = 'P'.
lv_uname = 'BGDJOBS'.
ELSE.
lv_uname = sy-uname.
ENDIF.
lv_count = 1.
LOOP AT lt_t001w INTO DATA(lw_t001w).
FREE lt_rspar.
lw_line-selname = 'S_WERKS'.
lw_line-kind = 'S'.
lw_line-sign = 'I'.
lw_line-option = 'EQ'.
lw_line-low = lw_t001w-werks.
* lw_line-high = S_WERKS-high.
APPEND lw_line TO lt_rspar.
IF lv_count = 1.
GET TIME.
lv_datum = sy-datum.
lv_uzeit = sy-uzeit.
lv_datum2 = sy-datum.
lv_uzeit2 = sy-uzeit.
ENDIF.
CLEAR:lv_uz,lv_uz2.
lv_uz = lv_uzeit+0(2).
lv_uz2 = lv_uzeit+2(4).
CONDENSE lv_uz.
CONDENSE lv_uz2.
CLEAR:lv_datum2,lv_uzeit2.
IF lv_uz >= 23.
"日期加1
lv_datum2 = lv_datum + 1.
lv_uzeit2 = '000000'.
ELSE.
"时间+1
lv_datum2 = lv_datum.
lv_uzeit2 = lv_uzeit + 1800.
ENDIF.
CLEAR lv_jobname.
CONCATENATE 'ZOT_' 'LIST' lw_t001w-werks '_' lv_datum2 '_' lv_uzeit2 INTO lv_jobname.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
* DELANFREP = ' '
* JOBGROUP = ' '
jobname = lv_jobname
* SDLSTRTDT = NO_DATE
* SDLSTRTTM = NO_TIME
* JOBCLASS =
* CHECK_JOBCLASS =
IMPORTING
jobcount = lv_jobcount
info = lv_info
CHANGING
ret = lv_ret
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*执行后台作业
"调用需要跑JOB的程序
SUBMIT zfix_list
WITH SELECTION-TABLE lt_rspar
USER lv_uname
VIA JOB lv_jobname NUMBER lv_jobcount AND RETURN.
* CALL FUNCTION 'JOB_SUBMIT'
* EXPORTING
* authcknam = lv_uname
* jobcount = lv_jobcount
* jobname = lv_jobname
* report = p_pgmna
** VARIANT =
* .
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
* laststrtdt = lv_datum2
* laststrttm = lv_uzeit2
sdlstrtdt = lv_datum2
sdlstrttm = lv_uzeit2
* 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
invalid_target = 8
invalid_time_zone = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'.
CONTINUE.
ENDIF.
ENDIF.
lv_count = lv_count + 1.
lv_datum = lv_datum2.
lv_uzeit = lv_uzeit2.
ENDLOOP.
MESSAGE '执行完毕,请TOCDE:SM37检查' TYPE 'S'.
SAP ABAP 使用程序设定定时后台执行JOB
最新推荐文章于 2024-06-14 09:53:56 发布