本文主要是介绍ABAP程序带参调用后台作业,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 主要内容
- 代码示例
- 注意事项
主要内容
带参调用后台作业
代码示例
DATA:lv_job_name TYPE btcjob,lv_joblike TYPE btcjob,lv_name TYPE progname,lv_subrc TYPE i,lr_agr_rspar TYPE TABLE OF rsparams,ls_agr_line LIKE LINE OF lr_agr_rspar,w_jobid TYPE tbtcjob-jobcount,w_stepnm TYPE tbtcjob-stepcount.* 查表 如果已存在执行中的后台 则报错退出lv_joblike = 'ZBJOB_TEST'.SELECT SINGLE jobnameINTO lv_job_nameFROM tbtcoWHERE jobname EQ lv_joblike
* AND ( status = 'R' "Active
* OR status = 'Z' ). "Released/SuspAND status EQ 'R'.IF sy-subrc NE 0.lv_job_name = 'ZBJOB_TEST'.ELSE.MESSAGE w147(zps) WITH '已存在活动后台作业' RAISING foreign_lockbg.RETURN.ENDIF.* 唤起后台 有则报错退出
*1. using JOB_OPEN to open jobCLEAR:w_jobid.CALL FUNCTION 'JOB_OPEN'EXPORTING
* DELANFREP = ’ ’
* JOBGROUP = ’ ’jobname = lv_job_name
* SDLSTRTDT = NO_DATE
* SDLSTRTTM = NO_TIME
* JOBCLASS =IMPORTINGjobcount = w_jobid
* CHANGING
* RET =EXCEPTIONScant_create_job = 1invalid_job_data = 2jobname_missing = 3OTHERS = 4.IF sy-subrc EQ 0.ls_agr_line-kind = 'S'.ls_agr_line-sign = 'I'.ls_agr_line-option = 'EQ'.IF it_agr_name IS NOT INITIAL.ls_agr_line-selname = 'S_AGR'.* S参数LOOP AT it_agr_name INTO ls_agr_name.* ls_agr-low = ls_agr_name-agr_name.
* APPEND ls_agr TO lr_agr.* lv_agr_name = ls_agr_name-agr_name.ls_agr_line-low = ls_agr_name-agr_name.APPEND ls_agr_line TO lr_agr_rspar.ENDLOOP.ENDIF.IF it_agr_uname IS NOT INITIAL.ls_agr_line-selname = 'S_UNAME'.
* 单值LOOP AT it_agr_uname INTO ls_agr_uname.ls_agr_line-low = ls_agr_uname-uname.APPEND ls_agr_line TO lr_agr_rspar.ENDLOOP.ENDIF.ls_agr_line-selname = 'P_CHK'.ls_agr_line-kind = 'P'. * 单选按钮类型ls_agr_line-sign = 'I'.ls_agr_line-option = 'EQ'.ls_agr_line-low = abap_true.APPEND ls_agr_line TO lr_agr_rspar.*2. using JOB_SUMMIT to insert stepSUBMIT ztest_bjob_01 WITH SELECTION-TABLE lr_agr_rsparVIA JOB lv_job_nameNUMBER w_jobidAND RETURN.CALL FUNCTION 'JOB_CLOSE'EXPORTING
* AT_OPMODE = ’ ’
* AT_OPMODE_PERIODIC = ’ ’
* CALENDAR_ID = ’ ’
* EVENT_ID = ’ ’
* EVENT_PARAM = ’ ’
* EVENT_PERIODIC = ’ ’jobcount = w_jobidjobname = lv_job_name
* LASTSTRTDT = NO_DATE
* LASTSTRTTM = NO_TIME
* PRDDAYS = 0
* PRDHOURS = 0
* PRDMINS = 0
* PRDMONTHS = 0
* PRDWEEKS = 0
* PREDJOB_CHECKSTAT = ’ ’
* PRED_JOBCOUNT = ’ ’
* PRED_JOBNAME = ’ ’
* SDLSTRTDT = NO_DATE
* SDLSTRTTM = NO_TIME
* STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYSstrtimmed = 'X'
* TARGETSYSTEM = ’ ’
* START_ON_WORKDAY_NOT_BEFORE = SY-DATUM
* START_ON_WORKDAY_NR = 0
* WORKDAY_COUNT_DIRECTION = 0
* RECIPIENT_OBJ =
* TARGETSERVER = ’ ’
* DONT_RELEASE = ’ ’
* TARGETGROUP = ’ ’direct_start = 'X'
* IMPORTING
* JOB_WAS_RELEASED =
* CHANGING
* RET =EXCEPTIONScant_start_immediate = 1invalid_startdate = 2jobname_missing = 3job_close_failed = 4job_nosteps = 5job_notex = 6lock_failed = 7invalid_target = 8OTHERS = 9.IF sy-subrc EQ 0.WHILE lv_subrc EQ 0. "当作业成功启动后才退出SELECT SINGLE jobnameINTO lv_job_nameFROM tbtcoWHERE jobname EQ lv_joblikeAND status EQ 'R'.IF sy-subrc EQ 0.lv_subrc = 2.ELSE.WAIT UP TO 1 SECONDS.ENDIF.ENDWHILE.ENDIF.ELSE.MESSAGE e147(zps) WITH '后台作业关闭失败' RAISING bg_job_fail.ENDIF.
注意事项
区分各个参数之间的类型(KIND)
这篇关于ABAP程序带参调用后台作业的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!