Processing Files and Records
6.5 Updating Files
Example 6–43 (Cont.) Updating an Indexed File Randomly
FILE-CONTROL.
SELECT FLAVORS
ASSIGN TO "DAIRY"
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
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
HOLD-ICE-CREAM-MASTER
PIC X(51).
01
PROGRAM-STAT
PIC X.
88
OPERATOR-STOPS-IT
VALUE "1".
88
LETS-SEE-NEXT-STORE
VALUE "2".
88
NO-MORE-DUPLICATES
VALUE "3".
PROCEDURE DIVISION.
A000-BEGIN.
OPEN I-O FLAVORS.
PERFORM A030-RANDOM-READ UNTIL OPERATOR-STOPS-IT.
A020-EOJ.
DISPLAY "END OF JOB".
STOP RUN.
A030-RANDOM-READ.
DISPLAY "Enter key".
ACCEPT ICE-CREAM-MASTER-KEY.
PERFORM A100-READ-INPUT-BY-PRIMARY-KEY
THROUGH A100-READ-INPUT-EXIT.
DISPLAY " Do you want to terminate the session?".
PERFORM A040-GET-ANSWER UNTIL PROGRAM-STAT
= "Y" OR "N".
IF PROGRAM-STAT
= "Y" MOVE "1" TO PROGRAM-STAT.
A040-GET-ANSWER.
DISPLAY "Please answer Y or N"
ACCEPT PROGRAM-STAT.
A100-READ-INPUT-BY-PRIMARY-KEY.
READ FLAVORS KEY IS ICE-CREAM-MASTER-KEY
INVALID KEY DISPLAY "Master does not exist - Try again"
GO TO A100-READ-INPUT-EXIT.
DISPLAY ICE-CREAM-MASTER.
PERFORM A200-READ-BY-ALTERNATE-KEY UNTIL NO-MORE-DUPLICATES.
A100-READ-INPUT-EXIT.
EXIT.
A200-READ-BY-ALTERNATE-KEY.
DISPLAY "Do you want to see the next store in this state?".
PERFORM A040-GET-ANSWER UNTIL PROGRAM-STAT
= "Y" OR "N".
IF PROGRAM-STAT
= "Y"
MOVE "2" TO PROGRAM-STAT
READ FLAVORS KEY IS ICE-CREAM-STORE-STATE
INVALID KEY DISPLAY "No more stores in this state"
MOVE "3" TO PROGRAM-STAT.
(continued on next page)
6–58 Processing Files and Records
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......