Compaq COBOL AAQ2G1FTK User Manual

Page 190

Advertising
background image

Processing Files and Records
6.1 Defining Files and Records

Example 6–2 Determining Fixed-Length Record Size

FD

FIXED-FILE
RECORD CONTAINS 100 CHARACTERS.

01

FIXED-REC

PIC X(75).

Fixed-length record size is determined by either the largest record description or
the record size specified by the RECORD CONTAINS clause, whichever is larger.
Example 6–2 shows how fixed-length record size is determined.

For the file, FIXED-FILE, the RECORD CONTAINS clause specifies a record size
larger than the record description; therefore, the record size is 100 characters.

In Example 6–2, the following warning message is generated when the file
FIXED-FILE is used:

"Record contains value is greater than length of longest record."

If the multiple record descriptions are associated with the file, the size of the
largest record description is used as the size. In Example 6–3, for the file REC-
FILE, the FIXED-REC2 record specifies the largest record size; therefore, the
record size is 90 characters.

Example 6–3 Determining Fixed-Length Record Size for Files with Multiple

Record Descriptions

FD

REC-FILE
RECORD CONTAINS 80 CHARACTERS.

01

FIXED-REC1

PIC X(75).

01

FIXED-REC2

PIC X(90).

When the file REC-FILE is used, the following warning message is generated:

"Longest record is longer than RECORD CONTAINS value -

longest record size used."

Variable-Length Records

Files with a variable-length record format can contain records of different length.
The compiler generates the variable-length attribute for a file when the file
description contains a RECORD VARYING clause or a RECORD CONTAINS TO
clause.

Each record is written to the file with a 32-bit integer that specifies the size of
the record. This integer is not counted in the size of the record.

Examples 6–4, 6–5, and 6–6 show you the three ways you can create a variable-
length record file.

In Example 6–4, the DEPENDING ON phrase sets the OUT-REC record length.
The IN-TYPE data field determines the OUT-LENGTH field’s contents.

Example 6–5 shows how to create variable-length records using the RECORD
VARYING phrase.

6–10 Processing Files and Records

Advertising