Example: accessing main program parameters under z/OS

The following example shows how to receive a parameter string that is passed to a COBOL program that runs under z/OS®, and shows the coding that you can use to access the parameter string.


 IDENTIFICATION DIVISION.
 PROGRAM-ID. "testarg".
*
 ENVIRONMENT DIVISION.
 CONFIGURATION SECTION.
*
 DATA DIVISION.
 WORKING-STORAGE SECTION.
*
 linkage section.
 01  os-parm.
     05 parm-len         pic s999 comp.
     05 parm-string.
         10 parm-char    pic x occurs 0 to 100 times
                         depending on parm-len.
*
 PROCEDURE DIVISION using os-parm.
     display "parm-len=" parm-len
     display "parm-string='" parm-string "'"
     evaluate parm-string
       when "01"  display "case one"
       when "02"  display "case two"
       when "95"  display "case ninety-five"
       when other display "case unknown"
     end-evaluate
     GOBACK.

Suppose that the CBLOPTS(ON) runtime option is in effect, and that you pass the following argument in the JCL or TSO command that you use to run the program:


'95/'

Then the resulting output is:


parm-len=002
parm-string='95'
case ninety-five