Compaq AAQ2G1FTK Marine Radio User Manual


 
Processing Files and Records
6.5 Updating Files
Rewriting Relative Records in Random Access Mode
Rewriting relative records in random access mode involves the following:
1. Specifying ORGANIZATION IS RELATIVE in the Environment Division
SELECT clause
2. Specifying ACCESS MODE IS RANDOM (or DYNAMIC) in the Environment
Division SELECT clause
3. Opening the file for I-O
4. Moving the relative record number value of the record you want to read to the
RELATIVE KEY data name
5. Reading the record from the cell identified by the relative record number
6. Updating the record
7. Rewriting the record into the cell identified by the relative record number
During execution of the REWRITE statement, the I/O system randomly reads the
record identified by the RELATIVE KEY IS clause. The REWRITE statement
then places the successfully read record back into its cell in the file.
If the cell does not contain a valid record, or if the REWRITE operation is
unsuccessful, the invalid key condition occurs, and the REWRITE operation
fails (see Chapter 7).
Example 6–39 reads a relative record randomly, displays its contents on the
terminal, updates the record, displays its updated contents on the terminal, and
rewrites the record in the same cell.
Example 639 Rewriting Relative Records in Random Access Mode
IDENTIFICATION DIVISION.
PROGRAM-ID. REL08.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FLAVORS ASSIGN TO "BRAND"
ORGANIZATION IS RELATIVE
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.
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.
(continued on next page)
652 Processing Files and Records