IBM i jobs comes in two flavours – INTERACTIVE which means that a user keying into a terminal and using the program interacting with the program code, or BATCH which means this program has been submitted and is expected to execute without any human interaction.
The module below, INTERACT, determines whether your program is running in interactive or batch mode:
h NoMain
// This *SRVPGM will determine if this IBM iSeries job is interactive or batch
// and return a status of *ON if its interactive and *OFF if its batch
p pInteractive B Export
d pInteractive PI N
d Format s 8
d RcvVarLen s 10i 0
d dsJobDta ds
d dsJobBytesRtn 10I 0
d dsJobBytesAvl 10I 0
d dsJobName 10A
d dsJobUser 10A
d dsJobNumber 6A
d dsJobIntern 16A
d dsJobStatus 10A
d dsJobType 1A
d dsJobSubtype 1A
d dsJobReserv1 2A
d dsJobRunPty 10I 0
d dsJobTimeSlc 10I 0
d dsJobDftWait 10I 0
d dsJobPurge 10A
// QUSRJOBI is an IBM *API which returns job information
d qUSRJOBI pr extpgm('QUSRJOBI')
d DsJob like(DsJobDta)
d Length 10i 0 const
d APIFormat 8 const
d ApiJob 26 const
d InternJob 16 const
RcvVarLen = %Size(DsJobDta);
Format = 'JOBI0100';
qUSRJOBI ( dsjobdta : rcvvarlen : Format : '*' : ' ');
if DSJOBTYPE = 'I';
Return *On;
Else;
Return *Off;
EndIf;
P pInteractive E
Use option 15 in PDM to compile INTERACT.
Issue the command:
CrtSrvPgm SrvPgm( INTERACT ) Export( *All ) ActGrp( NICKLITTEN)
To use this service program from an RPG IV program, follow these steps:
a) Include the following prototype in your source with the D-specs:
D pInteractive PR
If you expect to use this procedure in more than one program, you might consider using a /Copy member for this prototype.
b) Here are a couple of sample calls to INTERACT in the C-specs:
If pInteractive();
// this is an interactive job
EndIf
If Not pInteractive();
// this is a batch job
Endif;
c) Use PDM option 15 to compile your program. d) Issue the following command to create your program (Note that the following assumes your program is a standalone program, i.e., a single module, named MYPGM):
CrtPgm MyPgm Module(MYPGM) BndSrvPgm(INTERACT) ActGrp(NICKLITTEN)