December 16

0 comments

RPG4 code example to find if a job is interactive or batch environment

By NickLitten

December 16, 2009

RPG, IBM i

The module below, INTERACT, determines whether your program is running in interactive or batch mode:

     h NoMain

      // determine if this as400 job is interactive or batch
      // return a *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

     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)

Do you want to see this code upgraded to modern RPGLE **FREE?

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>