Entering content frame

Procedure documentation Displaying Job Status: SHOW_JOBSTATE Locate the document in its SAP Library structure

You can find out the status of a job with the SHOW_JOBSTATE function module. You provide this function module with a job name and job number. It returns one of the six possible statuses of the job.

The following example searches for jobs that contain a particular report or external program, using BP_FIND_JOBS_WITH_PROGRAM. It then uses SHOW_JOBSTATE to check the status of each of the jobs that were found. Using an IF keyword, the program evaluates the statuses returned by the function module and lists them, using icons to represent the statuses.

REPORT EXAMPLE.
INCLUDE LBTCHDEF. " Background processing definitions.
INCLUDE <LIST>. " List icons, lines, and other definitions.

* Data declaration: BP_FIND_JOBS_WITH_PROGRAM
DATA SEL_JOBLIST LIKE TBTCJOB OCCURS 100 WITH HEADER LINE.
" Internal table for jobs found.

* Data declaration: SHOW_JOBSTATE
DATA: " Possible job statuses.
ABORTED TYPE C,
FINISHED TYPE C,
PRELIMINARY TYPE C,
READY TYPE C,
RUNNING TYPE C,
SCHEDULED TYPE C.

* Find jobs that contain the ABAP program RSCRIDX4. The
* program and variant name must be in capital letters. It’s
* also possible to search for jobs that run an external program.
CALL FUNCTION 'BP_FIND_JOBS_WITH_PROGRAM'
EXPORTING
ABAP_PROGRAM_NAME = 'RSCRIDX4'
ABAP_VARIANT_NAME = 'V_ALL'
EXTERNAL_PROGRAM_NAME = ' '

" In non-interactive mode, you can search with
" a program name, a variant name, or both.
" Omitting all these specifications results in
" PROGRAM_SPECIFICATION_MISSING.
DIALOG = BTC_NO
" BTC_NO: non-interactive mode. You must
" specify at least a program name in the call.
" BTC_YES: your user enters the program name
" and variant.
TABLES
JOBLIST = SEL_JOBLIST
" Internal table of format TBTCJOB containing
" any jobs found.
EXCEPTIONS
NO_JOBS_FOUND = 1
PROGRAM_SPECIFICATION_MISSING = 2
INVALID_DIALOG_TYPE = 3
JOB_FIND_CANCELED = 4
OTHERS = 5.

IF SY-SUBRC <> 0.
<Error handling>
ENDIF.

* Write list heading lines.
WRITE: / 'Status', 9 'Job Name', 25 'Job Number'.
ULINE AT /1(85).

* Loop through jobs found by BP_FIND_JOBS_WITH_PROGRAM.
LOOP AT SEL_JOBLIST.

CALL FUNCTION 'SHOW_JOBSTATE'
EXPORTING
JOBCOUNT = SEL_JOBLIST-JOBCOUNT
JOBNAME = SEL_JOBLIST-JOBNAME
" Identify the job to be checked. Both
" name and count are required.
IMPORTING
" Possible statuses. The status of the
" job is set to the value ‘X’.
ABORTED = ABORTED
" Job terminated abnormally.
FINISHED = FINISHED
" Job completed successfully.
PRELIMINARY = PRELIMINARY
" Job can’t be started: Job scheduled
" but not yet released to run or job scheduled
" with no start condition.
READY = READY
" Job scheduled, released, start condition
" fulfilled, but job not yet started.
RUNNING = RUNNING
" Job in progress.
SCHEDULED = SCHEDULED
" Job scheduled and released, waiting for start
" condition to be fulfilled.
EXCEPTIONS
JOBCOUNT_MISSING = 1
JOBNAME_MISSING = 2
JOB_NOTEX = 3
OTHERS = 4.


IF SY-SUBRC <> 0.
<Error handling>
ENDIF.

* Determine the status of the job just checked by
* SHOW_JOBSTATE. Assign appropriate status icon and
* write to a list.
IF ABORTED = 'X'.
WRITE: /3 ICON_FAILURE AS ICON,
AT 9 SEL_JOBLIST-JOBNAME,
AT 25 SEL_JOBLIST-JOBCOUNT.
ELSEIF FINISHED = 'X'.
WRITE: /3 ICON_CHECKED AS ICON,
AT 9 SEL_JOBLIST-JOBNAME,
AT 25 SEL_JOBLIST-JOBCOUNT.
ELSEIF PRELIMINARY = 'X'.
WRITE: /3 ICON_INCOMPLETE AS ICON,
AT 9 SEL_JOBLIST-JOBNAME,
AT 25 SEL_JOBLIST-JOBCOUNT.
ELSEIF READY = 'X'.
WRITE: /3 ICON_INCOMPLETE AS ICON,
AT 9 SEL_JOBLIST-JOBNAME,
AT 25 SEL_JOBLIST-JOBCOUNT.
ELSEIF RUNNING = 'X'.
WRITE: /3 ICON_INCOMPLETE AS ICON,
AT 9 SEL_JOBLIST-JOBNAME,
AT 25 SEL_JOBLIST-JOBCOUNT.
ELSEIF SCHEDULED = 'X'.
WRITE: /3 ICON_INCOMPLETE AS ICON,
AT 9 SEL_JOBLIST-JOBNAME,
AT 25 SEL_JOBLIST-JOBCOUNT.
ENDIF.
ENDLOOP.

Leaving content frame