|
7.3 File Organization
There are at least four ways in which the records on a file may be organised: SEQUENTIAL,
LINE SEQUENTIAL, RELATIVE, AND INDEXED. When a file contains several records (hundreds or even thousands) if you only wanted
to access one or two of them, it would waste processor time having to search an entire file
in order to read them if stored in sequential or line sequential formats. Hence, relative and
indexed files are of particular advantage.
       Relative files
These files are organised so that a record can be accessed by referring to its position within the file, i.e.
relative to other records. This is acheived by calculating the size (in characters, defined in the FD description)
of each record and multiplying it by the required nth record....eh?? you ask. Consider the following
program:
In order to read the indexed file sequentially, but in ascending order on the key field, the verb START
is used. For the above example:
OPEN INPUT IN-FILE
START IN-FILE
KEY GREATER THAN 'D23301'
INVALID KEY
DISPLAY 'NO MORE RECORDS BEYOND THIS POINT'
NOT INVALID KEY
....statements to process rest of file e.g. READ within a loop
END-START
To differentiate between a sequential READ and a random READ when using DYNAMIC access mode, you would use
the statements READ (with INVALID KEY) for random read, and READ...NEXT for sequential read (with AT END) e.g. :
*Random read
MOVE 'E11323' TO CODE-NUM
READ IN-FILE
INVALID KEY DISPLAY 'CODE NOT FOUND'
END-READ
*Sequential read
READ IN-FILE NEXT
AT END MOVE 'Y' TO EOF-FLAG
END-READ
|