Two intrinsics, FFINDN and FFINDBYKEY, can be used to set the logical pointer to the
lowest value of an alternate key field. The FFINDN intrinsic identifies the first record by using
a logical record number. The FFINDBYKEY intrinsic uses a key value to determine the first record.
When the first record has been located, the FREAD intrinsic reads the first record specified by
the alternate key. Subsequent reads reposition the logical pointer
and read the next logical record.
The FREADBYKEY intrinsic can also be used to position the logical
pointer by alternate key value. In this case, however, the user
must know the lowest value of the alternate key. An approximate
value cannot be used with this intrinsic.
Specifying the Record Number |
 |
The FFINDN intrinsic positions the pointer to the record
specified by the logical record number of the appropriate key. To
position the pointer to the particular record of a key, the intrinsic
parameters identify the particular key of interest and then the
record number.
Depending on how the file was built, the first record of any
key is identified by 1 or 0. Use option 5 or 7 of the LISTFILE command to determine how records are numbered
in the file you are accessing. A negative record number also positions
the pointer to the lowest value in the key field.
The key location identifies the key field to be used. Again,
use option 5 or 7 of the LISTFILE command to determine the location of the desired
key (ffn_key_location). The following example identifies the record
of an alternate key and reads the specified record:
Specifying a Key Value |
 |
The FFINDBYKEY intrinsic can also be used to position the pointer
to an alternate key. This intrinsic is intended to position the
pointer to the first occurrence of a record value that matches or
is greater than the key value. This is referred to as an approximate
match. To position the pointer to the first record of the key, supply
a key value that is less than any value of the key and specify a
relational operator of 1 (greater than) or 2 (equal to or greater
than). For example, a relational operator of 1 locates the first
record having a key value greater than the key value provided.
Figure 5-2 “FFINDBYKEY Intrinsic Sample” sets the pointer to the lowest value
of the alternate key by searching for the first occurrence of a
key value greater than (relop = 1) the value "0000":