Preparing your main routine to receive parameters

When coding a main routine to receive a parameter list from the operating system, consider the following items:
  • The HLL in which your main routine is written

    HLL semantics determine how you code your main routine in order to receive a parameter list.

  • The method of main routine invocation

    You should consider the environment (MVS™, TSO, IMS™, CICS®) in which your main routine is invoked, as well as the commands used to invoke it.

  • The compiler or runtime options that you must specify
    The settings of the C PLIST runtime option, the C++ PLIST compiler option, or the PL/I SYSTEM compiler option that you must specify are based on:
    • The operating system or subsystem where you invoke your main routine
    • The commands you use to invoke your main routine
The following tables summarize options to consider when preparing a main routine to receive parameters in each system or subsystem; the tables also provide sample coding for each HLL:
TSO/E
Table 1
IMS
Table 2
CICS
Table 3
MVS
Table 4
Table 1. Coding a main routine to receive an inbound parameter list in TSO/E
Language Recommended options setting Sample main routine code
C or C++ (See note 1.) In C, specify PLIST(HOST) runtime option; if not specified, PLIST(HOST) is on by default. Under C++, this is the default behavior; do not specify a PLIST compiler option setting.
main(int argc, char * argv[])
{
⋮
     }
C or C++ (See note 2.) In C, PLIST(HOST) is the default; PLIST(TSO) is supported for compatibility and acts the same as PLIST(HOST). argc and argv are set from the command buffer. In C++, this is the behavior by default.

To see the TSO CPPL, specify PLIST(OS) and access the CPPL through __osplist. In C++, you must specify the PLIST(OS) compiler option.

For PLIST(HOST) behavior, see above.
The following code is a sample that accesses the TSO CPPL:
#include <stdlib.h>
typedef struct CPPL_STRUCT {
   void * CPPLCBUF;
   void * CPPLUPT;
   void * CPPLPSCB;
   void * CPPLECT;
} CPPL;
main()
{
   CPPL *cppl_ptr;

   cppl_ptr = __osplist;
⋮
}
COBOL (See note 1.) No specific options required.
IDENTIFICATION DIVISION.
⋮
DATA DIVISION.
⋮
LINKAGE SECTION.
 01 PARMDATA.
  02 STRINGLEN   PIC 9(4) USAGE IS BINARY. 
  02 STR.
   03 PARM-BYTE  PIC X OCCURS 0 TO 100  
                 DEPENDING ON STRINGLEN.
⋮
PROCEDURE DIVISION USING PARMDATA.
⋮
COBOL (See note 2.) No specific options required. Same as above.
PL/I (See note 1.) Specify SYSTEM(MVS) compiler option.
*PROCESS SYSTEM(xxx);
 MYMAIN: PROC (A) OPTIONS (MAIN);

         DCL  A CHAR(100) VARYING;  
⋮
PL/I (See note 2.) Specify SYSTEM(TSO) compiler option.
*PROCESS SYSTEM(TSO);
 MYMAIN: PROC (CPPLPTR) OPTIONS (MAIN);

         /*Pointer to CPPL*/
         DCL  CPPLPTR POINTER;

         DCL  1 CPPL based (CPPLPTR),
           /*Command buffer*/
              2 CPPLCBUF POINTER,
           /*User profile table*/
              2 CPPLUPT  POINTER,
           /*Protected step ctl blk*/
              2 CPPLPSCB POINTER,
           /*Environment ctl blk*/
              2 CPPLECT  POINTER;
⋮
Method of invocation:
  1. Use the LOADGO command or the CALL command.
  2. Use the TSO Command Processor.

Table 2. Coding a main routine to receive an inbound parameter list in IMS
Language Recommended options setting Sample main routine code
C Specify PLIST(OS) and ENV(IMS) runtime option.
#pragma runopts(env(ims),plist(os))
#include <ims.h>
typedef struct {PCB_STRUCT(10)} PCB_10_TYPE;
main()
{
   PCB_STRUCT_8_TYPE *alt_pcb;
   PCB_10_TYPE *db_pcb;
   IO_PCB_TYPE *io_pcb;
⋮
}
C++ Specify PLIST(OS) and TARGET(IMS) compiler option.
#include <ims.h>
typedef struct {PCB_STRUCT(10)} PCB_10_TYPE;
main()
{
   PCB_STRUCT_8_TYPE *alt_pcb;
   PCB_10_TYPE *db_pcb;
   IO_PCB_TYPE *io_pcb;
⋮
}
COBOL No specific options required.
IDENTIFICATION DIVISION.
PROGRAM-ID. DLITCBL.
DATA DIVISION.
⋮
   LINKAGE SECTION.
   01 PCB1.
      02 … .
   01 PCB2.
      02 … .
⋮
PROCEDURE DIVISION USING PCB1, PCB2.
⋮
PL/I Specify SYSTEM(IMS) compiler option.
*PROCESS SYSTEM(IMS);
 MYMAIN: PROC (X,Y,Z) OPTIONS(MAIN);

         DCL (X,Y,Z) POINTER;
         DCL 1 PCB based (X),
⋮

Table 3. Coding a main routine to receive an inbound parameter list in CICS
Language Recommended options setting Sample main routine code
C or C++ Do not specify any PLIST option. argc = 1 and argv[0] = transaction id.
main(int argc,char *argv[])
{
⋮
}
COBOL No specific options required.
IDENTIFICATION DIVISION.
⋮
DATA DIVISION.
⋮
   LINKAGE SECTION.
   01  DFHEIBLK.
⋮
   01  DFHCOMMAREA.
⋮
PROCEDURE DIVISION USING DFHEIBLK
                         DFHCOMMAREA.
⋮
PL/I Specify SYSTEM(CICS) compiler option.
*PROCESS SYSTEM(CICS);
 MYMAIN: PROC (DFHEIPTR, DFHCOMMAREAPTR_PTR)
         OPTIONS(MAIN);

         /*pointer to EIB*/
         /*supplied by CICS translator*/
         DCL DFHEIPTR POINTER;
         /*pointer to commarea*/
         DCL DFHCOMMAREAPTR_PTR POINTER;
⋮
Table 4. Coding a main routine to receive an inbound parameter list in MVS. Method of invocation: Assembler passing an arbitrary parameter list that Language Environment is not to interpret.
Language Recommended options setting Sample main routine code
C or C++ In C, specify PLIST(OS) runtime option.

In C++, specify PLIST(OS) compiler option.

main()
{ access register 1 through __osplist;
⋮
     }
COBOL No specific options required.
IDENTIFICATION DIVISION.
⋮
DATA DIVISION.
⋮
   LINKAGE SECTION.
   01 PARM1…
   01 PARM2…
⋮
PROCEDURE DIVISION USING PARM1, PARM2.
⋮
PL/I Specify SYSTEM(MVS) and NOEXECOPS procedure option.
*PROCESS SYSTEM(MVS);
 MYMAIN: PROC (PARM1,PARM2,…)
         OPTIONS (MAIN NOEXECOPS);

         DCL PARM1…

         DCL PARM2…
⋮