Compaq COBOL AAQ2G1FTK User Manual

Page 215

Advertising
background image

Processing Files and Records

6.3 Creating and Processing Files

01 EMPLOYEE.

02 FORENAME

PIC X(10).

02 BADGE-NO

PIC X(6).

02 DEPT

PIC X(2).

02 SURNAME

PIC X(20).

02 INITIAL

PIC X(1).

Then the following line in your program, which specifies the segmented key name
and three of its segments:

RECORD KEY IS NAME = SURNAME FORENAME INITIAL

causes Compaq COBOL to treat name as if it were an explicitly defined group
item consisting of the following:

02 SURNAME

PIC X(20).

02 FORENAME

PIC X(10).

02 INITIAL

PIC X(1).

You define a segmented key in either the RECORD KEY clause or the
ALTERNATE RECORD KEY clause. You use the START or READ statement
to reference a segmented key.

Each segment is a data-name of a data item in a record description entry. A
segment can be an alphanumeric or alphabetic item, a group item, or an unsigned
numeric display item. A segment can be qualified, but it cannot be a group item
containing a variable-occurrence item.

See the chapters on the Data Division and the Procedure Division in the Compaq
COBOL Reference Manual
for more information on segmented keys.

Example 6–27 shows how you might use segmented keys. In this example, SEG-
ICE-CREAM-KEY is a segmented-key name. ICE-CREAM-STORE-KIND and
ICE-CREAM-STORE-ZIP are the segments. Notice that the segmented-key name
is referenced in the READ statement.

Example 6–27 Using Segmented Keys

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

SELECT FLAVORS

ASSIGN TO "STORE"

ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS

SEG-ICE-CREAM-KEY =

ICE-CREAM-STORE-KIND,
ICE-CREAM-STORE-ZIP.

(continued on next page)

Processing Files and Records 6–35

Advertising