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

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

p Interactive PR N

D DummyPrm 1 Options( *Omit )

P pInteractive B Export
D pInteractive PI N
D DummyPrm 1 Options( *Omit )

 * Local variables
D RetdInfDs DS
D 4
D 10I 0 Inz( %Size( RetdInfDs ) )
D RiJobType 61 61
D RiTypeInteractive...
D C 'I'
D LenRetdInf S 10I 0 Inz( %Size( RetdInfDs ) )
D FmtName S 8 Inz( 'JOBI0100' )
D QlJobName S 26 Inz( '*' )
D IntJobId S 16 Inz( *Blank )

  Parm RetdInfDs
  Parm LenRetdInf
  Parm FmtName
  Parm QlJobName
  Parm IntJobId

 If RiJobType = RiTypeInteractive
   Return *On
   Return *Off

P pInteractive E

Use option 15 in PDM to compile INTERACT.

Issue the command: CrtSrvPgm SrvPgm( INTERACT ) Export( *All ) ActGrp( WhateverYouWant )

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 N D DummyPrm 1 Options( *Omit ) 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: C If pInteractive( *Omit ) C ‘Interactive’ DsplyDummyVar C EndIf C If Not pInteractive( *Omit ) C ‘Batch’ Dsply C 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( Whatever )

Adapted from a utility by Mike Cravitz


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"}

Start your
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 ]

IBM i Training For Technology Experts


Successfully Work Remote 

 $ 129.00  $59.00

By adding new skills in information technology, employers will be confident that you have the necessary skills and tools needed to successfully work remotely


Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"