Compaq AAQ2G1FTK Marine Radio User Manual


 
Processing Files and Records
6.4 Reading Files
available to the program. In dynamic mode, the program can switch from random
access I/O statements to sequential access I/O statements in any order, without
closing and reopening files. However, you must use the READ NEXT statement
to sequentially read a relative file open in dynamic mode.
Sequential processing need not begin at the first record of a relative file. The
START statement repositions the file position indicator for subsequent I/O
operations.
A sequential read of a dynamic file is indicated by the NEXT phrase of the READ
statement. A READ NEXT statement should follow the START statement since
the READ NEXT statement reads the next record indicated by the current record
pointer. Subsequent READ NEXT statements sequentially retrieve records until
another START statement or random READ statement executes.
Example 6–31 processes a relative file containing 10 records. If the previous
program examples in this chapter have been run, each record has a unique even
number from 2 to 20 as its key. The program positions the record pointer (using
the START statement) to the cell corresponding to the value in INPUT-RECORD-
KEY. The program’s READ...NEXT statement retrieves the remaining valid
records in the file for display on the terminal.
Example 631 Reading a Relative File Dynamically
IDENTIFICATION DIVISION.
PROGRAM-ID. REL06.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FLAVORS ASSIGN TO "BRAND"
ORGANIZATION IS RELATIVE
ACCESS MODE IS DYNAMIC
RELATIVE KEY IS KETCHUP-MASTER-KEY.
DATA DIVISION.
FILE SECTION.
FD FLAVORS.
01 KETCHUP-MASTER PIC X(50).
WORKING-STORAGE SECTION.
01 KETCHUP-MASTER-KEY PIC 99.
01 END-OF-FILE PIC X VALUE "N".
PROCEDURE DIVISION.
A000-BEGIN.
OPEN I-O FLAVORS.
DISPLAY "Enter number".
ACCEPT KETCHUP-MASTER-KEY.
START FLAVORS KEY = KETCHUP-MASTER-KEY
INVALID KEY DISPLAY "Bad START statement"
GO TO A005-END-OF-JOB.
PERFORM A010-DISPLAY-RECORDS UNTIL END-OF-FILE = "Y".
A005-END-OF-JOB.
DISPLAY "END OF JOB".
CLOSE FLAVORS.
STOP RUN.
A010-DISPLAY-RECORDS.
READ FLAVORS NEXT RECORD AT END MOVE "Y" TO END-OF-FILE.
IF END-OF-FILE NOT = "Y" DISPLAY KETCHUP-MASTER.
Processing Files and Records 641