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:
And here is a procedure in PL/I which does the same thing:
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.