Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.3 Sample 2: Using Line Sequential and Indexed Files

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

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.

  1. The project manager is started, and project file "SAMPLE02.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 SAMPLE02.EXE is created.

Setting Runtime Environment Information

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

    The runtime environment setup tool is displayed.

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

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

  4. If MASTER is specified for OUTFILE, input data as follow and push the "Set" button.

  5. Click the Apply button.

    The data is saved in the object initialization file.

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