Sample 2 demonstrates a program that reads a data file (line sequential file) created with the Editor, then creates a master file (indexed file). For details on how to use line sequential files and indexed files, refer to the “NetCOBOL User’s Guide”.
Overview
Reads a data file (line sequential file) that contains product codes, product names, and unit prices, and creates an indexed file with the product code as a primary record key and the product name as an alternate record key.
Files Included in Sample 2
SAMPLE2.COB (COBOL source program)
SAMPLE02. PRJ (COBOL project file)
SAMPLE02. CBI (COBOL compilation option file)
COBOL85.CBR (COBOL runtime initialization file)
DATAFILE(Data file)
COBOL Statements Used
The CLOSE , EXIT , GO TO , MOVE , OPEN , READ , and WRITE 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 "SAMPLE02.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 SAMPLE02.EXE is created.
Setting Runtime Environment Information
Select "Runtime Environment Setup Tool" from the "Tools" menu of the Project Manager.
The runtime environment setup tool is displayed.
Select "Open" on the "File" menu and select COBOL85.CBR in the folder that contains the executable program (SAMPLE02.EXE).
Select the Common tab and enter data as shown below:
For the file-identifier INFILE, specify DATAFILE that is the file name of data file (line sequential file).
For the file-identifier OUTFILE, specify MASTER that is the file name of master file (indexed file).
If MASTER is specified for OUTFILE, input data as follow and push the "Set" button.
Click the Apply button.
The data is saved in the object initialization file.
Select "Exit" on the "File" menu to terminate the runtime 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.
Press the ENTER key here and you will be taken into the Debugger.
Executing the Program
Once the project is built, you can run Sample 2 by double-clicking the mouse on SAMPLE2.EXE in the COBOL Project Manager window.
Execution Result
No termination message is displayed.
After completion of execution, an indexed file (MASTER) with a product code as a key is created in the SAMPLE02 directory. Use Windows Explorer or File Manager to check whether the indexed file was created.
Use the COBOL File Utility to confirm that indexed file (MASTER) was created correctly. The indexed file record can be browsed using the COBOL File Utility Browsing Records function. Refer to "COBOL File Utility" in Chapter 7 of the NetCOBOL User’s Guide for details.