User`s guide

BDOS FUNCTION 36: SET RANDOM RECORD
Entry Parameters:
Registers C: 24H
DE: FCB Address
Returned Value: Random Record Field Set
The Set Random Record function returns the random record number of the next
record to be accessed from a file that has been read or written sequentially to a
particular point. This value is returned in the random record field, bytes rO, rl, and
r2, of the FCB addressed by the register pair DE. Function 36 can be useful in two
ways,
First, it is often necessary to initially read and scan a sequential file to extract the
positions of various key fields. As each key is encountered, Function 36 is called to
compute the random record position for the data corresponding to this key. If the
data unit size is 128 bytes, the resulting record number minus one is placed into a
table with the key for later retrieval. After scanning the entire file and tabularizing
the keys and their record numbers, you can move directly to a particular record by
performing a random read using the corresponding random record number that you
saved earlier. The scheme is easily generalized when variable record lengths are involved,
because the program need only store the buffer-relative byte position along with the
key and record number to find the exact starting position of the keyed data at a later
time.
A second use of Function 36 occurs when switching from a sequential read or
write over to random read or write. A file is sequentially accessed to a particular
point in the file, then Function 36 is called to set the record number, and subsequent
random read and write operations continue from the next record in the file.
3-55
BDOS Function Calls CP/M 3 Programmers Guide