ABAP-后台作业-自开发调用程序

后台作业执行程序;

*&---------------------------------------------------------------------*
*& 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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值