Processing Files and Records
6.3 Creating and Processing Files
Example 6–27 (Cont.) Using Segmented Keys
DATA DIVISION.
FILE SECTION.
FD FLAVORS.
01 ICE-CREAM-MASTER.
02 ICE-CREAM-DATA.
03 ICE-CREAM-STORE-KIND PIC XX.
03 ICE-CREAM-STORE-MANAGER PIC X(40).
03 ICE-CREAM-STORE-SIZE PIC XX.
03 ICE-CREAM-STORE-ADDRESS PIC X(20).
03 ICE-CREAM-STORE-CITY PIC X(20).
03 ICE-CREAM-STORE-STATE PIC XX.
03 ICE-CREAM-STORE-ZIP PIC XXXXX.
WORKING-STORAGE SECTION.
01 PROGRAM-STAT PIC X.
88 OPERATOR-STOPS-IT VALUE "1".
PROCEDURE DIVISION.
A000-BEGIN.
OPEN I-O FLAVORS.
PERFORM A020-INITIAL-PROMPT.
IF OPERATOR-STOPS-IT
PERFORM A005-TERMINATE.
PERFORM A030-RANDOM-READ.
PERFORM A025-SUBSEQUENT-PROMPTS UNTIL OPERATOR-STOPS-IT.
PERFORM A005-TERMINATE.
A005-TERMINATE.
DISPLAY "END OF JOB".
STOP RUN.
A020-INITIAL-PROMPT.
DISPLAY "Do you want to see the manager of a store?".
PERFORM A040-GET-ANS UNTIL PROGRAM-STAT = "Y" OR "y" OR "N" OR "n".
IF PROGRAM-STAT = "N" OR "n"
THEN
MOVE "1" TO PROGRAM-STAT.
A025-SUBSEQUENT-PROMPTS.
MOVE SPACE TO PROGRAM-STAT.
DISPLAY "Do you want to see the manager of another store?".
PERFORM A040-GET-ANS UNTIL PROGRAM-STAT = "Y" OR "y" OR "N" OR "n".
IF PROGRAM-STAT = "Y" OR "y"
THEN
PERFORM A030-RANDOM-READ
ELSE
MOVE "1" TO PROGRAM-STAT.
A030-RANDOM-READ.
DISPLAY "Enter store kind: ".
ACCEPT ICE-CREAM-STORE-KIND.
DISPLAY "Enter zip code: " AT LINE PLUS 2.
ACCEPT ICE-CREAM-STORE-ZIP.
PERFORM A100-READ-INPUT-BY-KEY.
A040-GET-ANS.
DISPLAY "Please answer Y or N"
ACCEPT PROGRAM-STAT.
A100-READ-INPUT-BY-KEY.
READ FLAVORS KEY IS SEG-ICE-CREAM-KEY
INVALID KEY
DISPLAY "Store does not exist - Try again"
NOT INVALID KEY
DISPLAY "The manager is: ", ICE-CREAM-STORE-MANAGER.
6–36 Processing Files and Records