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).
PROCEDURE DIVISION.
MAIN-LINE.
PERFORM INITIALIZATION-ROUTINE.
PERFORM CHANGE-A-RECORD.
PERFORM EOJ-ROUTINE.
STOP RUN.
INITIALIZATION-ROUTINE.
OPEN I-O PERSON-FILE.
CHANGE-A-RECORD.
DISPLAY 'Enter ID Number for the record you want to change: '.
ACCEPT PERSON-KEY.
PERFORM GET-PERSON-ITEM.
IF INVALID-PERSON-KEY
DISPLAY 'Record not found'
ELSE
DISPLAY PERSON-NAME
DISPLAY PERSON-ADDRESS
DISPLAY PERSON-CITY ' ' PERSON-STATE ' ' PERSON-ZIP
DISPLAY 'Enter new area code and phone number: '
ACCEPT PERSON-PHONE
PERFORM REPLACE-PERSON-ITEM
IF VALID-PERSON-KEY
DISPLAY 'Phone number updated: '
'(' PERSON-AREA-CODE ') '
PERSON-PHONE-NUMBER (1:3) '-'
PERSON-PHONE-NUMBER (4:4)
ELSE
DISPLAY 'Error updating phone number'
END-IF
END-IF.
EOJ-ROUTINE.
CLOSE PERSON-FILE.
GET-PERSON-ITEM.
MOVE 'N' TO INVALID-PERSON-KEY-FLAG.
READ PERSON-FILE
INVALID KEY
MOVE 'Y' TO INVALID-PERSON-KEY-FLAG.
REPLACE-PERSON-ITEM.
MOVE 'N' TO INVALID-PERSON-KEY-FLAG.
REWRITE PERSON-ITEM
INVALID KEY
MOVE 'Y' TO INVALID-PERSON-KEY-FLAG.