Compaq AAQ2G1FTK Marine Radio User Manual


 
Processing Files and Records
6.5 Updating Files
Updating an Indexed File Sequentially
Updating indexed records in sequential acess mode involves the following:
1. Specifying ORGANIZATION IS INDEXED in the Environment Division
SELECT clause
2. Specifying ACCESS MODE IS SEQUENTIAL in Environment Division
SELECT clause
3. Opening the file for I-O
4. Reading records as you would a sequential file (use the READ statement with
the AT END phrase)
5. Rewriting or deleting records using the INVALID KEY phrase
The READ statement makes the next logical record of an open file available to the
program. It skips deleted records and sequentially reads and retrieves only valid
records. When the at end condition occurs, execution of the READ statement is
unsuccessful (see Chapter 7).
The REWRITE statement replaces the record just read, while the DELETE
statement logically removes the record just read from the file.
Example 6–42 updates an indexed file sequentially.
Example 642 Updating an Indexed File Sequentially
IDENTIFICATION DIVISION.
PROGRAM-ID. INDEX06.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FLAVORS ASSIGN TO "DAIRY"
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS ICE-CREAM-MASTER-KEY
ALTERNATE RECORD KEY IS ICE-CREAM-STORE-STATE
WITH DUPLICATES
ALTERNATE RECORD KEY IS ICE-CREAM-STORE-CODE.
DATA DIVISION.
FILE SECTION.
FD FLAVORS.
01 ICE-CREAM-MASTER.
02 ICE-CREAM-MASTER-KEY PIC XXXX.
02 ICE-CREAM-MASTER-DATA.
03 ICE-CREAM-STORE-CODE PIC XXXXX.
03 ICE-CREAM-STORE-ADDRESS PIC X(20).
03 ICE-CREAM-STORE-CITY PIC X(20).
03 ICE-CREAM-STORE-STATE PIC XX.
WORKING-STORAGE SECTION.
01 END-OF-FILE PIC X.
01 REWRITE-KEY PIC XXXXX.
01 DELETE-KEY PIC XX.
01 NEW-ADDRESS PIC X(20).
(continued on next page)
656 Processing Files and Records