Accessing Files Programmer's Guide (32650-90885)

Chapter 7 111
Record Selection and Data Transfer
Record Selection
RIO access, in which you access only records that are not deactivated.
Mapped access is a special type of access available only through the HPFOPEN intrinsic,
in which you bypass file system data transfer mechanisms by referencing the file as an
array using a pointer declared in your program. Mapped files are discussed in chapter
11, "Accessing a File Using Mapped Access".
Sequential access
When you use this method of record selection, you assume that the record pointer is
already where you want it. You transfer your data using the FREAD or FWRITE intrinsic, and
the record pointer is automatically set to the beginning of the next record at the end of
each read or write; for this reason, this method is also called serial record selection. For
fixed-length and undefined-length record files, the file system updates the record pointer
by adding the uniform record length to the pointer after you read or write a record; for
variable-length record files, the file system takes the byte count from the record being
transferred plus some bytes required for overhead, and adds that to the record pointer,
resulting in a pointer to the next record.
Random access
If the record pointer is not indicating the location that you want, you can use the random
access method to move the pointer and begin your transfer wherever that you like; for this
reason, this method is also called controlled record selection.
It is possible to access specific records in a disk file with the FREADDIR and FWRITEDIR
intrinsics. The record number to be read or written is specified as one of the parameters in
the FREADDIR or FWRITEDIR intrinsic call. Following the read or write operation, the record
pointer is set to the next record, as in the default case. Note that FREADDIR and FWRITEDIR
may be issued only for a disk file composed of fixed-length or undefined-length records.
Update access
To update a logical record of a disk file, you use the FUPDATE intrinsic. The FUPDATE
intrinsic affects the last logical record (or block for NOBUF files) accessed by any intrinsic
call for the file named and writes information from a buffer in the stack into this record.
Following the update operation, the record pointer is set to indicate the next record
position.
The record number need not be supplied in the FUPDATE intrinsic call; FUPDATE
automatically updates the last record referenced in any intrinsic call. Note that the file
system assumes the record to be updated has just been accessed in some way.
You must open the file containing the record to be updated with the
access type
option
parameter of the HPFOPEN/FOPEN call set to update access. In addition, the file must
not contain variable-length records.
Table 7-1. Intrinsics for Data Transfer
FREAD Used for sequential read.
May be used with fixed-length, variable-length, or undefined-length record files.