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

  • Home
  • /
  • Blog
  • /
  • RPG4 code example to find if a job is interactive or batch environment

December 16, 2009

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)

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

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits.

Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day.

Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

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

Subscribe NOW
7-day free trial

Take This Course with ALL ACCESS

Unlock your Learning Potential with instant access to every course and all new courses as they are released.
 [ For Serious Software Developers only ]

Online Learning for IBM i Software Technology Professionals

“The more that you read, the more things you will know. The more that you learn, the more places you’ll go.” – Dr. Seuss

>