Created On:  30 April 2012


Is it possible to pass command-line parameters to a Visual COBOL main program using a linkage section item?


Yes, it is possible to pass command-line parameters to a Visual COBOL native linked .EXE by using the run-time tunable command_line_linkage.

Program should receive parameters as follows:

linkage section.
01 CommandLine.
     05 CommandLineLen          pic 9(4) comp.
     05 CommandLineParams    pic x(256).
procedure division using CommandLine.

You must create a text file (called cobconfig.cfg in this example) containing the following line:

set command_line_linkage=TRUE

and then set the environment variable COBCONFIG to point to the file:

SET COBCONFIG=c:\myapp\cobconfig.cfg

Then when you start the app by passing it parameters on the command-line, e.g. myapp.exe "This is a test"
then the length of the command line, 16 in this case, will be passed in CommandLineLen and the value of the parameter will be passed in CommandLineParams.

This works only for native code main programs.

To read a command-line in either native or managed code use the following instead:

working-storage section.
01 CommandLine     pic x(256).
procedure division.

   accept CommandLine from command-line