DATA: lv_job_name LIKE tbtco-jobname, "作业名 lv_job_nr LIKE tbtco-jobcount, "作业号 lv_job_released TYPE c, lv_job_start_sofort TYPE c, lv_print_parameters TYPE pri_params. 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 = p_monat. APPEND lw_line TO lt_rspar. "传值给 SELECT-OPTION lw_line-selname = ‘S_WERKS‘. lw_line-kind = ‘S‘. lw_line-sign = ‘I‘. lw_line-option = ‘EQ‘. lw_line-low = ‘1000‘. APPEND lw_line TO lt_rspar. APPEND lw_line TO lt_rspar. "JOB 名称 lv_job_name = job_name . "打开JOB 通过JOB name 获得JOB号 CALL FUNCTION ‘JOB_OPEN‘ EXPORTING jobname = lv_job_name 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_job_name) WITH SELECTION-TABLE lt_rspar USER syst-uname " mandatory VIA JOB lv_job_name NUMBER lv_job_nr AND RETURN. "运行结束 关闭JOB IF sy-subrc = 0. CALL FUNCTION ‘JOB_CLOSE‘ EXPORTING jobcount = lv_job_nr jobname = lv_job_name strtimmed = ‘X‘ 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 ‘I‘. ELSE. MESSAGE ‘后台JOB开始运行‘ TYPE ‘I‘. ENDIF. ENDIF. ENDIF. 附: JOB相关系统表:TBTC* JOB的状态: 可以使用系统函数查看 BDL_READ_JOB_STATUS 或者是自己去表 TBTCO 中查找根据STATUS 字段判断是否完成 F 就是结束 A 出错终止 R 是运行中 JOB运行时间:TBTCO中有开始日期,开始时间和结束日期结束时间 两者直接相减就得出JOB运行的时间 JOB日志查看:系统中的日志好像是没有存放在系统表而是文件中,可以通过函数 BP_JOBLOG_READ 获取,传入JOB名和JOB编号就可以获得日志信息。 "获取失败日志 DATA:lt_log TYPE TABLE OF tbtc5 WITH HEADER LINE. CALL FUNCTION ‘BP_JOBLOG_READ‘ EXPORTING client = sy-mandt jobcount = lw_job-jobcount jobname = lw_job-jobname TABLES joblogtbl = lt_log EXCEPTIONS cant_read_joblog = 1 jobcount_missing = 2 joblog_does_not_exist = 3 joblog_is_empty = 4 joblog_name_missing = 5 jobname_missing = 6 job_does_not_exist = 7 OTHERS = 8. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
原文:https://www.cnblogs.com/wangxiaowen/p/8992335.html