Processing Files and Records
6.5 Updating Files
Example 6–42 (Cont.) Updating an Indexed File Sequentially
PROCEDURE DIVISION.
A000-BEGIN.
OPEN I-O FLAVORS.
DISPLAY "Which store code do you want to find?".
ACCEPT REWRITE-KEY.
DISPLAY "What is its new address?".
ACCEPT NEW-ADDRESS.
DISPLAY "Which state do you want to delete?".
ACCEPT DELETE-KEY.
PERFORM A100-READ-INPUT UNTIL END-OF-FILE = "Y".
A020-EOJ.
DISPLAY "END OF JOB".
STOP RUN.
A100-READ-INPUT.
READ
FLAVORS AT END MOVE "Y" TO END-OF-FILE.
IF END-OF-FILE NOT = "Y" AND
REWRITE-KEY = ICE-CREAM-STORE-CODE
PERFORM A200-REWRITE-MASTER.
IF END-OF-FILE NOT = "Y" AND
DELETE-KEY
= ICE-CREAM-STORE-STATE
PERFORM A300-DELETE-MASTER.
A200-REWRITE-MASTER.
MOVE NEW-ADDRESS TO ICE-CREAM-STORE-ADDRESS.
REWRITE ICE-CREAM-MASTER
INVALID KEY DISPLAY "Bad rewrite - ABORTED"
STOP RUN.
A300-DELETE-MASTER.
DELETE FLAVORS.
Updating an Indexed File Randomly
Updating indexed records in random access mode involves the following:
1.
Specifying ORGANIZATION IS INDEXED in the Environment Division
SELECT clause
2.
Specifying ACCESS MODE IS RANDOM in the Environment Division
SELECT clause
3.
Opening the file for I-O
4.
Initializing the RECORD KEY or ALTERNATE RECORD KEY data name
5.
Writing, rewriting, or deleting records using the INVALID KEY phrase
You do not need to first read a record to update or delete it. If the primary or
alternate key you specify allows duplicates, only the first occurrence of a record
with a matching value will be updated.
Example 6–43 updates an indexed file randomly.
Example 6–43 Updating an Indexed File Randomly
IDENTIFICATION DIVISION.
PROGRAM-ID. INDEX07.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
(continued on next page)
Processing Files and Records 6–57
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......