Sample 7 demonstrates a program that changes the value of an environment variable during COBOL program execution, using the environment variable handling function (ACCEPT FROM/DISPLAY UPON environment-name/environment-value). Refer to “Using ACCEPT and DISPLAY Statements” in the “NetCOBOL User’s Guide” for details on how to use the environment variable handling function.
Overview
The sample program divides a master file (the indexed file created in Sample 2), storing product codes, product names, and unit prices, into two master files according to product codes. The following table shows the division method and the names of the two new master files:
Product Code | File Name |
---|---|
Code beginning with 0 | master-file-name.A |
Code beginning with a non-zero value | master-file-name.B |
Files Included in Sample 7
SAMPLE7.COB (COBOL source program)
SAMPLE07. PRJ (COBOL project file)
SAMPLE07. CBI (COBOL compilation option file)
COBOL85.CBR (COBOL run-time initialization file)
COBOL Statements Used
The ACCEPT, CLOSE, DISPLAY, EXIT, GO TO, IF, OPEN, READ, STRING, and WRITE statements are used.
Prerequisite to Executing the Program
The master file created in Sample 2 is used. Therefore, execute the program in Sample 2 before executing Sample 7.
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 "SAMPLE07.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 SAMPLE07.EXE is created.
Setting Runtime Environment Information
Select "Runtime Environment Setup Tool" from the "Tools" menu of the Project Manager.
The run-time environment setup tool is displayed.
Select "Open" on the "File" menu and select COBOL85.CBR in the folder that contains the executable program (SAMPLE07.EXE).
Select the Common tab and enter data as shown below:
For the file-identifier INFILE, specify the path name of the master file (MASTER) created in Sample 2.
Click the Apply button.
The data is saved in the object initialization file.
Select "Exit" on the "File" menu to terminate the run-time environment setup tool.
Debugging the Program
To run this program under the control of the Debugger, select Debug from the Project menu. The Debugger starts and displays the Start Debugging dialog box.
Click the OK button or press the ENTER key. You will be taken into the Debugger as shown in the following figure.
Executing the Program
To execute the program from COBOL Project Manager, select Execute from the Project menu. There are no command line arguments.
Note
Execute the program in Sample 2 beforehand.
Execution Result
The following two files are created in the directory of the master file created in Sample 2:
MASTER.A: Stores the data of products whose codes begin with 0.
MASTER.B: Stores the data of products whose codes begin with a non-zero value.
The contents of the newly created master files (MASTER.A and MASTER.B) can be checked with the program in Sample 5, in the same manner as for the master file created in Sample 2.