Compaq COBOL AAQ2G1FTK User Manual

Page 233

Advertising
background image

Processing Files and Records

6.5 Updating Files

Example 6–39 (Cont.) Rewriting Relative Records in Random Access Mode

A100-UPDATE-RECORD.

DISPLAY "TO UPDATE A RECORD ENTER ITS RECORD NUMBER".
ACCEPT KETCHUP-MASTER-KEY.
READ FLAVORS INVALID KEY DISPLAY "BAD READ"

GO TO A005-EOJ.

DISPLAY

"*********BEFORE UPDATE*********".

DISPLAY KETCHUP-MASTER.

********************************************************
*
*

Update routine

*
********************************************************

DISPLAY

"*********AFTER UPDATE*********".

DISPLAY KETCHUP-MASTER.
REWRITE KETCHUP-MASTER INVALID KEY DISPLAY "BAD REWRITE"

GO TO A005-EOJ.

6.5.2.2 Deleting Records from a Relative File

The DELETE statement logically removes an existing record from a relative file.
After successfully removing a record from a file, the program cannot later access
it. Two options are available for deleting relative records:

Sequential access mode deletion

Random access mode deletion

Deleting A Relative Record in Sequential Access Mode

Deleting a relative record in sequential access mode involves the following:

1.

Specifying ORGANIZATION IS RELATIVE in the Environment Division
SELECT clause

2.

Specifying ACCESS MODE IS SEQUENTIAL in the Environment Division
SELECT clause

3.

Opening the file for I-O

4.

Using a START statement to position the record pointer, or sequentially
reading the file up to the target record

5.

Deleting the last read record

Example 6–40 deletes relative records in sequential access mode.

Example 6–40 Deleting Relative Records in Sequential Access Mode

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

SELECT FLAVORS ASSIGN TO "BRAND"

ORGANIZATION IS RELATIVE

(continued on next page)

Processing Files and Records 6–53

Advertising