Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 88
Using Alternate Keys With a Relative File
The GET^DATE procedure has been added to prompt the user for the date and
check its length.
The READ^RECORD procedure is modified as follows:
The procedure prompts the user for a date instead of a record number.
The procedure positions the pointers using the KEYPOSITION procedure
(instead of POSITION). KEYPOSITION uses the alternate key to position the
pointers. It also uses approximate positioning mode to accept a key value that
does not exist. This is a useful feature, for example, if the user wants to read
the log for the month of April and there was no entry for April 1.
Positioning by alternate key also causes sequential reads to be done in
alternate-key sequence rather than by record number.
The UPDATE^RECORD procedure also prompts the user for a date and then
positions the pointers using this date and the KEYPOSITION procedure. Here, the
positioning mode is exact. If there is no such key, then the procedure displays “No
such record” and returns to the LOGGER procedure.
The INSERT^RECORD procedure replaces the APPEND^RECORD procedure. It
works like APPEND^RECORD, except that it prompts the user separately for the
date and comments. Note that positioning is still done using the POSITION
procedure, because the program simply adds records to the end of the file.
The LOGGER procedure does not change. The alternate-key file is automatically
opened when the corresponding data file is opened. Therefore there is no need for
a separate open.
The following complete program applies alternate keys to a relative file.