============================================================
REPORT SUBMIT_JOB_SAMPLE.
TABLES : BKPF.
DATA: IT_BKPF LIKE STANDARD TABLE OF BKPF WITH HEADER LINE.
SELECT-OPTIONS S_BUKRS FOR BKPF-BUKRS.
SELECT-OPTIONS S_BELNR FOR BKPF-BELNR.
SELECT-OPTIONS S_GJAHR FOR BKPF-GJAHR.
PARAMETERS : P_BATCH AS CHECKBOX.
START-OF-SELECTION.
"當 user 勾選產生 Batch JOB 時拋 Background JOB
IF P_BATCH EQ 'X'.
PERFORM CREATE_BATCH_JOB.
ELSE.
"不產生 Batch JOB 則捉取資料並輸出
SELECT SINGLE * INTO CORRESPONDING FIELDS OF IT_BKPF
FROM BKPF
WHERE BUKRS IN S_BUKRS
AND BELNR IN S_BELNR
AND GJAHR IN S_GJAHR.
IF SY-SUBRC EQ 0.
WRITE: IT_BKPF-BELNR.
ELSE.
WRITE: 'No data found!'.
ENDIF.
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form create_batch_job
*&---------------------------------------------------------------------*
FORM CREATE_BATCH_JOB .
DATA: ARCXPARA LIKE ARC_PARAMS,
PRINPARA LIKE PRI_PARAMS,
JOBXNAME LIKE RSJOBINFO-JOBNAME,
JOBXCONT LIKE RSJOBINFO-JOBNUMB,
VALDCODE.
CHECK SY-BATCH IS INITIAL.
JOBXNAME = 'SUBMIT_JOB_SAMPLE'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = jobxname
IMPORTING
jobcount = jobxcont
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE 'Submit batch job error' TYPE 'E'.
ENDIF.
SUBMIT SUBMIT_JOB_SAMPLE
WITH S_BUKRS IN S_BUKRS[]
WITH S_BELNR IN S_BELNR[]
WITH S_GJAHR IN S_GJAHR[]
WITH P_BATCH = SPACE
VIA JOB JOBXNAME
NUMBER JOBXCONT
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = jobxcont
jobname = jobxname
strtimmed = 'X'
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 sy-subrc NE 0.
MESSAGE 'Submit batch job error' TYPE 'E'.
else.
MESSAGE 'Submit batch job done' TYPE 'I'.
ENDIF.
STOP.
ENDFORM. " create_batch_job
============================================================
Step1 : 執行時勾選 P_BATCH,按下前景執行按鈕
Step2 : 執行後在 SM37 產生 Background JOB
Step3 : 查看 Spool 可以看到執行的結果
沒有留言:
張貼留言