ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PERSON-FILE
ASSIGN TO 'C:\PCOBWIN\ROGERS\I\PERSON.DAT'
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS PERSON-KEY
ALTERNATE RECORD KEY IS PERSON-ALTERNATE-KEY
WITH DUPLICATES
FILE STATUS IS IO-FILE-STATUS.
DATA DIVISION.
FILE SECTION.
FD PERSON-FILE
DATA RECORD IS PERSON-ITEM.
01 PERSON-ITEM.
02 PERSON-KEY.
03 PERSON-ID PICTURE X(4).
02 PERSON-ALTERNATE-KEY.
03 PERSON-NAME PICTURE X(20).
02 PERSON-ADDRESS PICTURE X(20).
02 PERSON-CITY PICTURE X(18).
02 PERSON-STATE PICTURE X(2).
02 PERSON-ZIP PICTURE X(5).
02 PERSON-PHONE.
03 PERSON-AREA-CODE PICTURE X(3).
03 PERSON-PHONE-NUMBER PICTURE X(7).
02 PERSON-STATUS PICTURE X.
WORKING-STORAGE SECTION.
01 INVALID-PERSON-KEY-FLAG PICTURE X.
88 INVALID-PERSON-KEY VALUE 'Y'.
88 VALID-PERSON-KEY VALUE 'N'.
01 IO-FILE-STATUS PICTURE X(2).
01 EOF-FLAG PICTURE X.
88 NO-MORE-INPUT VALUES 'N' 'n'.
PROCEDURE DIVISION.
MAIN-LINE.
PERFORM INITIALIZATION-ROUTINE.
PERFORM DATA-ENTRY
UNTIL NO-MORE-INPUT.
PERFORM EOJ-ROUTINE.
STOP RUN.
* We use OPEN OUTPUT to create a new file. If the file already
* existed we would use OPEN I-O PERSON-FILE to add additional
* records to it.
INITIALIZATION-ROUTINE.
OPEN OUTPUT PERSON-FILE.
PERFORM PROMPT-THE-OPERATOR.
DATA-ENTRY.
DISPLAY 'Enter ID Number: '.
ACCEPT PERSON-ID.
DISPLAY 'Enter Name: '.
ACCEPT PERSON-NAME.
DISPLAY 'Enter Address: '.
ACCEPT PERSON-ADDRESS.
DISPLAY 'Enter City: '.
ACCEPT PERSON-CITY.
DISPLAY 'Enter State: '.
ACCEPT PERSON-STATE.
DISPLAY 'Enter Zip Code: '.
ACCEPT PERSON-ZIP.
DISPLAY 'Enter Area Code and Phone Number: '.
ACCEPT PERSON-PHONE.
MOVE '1' TO PERSON-STATUS.
PERFORM ADD-PERSON-ITEM.
IF VALID-PERSON-KEY
DISPLAY 'Record added successfully'
ELSE
DISPLAY 'Error adding record to Person file'
END-IF.
PERFORM PROMPT-THE-OPERATOR.
EOJ-ROUTINE.
CLOSE PERSON-FILE.
PROMPT-THE-OPERATOR.
DISPLAY 'Do you want to enter a new record? '.
ACCEPT EOF-FLAG.
IF NOT NO-MORE-INPUT
MOVE 'Y' TO EOF-FLAG.
ADD-PERSON-ITEM.
MOVE 'N' TO INVALID-PERSON-KEY-FLAG.
WRITE PERSON-ITEM
INVALID KEY.
MOVE 'Y' TO INVALID-PERSON-KEY-FLAG