ABAP后台作业设置过程:
1.变式校验
2.当前作业是否正在运行(加锁及防重)
3.后台作业提交
1.变式校验:
SELECT SINGLE @abap_true FROM varid WHERE report = @lv_report AND variant = @lv_vart INTO @DATA(lv_exists).
2.是否正在运行:
SELECT SINGLE @abap_true FROM tbtco WHERE jobname = @lv_jobname AND status IN (@/isdfps/cl_const_abc_123=>gc_s, @/isdfps/cl_const_abc_123=>gc_r, @/isdfps/cl_const_abc_123=>gc_y) INTO @DATA(lv_true).
上面只针对jobname名称进行校验,如果对当前执行程序进程进行校验,可参考IT虾米网:
call 'ThWpInfo' id 'OPCODE' field lc_opcode_wp_list id 'TAB' field lt_wpinfo-*sys* id 'CPU' field lv_with_cpu.
3.作业提交:
作业提交过程中需注意并发及防重执行,尽量通过作业变式分开提交,相同作业名避免记录前后执行重复。
CONCATENATE lv_report '_'lv_vart INTO lv_jobname.
CALL FUNCTION 'ZFG0030_CRTJOB' EXPORTING jobname = lv_jobname rept = lv_report jbnamclas = /isdfps/cl_const_abc_123=>gc_b vart = lv_vart lang = '1' stdat = l_stdat sttim = l_sttim dirst = abap_true IMPORTING jbname = l_jobname jbcount = l_jobcount.
FUNCTION ZFG0030_CRTJOB. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(JOBNAME) LIKE TBTCJOB-JOBNAME *" VALUE(JBNAMCLAS) LIKE TBTCJOB-JOBCLASS OPTIONAL *" VALUE(REPT) LIKE SY-REPID *" VALUE(VART) LIKE RALDB-VARIANT OPTIONAL *" VALUE(LANG) LIKE SY-LANGU OPTIONAL *" VALUE(IMED) LIKE BTCH0000-CHAR1 OPTIONAL *" VALUE(EVEID) LIKE TBTCJOB-EVENTID OPTIONAL *" VALUE(EVEPA) LIKE TBTCJOB-EVENTPARM OPTIONAL *" VALUE(EVEPER) LIKE BTCH0000-CHAR1 OPTIONAL *" VALUE(PREST) LIKE TBTCSTRT-CHECKSTAT OPTIONAL *" VALUE(PREJB) LIKE TBTCJOB-JOBCOUNT OPTIONAL *" VALUE(PRJBN) LIKE TBTCJOB-JOBNAME OPTIONAL *" VALUE(STDAT) LIKE SY-DATUM OPTIONAL *" VALUE(STTIM) LIKE SY-UZEIT OPTIONAL *" VALUE(TARSER) LIKE BTCTGTSRVR-SRVNAME OPTIONAL *" VALUE(DIRST) LIKE BTCH0000-CHAR1 OPTIONAL *" EXPORTING *" REFERENCE(JBNAME) LIKE TBTCJOB-JOBNAME *" REFERENCE(JBCOUNT) LIKE TBTCJOB-JOBCOUNT *" REFERENCE(ABORTED) LIKE TBTCV-ABORT *" REFERENCE(FINISHED) LIKE TBTCV-FIN *" REFERENCE(PRELIMINARY) LIKE TBTCV-PRELIM *" REFERENCE(READY) LIKE TBTCV-READY *" REFERENCE(RUNNING) LIKE TBTCV-RUN *" REFERENCE(SCHEDULED) LIKE TBTCV-SCHED *" EXCEPTIONS *" 11CANT_CREATE_JOB *" 12INVALID_JOB_DATA *" 13JOBNAME_MISSING *" GENERAL_FAULT *" 21BAD_PRIPARAMS *" 22IBAD_XPGFLAGS *" 23INVALID_JOBDATA *" 24JOBNAME_MISSING *" 25JOB_NOTEX *" 26JOB_SUBMIT_FAILED *" 27LOCK_FAILED *" 28PROGRAM_MISSING *" 29PROG_ABAP_AND_EXTPG_SET *" 31CANT_START_IMMEDIATE *" 32INVALID_STARTDATE *" 33JOBNAME_MISSING *" 34JOB_CLOSE_FAILED *" 35JOB_NOSTEPS *" 36JOB_NOTEX *" 37LOCK_FAILED *" 38INVALID_TARGET *"---------------------------------------------------------------------- DATA: JOBCOUNT LIKE TBTCJOB-JOBCOUNT. CALL FUNCTION 'JOB_OPEN' EXPORTING * DELANFREP = ' ' * JOBGROUP = ' ' JOBNAME = JOBNAME JOBCLASS = JBNAMCLAS IMPORTING JOBCOUNT = JOBCOUNT EXCEPTIONS CANT_CREATE_JOB = 1 INVALID_JOB_DATA = 2 JOBNAME_MISSING = 3 OTHERS = 4. IF SY-SUBRC <> 0. CASE SY-SUBRC. WHEN 1. MESSAGE 'CANT_CREATE_JOB' TYPE 'E' "#EC NOTEXT RAISING 11CANT_CREATE_JOB. WHEN 2. MESSAGE 'INVALID_JOB_DATA' TYPE 'E' RAISING 12INVALID_JOB_DATA. WHEN 3. MESSAGE 'JOBNAME_MISSING' TYPE 'E' RAISING 13JOBNAME_MISSING. WHEN 4. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 RAISING GENERAL_FAULT. ENDCASE. ELSE. JBNAME = JOBNAME. JBCOUNT = JOBCOUNT. CALL FUNCTION 'JOB_SUBMIT' EXPORTING AUTHCKNAM = SY-UNAME JOBCOUNT = JOBCOUNT JOBNAME = JOBNAME LANGUAGE = SY-LANGU REPORT = REPT VARIANT = VART 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. IF SY-SUBRC <> 0. CASE SY-SUBRC. WHEN 1. MESSAGE 'BAD_PRIPARAMS' TYPE 'E' "#EC NOTEXT RAISING 21BAD_PRIPARAMS. WHEN 2. MESSAGE 'IBAD_XPGFLAGS' TYPE 'E' RAISING 22IBAD_XPGFLAGS. WHEN 3. MESSAGE 'INVALID_JOBDATA' TYPE 'E' RAISING 23INVALID_JOBDATA. WHEN 4. MESSAGE 'JOBNAME_MISSING' TYPE 'E' RAISING 24JOBNAME_MISSING. WHEN 5. MESSAGE 'JOB_NOTEX' TYPE 'E' RAISING 25JOB_NOTEX. WHEN 6. MESSAGE 'JOB_SUBMIT_FAILED' TYPE 'E' RAISING 26JOB_SUBMIT_FAILED. WHEN 7. MESSAGE 'LOCK_FAILED' TYPE 'E' RAISING 27LOCK_FAILED. WHEN 8. MESSAGE 'PROGRAM_MISSING ' TYPE 'E' RAISING 28PROGRAM_MISSING. WHEN 9. MESSAGE 'PROG_ABAP_AND_EXTPG_SET' TYPE 'E' RAISING 29PROG_ABAP_AND_EXTPG_SET. WHEN 10. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 RAISING GENERAL_FAULT. ENDCASE. ELSE. DATA:V_TIM TYPE SY-UZEIT. V_TIM = STTIM + 10. *if PREJB ne space and prjbn ne space. * PERFORM build_predjob_event_name USING * PREJB * prjbn * job_head-eventid * job_head-eventparm * job_head-eventcount * rc. *endif. CALL FUNCTION 'JOB_CLOSE' EXPORTING EVENT_ID = EVEID EVENT_PARAM = EVEPA EVENT_PERIODIC = EVEPER JOBCOUNT = JOBCOUNT JOBNAME = JOBNAME PREDJOB_CHECKSTAT = PREST PRED_JOBCOUNT = PREJB PRED_JOBNAME = PRJBN SDLSTRTDT = STDAT SDLSTRTTM = V_TIM TARGETSERVER = TARSER STRTIMMED = IMED * TARGETGROUP = ' ' DIRECT_START = DIRST 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 OTHERS = 9. IF SY-SUBRC <> 0. CASE SY-SUBRC. WHEN 1. MESSAGE 'cant_start_immediate ' TYPE 'E' "#EC NOTEXT RAISING 31CANT_START_IMMEDIATE . WHEN 2. MESSAGE 'invalid_startdate' TYPE 'E' RAISING 32INVALID_STARTDATE. WHEN 3. MESSAGE 'jobname_missing' TYPE 'E' RAISING 33JOBNAME_MISSING. WHEN 4. MESSAGE 'job_close_failed ' TYPE 'E' RAISING 34JOB_CLOSE_FAILED . WHEN 5. MESSAGE 'job_nosteps' TYPE 'E' RAISING 35JOB_NOSTEPS. WHEN 6. MESSAGE 'job_notex ' TYPE 'E' RAISING 36JOB_NOTEX . WHEN 7. MESSAGE 'LOCK_FAILED' TYPE 'E' RAISING 37LOCK_FAILED. WHEN 8. MESSAGE 'invalid_target ' TYPE 'E' RAISING 38INVALID_TARGET. WHEN OTHERS. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 RAISING GENERAL_FAULT. ENDCASE. ENDIF. ENDIF. ENDIF. ENDFUNCTION.
View Code
4.后台作业调试JDBG :
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/17944.html