Chapter 13. RANDOM FILE ACCESS FOR KEYED FILES
Upon completion of this chapter, you should be able to
Describe the various methods of processing keyed files.
Describe the various formats of the READ statement and demonstrate their use.
Describe how the REWRITE statement is used to update a keyed file.
Describe the use of the START statement and demonstrate its use.
Describe and demonstrate how files are accessed dynamically.
ACCESSING A KEYED FILE RANDOMLY
With a keyed file we can access records either sequentially or randomly, depending on the user's needs. The term random access implies that records are to be processed or accessed in some order other than the one in which they were physically written on the disk.
When records are added to a keyed file, they are placed at the end of the data file. At the same time, an entry is added to the index file in the proper location to keep the index in sequence according to the key field or fields.
Keyed files may be accessed randomly to respond to special requests or inquiries or accessed randomly to verify the existence of a record and to update that record. Let us consider an example of random inquiries to a keyed file for the purpose of printing an employee request report. Figure 13.1 illustrates the processing involved.
Suppose managers submit daily requests for employee information required for the next business day. All requests submitted are grouped together and entered into one batch file called EMPLOYEE-QUERY-FILE.