HPlogo Using KSAM XL and KSAM 64 > Chapter 5 Reading File Data

Random Access of a Single Record

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 4 ♥
E0394 Edition 3

A record can be accessed randomly by a particular key value or by its relative or physical record number.

Using a Key Value


The FREADBYKEY intrinsic is recommended for retrieving records randomly. The desired key value and the key location are specified in the intrinsic parameters. The index of the specified key is checked for a matching key value and the appropriate record is read.

If an exact key value match is not found, an error condition is returned. Because of this, the FREADBYKEY intrinsic is not appropriate when searching for an approximate key value or the lowest value of a key. Use the FFINDBYKEY intrinsic in such cases.

Figure 5-4 Accessing a Record by Key Value

  target   := '    ';
  tcount   := -8;
  keyvalue  := '15 ';
  keylocation := 5;

  lgth :=FREADBYKEY(filenum,target,tcount,keyvalue,keylocation);

Using the Relative Record Number


Records can also be accessed randomly using the FFINDN intrinsic. To use this intrinsic, however, you need to know the record's relative record number in its key sequence.

Using a Physical Record Number


The FREADDIR intrinsic reads a single record based on its physical record number in the file. The record number is supplied as parameter data in the intrinsic call. Record numbering starts with either 1 or 0, depending on the specifications made when the file was built.

The FPOINT and FREADC intrinsics can be used to read a record based on its physical record number. The FPOINT intrinsic positions the pointers to the record identified by its physical record number in the file. The FREADC intrinsic is then used to read the record based on the physical record pointer without reference to the record's index location.

In this case, the FREAD intrinsic could also be used to read the record, because the FPOINT intrinsic also sets the logical record pointer to the record that it located by physical record number. By default, the key used is the primary key for that record. An alternate key is used, however, if such a key was specified by a previous call to the FFINDBYKEY or FREADBYKEY intrinsic.


NOTE: This is true for the reads on the previous examples of FFINDN FFINDBYKEY, FREADBYKEY intrinsics that sets the key of reference for succeeding reads.




Sequential Access by Partial Key Value


Sequential Access in Physical Record Order