Sample 6 demonstrates a program that receives an argument specified at program execution, using the command line argument handling function (ACCEPT FROM argument-name/argument-value). Refer to “Using ACCEPT and DISPLAY Statements” in the “NetCOBOL User’s Guide” for details on how to use the command line argument handling function.
Sample 6 also calls an internal program.
Overview
The sample program calculates the number of days from the start date to the end date. The start and end dates are specified as command arguments in the following format:
command-name start-date end-date
START-DATE , END-DATE:
Specify a year, month, and day between January 1, 1900 and December 31, 2172 in the YYYYMMDD format.
Files Included in Sample 6
SAMPLE6.COB (COBOL source program)
SAMPLE06. PRJ (COBOL project file)
SAMPLE06. CBI (COBOL compilation option file)
COBOL Statements Used
The ACCEPT, CALL, COMPUTE, COPY, DISPLAY, DIVIDE, EXIT, GO TO, IF, MOVE, and PERFORM statements are used.
Building/Rebuilding the Program
Project manager's build function is used to create the executable program.
In the following screen snapshots, the sample program was installed to C:\NetCOBOL. Your installation folder may be different.
The project manager is started, and project file "SAMPLE06.PRJ" is opened.
Select "Build" from Project Manager's "Project" menu or click on the Build button in the Project Manager toolbar.
After the build terminates, check that SAMPLE06.EXE is created.
Debugging the Program
To run this program under the control of the Debugger, select Debug from the Project menu. The COBOL Debugger starts and displays the Start Debugging dialog box. The application name is already entered for you, you need to enter the execution-time options (command line arguments) the program expects - a start and end date. For example:
After you type in the command-line parameters for the program in the “Executiontime options” field, press the ENTER key. The Debugger starts as shown in the following figure.
Executing the Program
To execute the program from COBOL Project Manager, you need to select “Execute with Arguments” from the Project menu.
Enter the start date and end date arguments in the “Specify Arguments” dialog.
Refer to Chapter 1, “A Quick Tour” for details on using the COBOL Project Manager.
Execution Result
Sample 6 displays the number of days from the specified start date to the specified end date.