Compaq COBOL AAQ2G1FTK User Manual

Page 222

Advertising
background image

Processing Files and Records
6.4 Reading Files

6.4.3 Reading an Indexed File

Your program can read an indexed file sequentially, randomly, or dynamically.

Reading an Indexed File Sequentially

Reading indexed records sequentially involves the following:

1.

Specifying ORGANIZATION IS INDEXED in the Environment Division
SELECT clause

2.

Specifying ACCESS MODE IS SEQUENTIAL in the Environment Division
SELECT clause

3.

Opening the file for INPUT or I-O

4.

Reading records from the beginning of the file as you would a sequential file
(using a READ...AT END statement)

The READ statement makes the next logical record of an open file available to the
program. It skips deleted records and sequentially reads and retrieves only valid
records. When the at end condition occurs, execution of the READ statement is
unsuccessful (see Chapter 7).

Example 6–32 reads an entire indexed file sequentially beginning with the first
record in the file, displaying every record on the terminal.

Example 6–32 Reading an Indexed File Sequentially

IDENTIFICATION DIVISION.
PROGRAM-ID. INDEX03.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT FLAVORS

ASSIGN TO "DAIRY"
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS ICE-CREAM-MASTER-KEY
ALTERNATE RECORD KEY IS ICE-CREAM-STORE-STATE

WITH DUPLICATES

ALTERNATE RECORD KEY IS ICE-CREAM-STORE-CODE.

DATA DIVISION.
FILE SECTION.
FD

FLAVORS.

01

ICE-CREAM-MASTER.
02 ICE-CREAM-MASTER-KEY

PIC XXXX.

02 ICE-CREAM-MASTER-DATA.

03

ICE-CREAM-STORE-CODE

PIC XXXXX.

03

ICE-CREAM-STORE-ADDRESS

PIC X(20).

03

ICE-CREAM-STORE-CITY

PIC X(20).

03

ICE-CREAM-STORE-STATE

PIC XX.

WORKING-STORAGE SECTION.
01

END-OF-FILE

PIC X.

(continued on next page)

6–42 Processing Files and Records

Advertising