ABAP 在程序中啟動後臺JOB
阿新 • • 發佈:2018-05-04
number mes AS exist abap count str imm mis
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.
ABAP 在程序中啟動後臺JOB