Compaq COBOL AAQ2G1FTK User Manual

Page 231

Advertising
background image

Processing Files and Records

6.5 Updating Files

4.

Using a START statement and then a READ statement to read the target
record

5.

Updating the record

6.

Rewriting the record into its cell

Example 6–38 reads a relative record sequentially and displays the record on the
terminal. The program then passes the record to an update routine that is not
included in the example. The update routine updates the record, and passes the
updated record back to the program illustrated in Example 6–38, which displays
the updated record on the terminal and rewrites the record in the same cell.

Example 6–38 Rewriting Relative Records in Sequential Access Mode

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

SELECT FLAVORS ASSIGN TO "BRAND"

ORGANIZATION IS RELATIVE
ACCESS MODE IS SEQUENTIAL
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 99.

PROCEDURE DIVISION.
A000-BEGIN.

OPEN I-O FLAVORS.
PERFORM A100-UPDATE-RECORD UNTIL KETCHUP-MASTER-KEY = 00.

A005-EOJ.

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

A100-UPDATE-RECORD.

DISPLAY "TO UPDATE A RECORD ENTER ITS RECORD NUMBER (ZERO to END)".
ACCEPT KETCHUP-MASTER-KEY WITH CONVERSION.
IF KETCHUP-MASTER-KEY IS NOT EQUAL TO 00

START FLAVORS KEY IS EQUAL TO KETCHUP-MASTER-KEY

INVALID KEY DISPLAY "BAD START"

STOP RUN.

PERFORM A200-READ-FLAVORS
DISPLAY

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

DISPLAY KETCHUP-MASTER

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

Update routine code here

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

DISPLAY

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

DISPLAY KETCHUP-MASTER
REWRITE KETCHUP-MASTER.

A200-READ-FLAVORS.

READ FLAVORS

AT END DISPLAY "END OF FILE"

GO TO A005-EOJ.

Processing Files and Records 6–51

Advertising