Processing Files and Records
6.3 Creating and Processing Files
Table 6–5 Valid I/O Statements for Relative Files
File
Access
Organization
Mode
RELATIVE
SEQUENTIAL
RANDOM
DYNAMIC
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
Statement
INPUT
DELETE
No
READ
Yes
REWRITE
No
START
Yes
WRITE
No
UNLOCK
Yes
DELETE
No
READ
Yes
REWRITE
No
WRITE
No
UNLOCK
Yes
DELETE
No
READ
Yes
READ NEXT
Yes
REWRITE
No
START
Yes
WRITE
No
UNLOCK
Yes
Open Mode
OUTPUT I-O
EXTEND
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
No
Yes
No
No
Yes
No
Yes
Yes
No
Yes
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
Yes
Yes
No
Yes
Yes
No
Need help?
Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?