Chapter 13. RANDOM FILE ACCESS FOR KEYED FILES

CHAPTER OBJECTIVES

Upon completion of this chapter, you should be able to

  1. Describe the various methods of processing keyed files.

  2. Describe the various formats of the READ statement and demonstrate their use.

  3. Describe how the REWRITE statement is used to update a keyed file.

  4. Describe the use of the START statement and demonstrate its use.

  5. 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.

Record ...

Get PROGRAMMING IN COBOL/400: 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.