KSAM/3000 Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 4 USING KSAM FILES IN SPL PROGRAMSFFINDN |
|
Positions the logical record pointer to relative record number according to key sequence.
When FFINDN is executed, it positions the KSAM logical record pointer to the record whose relative record number is specified in the parameter number. Records are numbered from the record with the lowest key value in the key that starts at keylocation in each record. Record numbering starts with zero unless the flagword in the FOPEN ksamparam parameter specifies that record numbering starts with 1, or the FIRSTREC parameter in the >BUILD command is set to 1.
When you specify the relative record number, it is important not to confuse this number with the chronological record number, the number of the record as it is stored in the file. To illustrate, assume a file in which records have been stored in chronological order from the beginning of the file (BOF). Each record has a key starting in byte 3 that contains a name. The relative record number is based on the value of this key, not the relative location of the record in the file. For example:
This call positions the logical record pointer (as shown in Figure 4-3 File Position with FFINDN) to record number 4 of the key at location 3. Note that record number 4 is the fifth record in the sequence of key values:
If you want to position the chronological record pointer to the relative record number in chronological sequence from the beginning of the file, you can use the intrinsic FPOINT, discussed later in this section. Chronological order is the order in which records are written. In Figure 4-3 File Position with FFINDN, record number 4 in key order, to which FFINDN positioned the file pointer, is also record number 2 in chronological order. Note that FFINDN is useful to reset the pointer to an alternate key. For example, when you open the file, the primary key is selected by default. If you want to select another key starting in location 23 and position to the first record in key sequence, you can use the following command:
If you use FFINDN to position the pointer before calling another procedure that reads or updates the file in a shared environment, you must call FLOCK before calling FFINDN. Then, after performing the read or update operation, you should unlock the file so other users can access it. If you lock the file after calling FFINDN, another user can change the pointer position without your program being aware of it. |