4 file handling for indexed files – Compaq COBOL AAQ2G1FTK User Manual

Page 212

Advertising
background image

Processing Files and Records
6.3 Creating and Processing Files

Table 6–5 Valid I/O Statements for Relative Files

Open Mode

File
Organization

Access
Mode

Statement

INPUT

OUTPUT I-O

EXTEND

RELATIVE

SEQUENTIAL

DELETE
READ
REWRITE
START
WRITE
UNLOCK

No
Yes
No
Yes
No
Yes

No
No
No
No
Yes

Yes

Yes
Yes
Yes
Yes
No
Yes

No
No
No
No
Yes

Yes

RANDOM

DELETE
READ
REWRITE
WRITE
UNLOCK

No
Yes
No
No
Yes

No
No
No
Yes
Yes

Yes
Yes
Yes
Yes
Yes

No
No
No
No
No

DYNAMIC

DELETE
READ
READ NEXT
REWRITE
START
WRITE
UNLOCK

No
Yes
Yes
No
Yes
No

Yes

No
No
No
No
No

Yes
Yes

Yes
Yes
Yes
Yes
Yes
Yes

Yes

No
No
No
No
No

No
No

Writing a Relative File

Each WRITE statement places a record into a cell that contains no valid data. If
the cell does not already exist, the I/O system creates it. To change the contents
of a cell that already contains valid data, use the REWRITE statement.

6.3.4 File Handling for Indexed Files

Creating an indexed file involves the following tasks:

1.

Specifying ORGANIZATION IS INDEXED in the Environment Division
SELECT clause

2.

Specifying ACCESS MODE IS SEQUENTIAL (or RANDOM or DYNAMIC) in
the Environment Division SELECT clause

3.

Opening the file for OUTPUT (to create and add records) or for I-O (to add,
change, delete, or extend records)

4.

Initializing the key values

5.

Executing a WRITE statement

6.

Closing the file

One way to populate an indexed file is to sequentially write the records in
ascending order by primary key. Example 6–26 creates and populates an indexed
file from a sequential file, which has been sorted in ascending sequence on the
primary key field. Notice that the primary and alternate keys are initialized in
ICE-CREAM-MASTER when the contents of the fields in INPUT-RECORD are
read into ICE-CREAM-MASTER before the record is written.

6–32 Processing Files and Records

Advertising