Compaq COBOL AAQ2G1FTK User Manual

Page 235

Advertising
background image

Processing Files and Records

6.5 Updating Files

Example 6–41 (Cont.) Deleting Relative Records in Random Access Mode

ACCESS MODE IS RANDOM
RELATIVE KEY IS KETCHUP-MASTER-KEY.

DATA DIVISION.
FILE SECTION.
FD

FLAVORS.

01

KETCHUP-MASTER

PIC X(50).

WORKING-STORAGE SECTION.
01

KETCHUP-MASTER-KEY

PIC 99 VALUE 1.

PROCEDURE DIVISION.
A000-BEGIN.

OPEN I-O FLAVORS.
PERFORM A010-DELETE-RECORDS UNTIL KETCHUP-MASTER-KEY = 00.

A005-EOJ.

DISPLAY "END OF JOB".
CLOSE FLAVORS.
STOP RUN.

A010-DELETE-RECORDS.

DISPLAY "TO DELETE A RECORD ENTER ITS RECORD NUMBER".
ACCEPT KETCHUP-MASTER-KEY.
IF KETCHUP-MASTER-KEY NOT = 00

DELETE FLAVORS RECORD

INVALID KEY DISPLAY "INVALID DELETE"

STOP RUN.

6.5.3 Updating an Indexed File

Updating a record in an indexed file in sequential access mode involves the
following:

1.

Reading the target record

2.

Verifying that the record is the one you want to change

3.

Changing the record

4.

Rewriting or deleting the target record

A program updates an indexed file in random access mode by rewriting or
deleting the record.

Three options are available for updating indexed records:

Sequential access mode updating

Random access mode updating

Dynamic access mode updating

Note

A program cannot rewrite an existing record if it changes the contents
of the primary key in that record. Instead, the program must delete the
record and write a new record. Alternate key values can be changed at
any time. However, the value of alternate keys must be unique unless the
WITH DUPLICATES phrase is present.

Processing Files and Records 6–55

Advertising