Q: How can I determine whether my program is being run in an interactive or batch job? How can I tell if my job is a pre-start job?
A: In a CL program, you can check if the job is running interactively or in batch by retrieving the job type with the RTVJOBA command. For example:
PGM
DCL VAR(&JT) TYPE(*CHAR) LEN(1)
RTVJOBA TYPE(&JT)
IF (&JT *EQ '0') THEN(DO)
/* RUNNING IN BATCH */
ENDDO
ELSE DO
/* RUNNING INTERACTIVELY */
ENDDO
ENDPGM
If you'd like to find out the job type in ILE RPG or you'd like to get more information about the job type, you can do so with the QUSRJOBI API. I've written a routine that retrieves the job type and converts it to a three-character abbreviation like the one shown in the WRKACTJOB command.
The following source illustrates how to check to see if the job is Interactive or Batch and whether it's a pre-start job:
H OPTION(*SRCSTMT: *NOSHOWCPY)
H DFTACTGRP(*NO)
D RtvJobType PR 3A
D jt s 3A
/free
jt = RtvJobType();
if (jt = 'INT');
// interactive job
elseif (jt = 'PJ ');
// prestart job
else;
// some other sort of batch job...
endif;
*inlr = *on;
/end-free
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* RtvJobType(): Retrieve Job Type of the current job as
displayed
* in the "Type" column of WRKACTJOB.
*
* Returns the 3-character job type
* or 'ERR' if an error occurs (see job log for error
message)
* or '***' if the job type was unrecognized
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P RtvJobType B export
D RtvJobType PI 3A
D* Retrieve Job Information API:
D QUSRJOBI PR ExtPgm('QUSRJOBI')
D RcvVar 32766A Options(*varsize)
D RcvVarLen 10I 0 const
D Format 8A const
D QualJob 26A const
D IntJobID 16A const
D ErrorCode 32766A options(*varsize)
*
* Fields in the JOBI0100 format of the QUSRJOBI API
*
D dsJob ds qualified
D BytesRtn 10I 0
D BytesAvl 10I 0
D Name 10A
D User 10A
D JobNbr 6A
D IntID 16A
D Status 10A
D Type 1A
D SubType 1A
D Reserved 2A
D RunPty 10I 0
D TimeSlice 10I 0
D DftWait 10I 0
D Purge 10A
**
** Error code structure to utilize the operating
** system's normal error handling scheme
**
D dsEC DS
D dsEC1 10I 0 inz(0)
D dsEC2 10I 0 inz(0)
/free
monitor;
QUSRJOBI(dsJob: %size(dsJob): 'JOBI0100': '*': ' ': dsEC);
on-error;
return 'ERR';
endmon;
select;
when dsJob.Type='A';
return 'ASJ';
when dsJob.Type='B' and dsJob.Subtype=' ';
return 'BCH';
when dsJob.Type='B' and dsJob.Subtype='D';
return 'BCI';
when dsJob.Type='B' and dsJob.Subtype='E';
return 'EVK';
when dsJob.Type='B' and dsJob.Subtype='F';
return 'M36';
when dsJob.Type='B' and dsJob.Subtype='T';
return 'MRT';
when dsJob.Type='B' and dsJob.Subtype='J';
return 'PJ ';
when dsJob.Type='I';
return 'INT';
when dsJob.Type='W' and dsJob.Subtype='P';
return 'PDJ';
when dsJob.Type='R';
return 'RDR';
when dsJob.Type='S' or dsJob.Type='X';
return 'SYS';
when dsJob.Type='M';
return 'SBS';
when dsJob.Type='W';
return 'WTR';
when dsJob.Type='B' and dsJob.SubType='U';
return *blanks;
other;
return '***';
endsl;
/end-free
P E