Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.8 Sample 7: Environment Variable Handling

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

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.

  1. The project manager is started, and project file "SAMPLE07.PRJ" is opened.

  2. 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

  1. Select "Runtime Environment Setup Tool" from the "Tools" menu of the Project Manager.

    The run-time environment setup tool is displayed.

  2. Select "Open" on the "File" menu and select COBOL85.CBR in the folder that contains the executable program (SAMPLE07.EXE).

  3. 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.

  4. Click the Apply button.

    The data is saved in the object initialization file.

  5. 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:

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.