Processing Files and Records
6.5 Updating Files
Example 6–43 (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 ALTERNATE RECORD 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 INVALID KEY phrase
For indexed files with duplicate primary keys values, rewriting and deleting work
as if the file was opened in sequential access mode. You first read the record,
then update or delete the record just read.
For indexed files without duplicates allowed on the primary key, rewriting and
deleting work as if the file was opened in random access mode. Specify the value
of the primary key data item to indicate the target record, then update or delete
that record.
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......