Compaq COBOL AAQ2G1FTK User Manual

Page 189

Advertising
background image

Processing Files and Records

6.1 Defining Files and Records

If a file has more than one record description, the different record descriptions
automatically share the same record area in memory. The I/O system does not
clear this area before it executes the READ statement. Therefore, if the record
read by the latest READ statement does not fill the entire record area, the area
not overlaid by the incoming record remains unchanged.

The record format type that was specified when the file was created must be used
for all subsequent accesses to the file.

In Example 6–1, a file contains a company’s stock inventory information (part
number, supplier, quantity, price). Within this file, the information is divided into
records. All information for a single piece of stock constitutes a single record.

Example 6–1 Sample Record Description

01

PART-RECORD.
02

PART-NUMBER

PIC 9999.

02

PART-SUPPLIER

PIC X(20).

02

PART-QUANTITY

PIC 99999.

02

PART-PRICE

PIC S9(5)V99.

Each record in the stock file is itself divided into discrete pieces of information
referred to as elementary items (02 level items). You give each elementary item
a specific location in the record, give it a name, and define its size and type. The
part number is an elementary item in the part record, as are supplier, quantity,
and price. In this example PART-RECORD contains four elementary items:
PART-NUMBER, PART-SUPPLIER, PART-QUANTITY, and PART-PRICE.

Fixed-Length Records

Files with a fixed-length record format contain the same size records. The
compiler generates the fixed-length format when either of the following conditions
is true:

The RECORD CONTAINS clause specifies a fixed number of characters.

The RECORD CONTAINS clause is omitted.

The compiler does not generate fixed-length format when any of the following
conditions exist:

The file description contains a RECORD CONTAINS TO clause or a RECORD
VARYING clause.

The program specifies a print-control file by referring to the file with:

The ADVANCING phrase in a WRITE statement

An APPLY PRINT-CONTROL clause in the Environment Division

A LINAGE clause in the file description

Report Writer statements and phrases

ASSIGN TO PRINTER

LINE SEQUENTIAL organization is specified.

Processing Files and Records 6–9

Advertising