KSAM/3000 Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 3 USING KSAM FILES IN COBOL PROGRAMS CKREAD |
|
A call to procedure CKREAD makes available the next logical record from a file.
In order to read records in sequential order by key value, call procedure CKREAD. The file must have been opened in input or input-output mode with access mode specified as either sequential or dynamic.
The file from which the record is read must be open for sequential or dynamic access (access mode = 0 or 2.) It may be opened for input only or input-output (input-output type = 0 or 2), but not for output only. When the file is opened initially for input or input-output, the logical record pointer is positioned at the first sequential record; that is, at the record with the lowest key value. The key used is the primary key unless a previous call to CKSTART has specified an alternate key. When a call to CKREAD is executed, the record at which the record pointer is currently positioned is read into the location specified by record. If, when CKREAD is executed, there is no next logical record in the file, the at end condition is returned to status; that is, status is to"10". Note that a call to the procedure CKSTART can be used to reposition the pointer for subsequent sequential access according to primary or alternate key order. In order to update records in sequential order, CKREAD must be called before executing either of the update procedures CKREWRITE and CKDELETE. When access is shared, it is important to include the call to CKREAD within the same locked portion of code that includes the call to CKREWRITE or CKDELETE. This insures that the correct record is modified or deleted. SHARED ACCESS. Because CKREAD is a pointer-dependent procedure (refer to Table 3-3 “Positioning the Logical Record Pointer”), the actual record read depends on the current position of the logical record pointer. When access is shared, this pointer position can be made incorrect by other users without your program being aware of it. For this reason, you should lock the file, position the pointer with a pointerdent procedure, and then call CKREAD. When the last record is read, you should then unlock the file so other users can access the file. Example 2 below illustrates how you should read the file sequentially when access is shared. Using the WORKING-STORAGE SECTION from Figure 3-2 Representation of KSAMFILE Used in COBOL Examples and the FINISH procedure in the CKCLOSE example, the following procedures read records in sequential order from file KSAMFILE and display them on the standard output device.
|