Using the Primary Key for a Record Look-up

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 LOOKUP-A-RECORD.
PERFORM EOJ-ROUTINE.
STOP RUN.


INITIALIZATION-ROUTINE.
OPEN I-O PERSON-FILE.


LOOKUP-A-RECORD.
DISPLAY 'Enter ID Number for the record you want to view: '.
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 '(' PERSON-AREA-CODE ') '
PERSON-PHONE-NUMBER (1:3) '-'
PERSON-PHONE-NUMBER (4:4)
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.