Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Example: command-line arguments

This example shows how to read the command-line arguments.

 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 you compile and run the program as follows:

cob2 testarg.cbl

testarg 95

Then the resulting output is:

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

Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)