Compaq COBOL AAQ2G1FTK User Manual

Page 206

Advertising
background image

Processing Files and Records
6.3 Creating and Processing Files

6.

If the file characteristics specified by the program attempting an OPEN
operation differ from the characteristics specified when the file was created,
the OPEN statement fails.

If the file is on magnetic tape, the I/O system rewinds the tape. (To close a file
on tape without rewinding the tape, use the NO REWIND phrase.) This speeds
processing when you want to write another file beyond the end of the first file, as
in the following example:

CLOSE MASTER-FILE NO REWIND.

You can also close a file and prevent your program from opening that file again in
the same run, as in the following example:

CLOSE MASTER-FILE WITH LOCK.

6.3.2 File Handling for Sequential and Line Sequential Files

Creating a sequential or line sequential file involves the following:

1.

Opening the file for OUTPUT or EXTEND

2.

Executing valid I/O statements

3.

Closing the file

By default, Compaq COBOL assumes sequential organization and sequential
access mode. (See Example 6–22.)

Example 6–22 Creating a Sequential File

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

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

DATA DIVISION.
FILE SECTION.
FD

TRANS-FILE.

01

TRANSACTION-RECORD

PIC X(25).

PROCEDURE DIVISION.
A000-BEGIN.

OPEN OUTPUT TRANS-FILE.
PERFORM A010-PROCESS-TRANS

UNTIL TRANSACTION-RECORD = "END".

CLOSE TRANS-FILE.
STOP RUN.

A010-PROCESS-TRANS.

DISPLAY "Enter next record

- X(25)".

DISPLAY "enter END to terminate the session".
DISPLAY "-------------------------".
ACCEPT TRANSACTION-RECORD.
IF TRANSACTION-RECORD NOT = "END"

WRITE TRANSACTION-RECORD.

6–26 Processing Files and Records

Advertising