Processing Files and Records
6.5 Updating Files
Example 643 (Cont.) Updating an Indexed File Randomly
IF LETS-SEE-NEXT-STORE AND
ICE-CREAM-STORE-STATE = "NY"
PERFORM A500-DELETE-RANDOM-RECORD.
IF LETS-SEE-NEXT-STORE AND
ICE-CREAM-STORE-STATE = "NJ"
MOVE "Monmouth" TO ICE-CREAM-STORE-CITY
PERFORM A400-REWRITE-RANDOM-RECORD.
IF LETS-SEE-NEXT-STORE AND
ICE-CREAM-STORE-STATE = "CA"
MOVE ICE-CREAM-MASTER TO HOLD-ICE-CREAM-MASTER
PERFORM A500-DELETE-RANDOM-RECORD
MOVE HOLD-ICE-CREAM-MASTER TO ICE-CREAM-MASTER
MOVE "AZ" TO ICE-CREAM-STORE-STATE
PERFORM A300-WRITE-RANDOM-RECORD.
IF PROGRAM-STAT = "N"
MOVE "3" TO PROGRAM-STAT.
A300-WRITE-RANDOM-RECORD.
WRITE ICE-CREAM-MASTER
INVALID KEY DISPLAY "Bad write - ABORTED"
STOP RUN.
A400-REWRITE-RANDOM-RECORD.
REWRITE ICE-CREAM-MASTER
INVALID KEY DISPLAY "Bad rewrite - ABORTED"
STOP RUN.
A500-DELETE-RANDOM-RECORD.
DELETE FLAVORS
INVALID KEY DISPLAY "Bad delete - ABORTED"
STOP RUN.
Updating an Indexed File Dynamically
Updating indexed records in dynamic access mode involves the following:
1. Specifying ORGANIZATION IS INDEXED in the Environment Division
SELECT clause
2. Specifying ACCESS MODE IS DYNAMIC in the Environment Division
SELECT clause
3. Opening the file for I-O
4. Reading the records sequentially (using the START statement to position
the record pointer and then using the READ...NEXT statement) or randomly
(initializing the RECORD KEY or ALTERNATERECORD KEY data name
and then reading records in any order you want using the INVALID KEY
phrase) (See Example 6–43.)
5. Rewriting or deleting records using the INVALIDKEY phrase
For indexed files with duplicate primary keys values, rewriting and deleting work