MainframeSupports
tip week 5/2008:

Currently the IT industry talks a lot about reuse. One of the classic challenges in the mainframe environment is that many sub modules are produced in two flavours: one for batch and one for online. This is typically done because the sub module has to call different APIs dependent on whether the sub module is executed online or batch.

In order to use the same sub module to call different APIs in batch and online it has to be able to determine whether it is executing batch or online. The definition of online depends on the type of transaction processor used in different installations. Batch is almost certainly a job being executed by JES. This tip show you how to find out whether your program is being executed by JES or not. In the following two examples BATCH is equal to JES execution and online everything else. The first example is how to do it in COBOL:

* IN WORKING-STORAGE SECTION
 01  AREA-ADDRESS PIC S9(9) BINARY.
 01  FILLER REDEFINES AREA-ADDRESS.
   02  AREA-POINTER POINTER.
* IN LINKAGE SECTION
 01  PSA.
   02  FILLER PIC X(548).
   02  ASCB-POINTER POINTER.
 01  ASCB.
   02  FILLER PIC X(172).
   02  JBNI PIC S9(9) BINARY.
* SOMEWHERE IN PROCEDURE DIVISION
     MOVE 0 TO AREA-ADDRESS
     SET ADDRESS OF PSA TO AREA-POINTER
     SET ADDRESS OF ASCB TO ASCB-POINTER
     IF JBNI = 0
       DISPLAY 'ONLINE'
     ELSE
       DISPLAY 'BATCH'
     END-IF

And here is a procedure in PL/I which does the same thing:

batch_or_online: PROC;
DCL psa_address FIXED BIN(31) INIT(0);
DCL psa_pointer POINTER BASED(ADDR(psa_address));
DCL 1 psa BASED(psa_pointer)
  , 2 filler CHAR(548)
  , 2 ascb_pointer POINTER
  ;
DCL 1 ascb BASED(ascb_pointer)
  , 2 filler CHAR(172)
  , 2 jbni FIXED BIN(31)
  ;
IF jbni = 0
  PUT SKIP LIST('ONLINE');
ELSE
  PUT SKIP LIST('BATCH');
END batch_or_online;

And now something about the pitfalls. It is possible, but rarely used to execute CICS as a batch job. This will make the tip work very badly. Also it is not possible to distinguish between a started task and a TSO online session. Therefore the tip cannot be used to differentiate between CICS, IMS or TSO or something else running as a started task.

Previous tip in english        Sidste danske tip        Tip list