Compaq COBOL AAQ2G1FTK User Manual

Page 207

Advertising
background image

Processing Files and Records

6.3 Creating and Processing Files

Example 6–23 Creating a Line Sequential File

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

SELECT LINESEQ-FILE ASSIGN TO "LINESEQ.DAT".

DATA DIVISION.
FILE SECTION.
FD

LINESEQ-FILE.

01

LINESEQ-RECORD

PIC X(25).

PROCEDURE DIVISION.
A000-BEGIN.

OPEN OUTPUT LINESEQ-FILE.
CLOSE LINESEQ-FILE.
STOP RUN.

By default, Compaq COBOL assumes sequential access mode when the line
sequential organization is specified. (See Example 6–23.)

Statements for Sequential and Line Sequential File Processing

Processing a sequential or line sequential file involves the following:

1.

Opening the file

2.

Processing the file with valid I/O statements

3.

Closing the file

Table 6–3 lists the valid I/O statements for sequential files, and Table 6–4 lists
the valid I/O statements for line sequential files. Both tables illustrate the
following relationships:

Organization determines valid access modes.

Organization and access mode determine valid open modes.

All three (organization, access, and open mode) enable or disable I/O
statements.

Table 6–3 Valid I/O Statements for Sequential Files

Open Mode

File
Organization

Access
Mode

Statement

INPUT

OUTPUT I/O

EXTEND

SEQUENTIAL SEQUENTIAL

READ

Yes

No

Yes

No

REWRITE

No

No

Yes

No

WRITE

No

Yes

No

Yes

UNLOCK

Yes

Yes

Yes

Yes

Writing a Sequential File

Each WRITE statement appends a logical record to the end of an output file,
thereby creating an entirely new record in the file. The WRITE statement
appends records to files that are OPEN for the following modes:

Processing Files and Records 6–27

Advertising