Skip to main content

It's often a requirement to use arguments entered on the command line during the execution of a COBOL application; here’s a technique for capturing a varying number of arguments.

Problem:

How to capture a varying number of command-line arguments while executing a COBOL application.

Resolution:

ARGUMENT-NUMBER and ARGUMENT-VALUE are functions that can be defined in the SPECIAL-NAMES paragraph of a COBOL program. These functions can be used to retrieve the numbers and values of command-line arguments entered when the program is executed.

The attached sample program demonstrates the use of these functions.

These functions work in combination with the ACCEPT and DISPLAY COBOL verbs: DISPLAY UPON ARGUMENT-NUMBER establishes which argument should be manipulated, and ACCEPT FROM ARGUMENT-VALUE returns the contents of the command-line argument identified in ARGUMENT-NUMBER.

ACCEPT VARIABLE FROM ARGUMENT-NUMBER returns the number of command-line arguments entered.

Old KB# 14331