Code for PROGRAM TO SEARCH THE RECORDS FROM FILE in Cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. SRCH.
ENVIRONMENT DIVISION.
FILE-CONTROL.
SELECT TRAN-FILE ASSIGN TO "MEMBER.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD TRAN-FILE
LABEL RECORDS ARE STANDARD.
01 TRAN-REC.
03 RNO PIC 999.
03 RNAME PIC X(12).
WORKING-STORAGE SECTION.
01 TBL.
03 ENTRIES OCCURS 10 TIMES INDEXED BY IDX.
05 RNO1 PIC 999.
05 RNAME1 PIC X(12).
01 EOF PIC X VALUE "N".
01 VAL PIC 999.
01 X PIC 9 VALUE 0.
PROCEDURE DIVISION.
BEGIN.
OPEN INPUT TRAN-FILE.
PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX>7
READ TRAN-FILE
AT END DISPLAY "ERROR"
NOT AT END
MOVE RNO TO RNO1(IDX)
MOVE RNAME TO RNAME1(IDX)
END-READ
END-PERFORM.
CLOSE TRAN-FILE.
DISPLAY "NO:" WITH NO ADVANCING.
ACCEPT VAL.
SET IDX TO 1
SEARCH ENTRIES
WHEN RNO1(IDX)=VAL
DISPLAY RNAME1(IDX)
END-SEARCH.
STOP RUN.