Record Selection [ Accessing Files Programmer's Guide ] MPE/iX 5.0 Documentation
Accessing Files Programmer's Guide
Record Selection
How are records selected for transfer? The file system intrinsics listed
in Table 7-1 are designed to move records to and from your file, but
how do they choose the records they want? The record pointer indicates
the specific location where a file will be accessed; records can be
transferred to or from this location, or the pointer can be moved to
another place in the file that you wish to access.
There are five methods of record selection that you can use to access
your file:
* sequential access, in which you transfer data to and from the
place the record pointer currently indicates
* random access, in which you move the record pointer before
transferring data
* update access, in which you choose a record and write a new record
over it
* 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. |
- File must be opened with Read, Read/Write, or Update access. -
| Successful read returns CCE condition code and transfer length; file |
| error results in CCL condition code; end-of-file results in CCG condition |
| code and returns a transfer length of zero. |
- FWRITE Used for sequential write. -
| May be used with fixed-length, variable-length, or undefined-length |
| record files. |
| File must be opened with Write, Write/SAVE, APPEND, Read/Write or Update |
| access. |
| Successful write returns CCE condition code; file error results in CCL |
| condition code; end-of-file results in CCG condition code. |
- FREADDIR Used for random-access read. -
- Used only with fixed or undefined-length record files. -
- File must be opened with Read, Read/Write, or Update access. -
| Successful read returns CCE condition code; file error results in CCL |
| condition code; end-of-file results in CCG condition code. No transfer |
| length is returned because you get the amount requested unless an error |
| occurs. |
- FREADSEEK Used for anticipatory random-access read into file system buffers. -
- Used only with buffered fixed-length or undefined-length record files. -
- File must be opened with Read, Read/Write, or Update access. -
| Successful read returns CCE condition code; file error results in CCL |
| condition code; end-of-file results in CCG condition code. |
- FWRITEDIR Used for direct write. -
- Use only with fixed-length or undefined-length record files. -
| File must be opened with Write, Write/SAVE, Read/Write or Update access; |
| APPEND not allowed. |
| Successful write returns CCE condition code; file error results in CCL |
| condition code; end-of-file results in CCG condition code. |
- FUPDATE Used to update previous record (logical or physical). -
- Used only with fixed-length or undefined-length record files. -
- File must be opened with Update access. No multirecord update allowed. -
| Successful update returns CCE condition code; file error results in CCL |
| condition code; end-of-file results in CCG condition code. |
------------------------------------------------------------------------------------------
RIO access
RIO is an access method that permits individual file records to be
deactivated. These inactive records retain their relative position
within the file. RIO access is intended for use primarily by COBOL
programs; however, you can access these files by programs written in any
language. You create an RIO file using the file type option parameter of
HPFOPEN/FOPEN.
RIO files may be accessed in two ways, RIO access and non-RIO access.
RIO access ignores the inactive records when the file is read
sequentially using the FREAD intrinsic, and these records are transparent
to you; however, they can be read by random access using FREADDIR. They
may be overwritten both sequentially and randomly using FWRITE,
FWRITEDIR, or FUPDATE. With non-RIO access, the internal structure of RIO
blocks is transparent.
MPE/iX 5.0 Documentation