Example: accessing main program parameters under z/OS UNIX

The following example shows the three parameters that are passed by reference, and shows the coding that you can use to access them.


 Identification division.
 Program-id. "EXECED".
****************************************************************
* This sample program displays arguments received via exec()   *
* function of z/OS UNIX                                        *
****************************************************************
 Data division.
 Working-storage section.
 01 curr-arg-count pic 9(9) binary value zero.
 Linkage section.
 01 arg-count pic 9(9) binary.                     (1)
 01 arg-length-list.                               (2)
     05 arg-length-addr pointer occurs 1 to 99999
           depending on curr-arg-count.
 01 arg-list.                                      (3)
     05 arg-addr pointer occurs 1 to 99999
           depending on curr-arg-count.
 01 arg-length pic 9(9) binary.
 01 arg pic X(65536).
 Procedure division using arg-count arg-length-list arg-list.
*****************************************************************
* Display number of arguments received                          *
*****************************************************************
     Display "Number of arguments received: " arg-count
*****************************************************************
* Display each argument passed to this program                  *
*****************************************************************
     Perform arg-count times
       Add 1 to curr-arg-count
* *******************************************************
* * Set address of arg-length to address of current     *
* * argument length and display                         *
* *******************************************************
       Set Address of arg-length
         to arg-length-addr(curr-arg-count)
       Display
         "Length of Arg " curr-arg-count " = " arg-length
* *******************************************************
* * Set address of arg to address of current argument   *
* * and display                                         *
* *******************************************************
       Set Address of arg to arg-addr(curr-arg-count)
       Display "Arg " curr-arg-count " = " arg (1:arg-length - 1)
     End-Perform
     Display "Display of arguments complete."
     Goback.
(1)
This count contains the number of elements in the arrays that are passed in the second and third parameters.
(2)
This array contains a pointer to the length of the nth entry in the argument list.
(3)
This array contains a pointer to the nth character string passed as an argument in the spawn() or exec() function or in the command invocation.