Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic


Read the last data record in the set defined by a target.

Short Name



ISAM function


COUNT LastInSet(FILNO keyno, pVOID target, pVOID recptr, COUNT siglen)


In V12 the file number typedef was formally changed from COUNT, a two-byte value to FILNO, a four-byte value. Refer to this link for compatibility details. Four Byte File Numbering

LastInSet() reads the last data record in the set of data records whose keys match the target key in the first siglen bytes. If successful, this record becomes the current ISAM record for the associated data file. A successful LastInSet() defines a current key value set, and subsequent calls to NextInSet() and PreviousInSet() will read the other records in the set (i.e., those records whose keys also match the last siglen bytes of target). If an error occurs or no key value matches the target, the current ISAM record is not updated, and no key value set is defined.

If the data file has variable-length records, only the fixed-length portion, defined by dreclen in the original call to CreateIFile(), is actually read into the buffer pointed to by recptr. If you wish to read the entire variable-length record into the same or a different buffer, issue a call to ReReadVRecord() after the call to LastInSet(). Note that ReReadVRecord() requires the size of the buffer area so that it can check if sufficient space is available.

The target buffer must be initialized to the full length of the key to avoid memory corruption when the target is transformed to match the key.

LastInSet() can be used to perform an equality search for duplicate keys. Set target to the key value of interest, and set siglen to the key length less the 4 bytes of the suffix.

Notice that you do not directly identify the data file number involved. The ISAM parameter file described in ISAM Functions (ISAM Database Technology, /doc/ctreeplus/30841.htm) of the c-tree Programmer’s Reference Guide contains the correspondence between the index file number and the associated data file.



Symbolic Constant




Successful retrieval of current ISAM record.



recptr is NULL. No data file read performed.



Could not get lock on data record. No data file read performed.



No active entries.



keyno must reference a non-numeric key type.

See c-tree Error Codes for a complete listing of valid c-tree error values.


FILNO keyfil;

TEXT target[24], recbuf[320];

printf("\nEnter set value:");

scanf("%23s", target);

LastInSet(keyfil, TransformKey(keyfil,target), recbuf,


while (isam_err == NO_ERROR) {


PreviousInSet(keyfil, recbuf);



No check is made to determine if recptr points to a region sufficiently large to accept a data record. If the area is too small, either code or data will be clobbered.

See also

NextInSet(), PreviousInSet(), FirstInSet(), PositionSet(), ChangeSet(), CreateIFile(),
ReReadVRecord(), TransformKey()