Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 86
Using Alternate Keys With a Relative File
Using Alternate Keys With a Relative File
Alternate keys used with a relative file reference a record number. As with any
alternate-key mechanism, each occurrence of an alternate key references a primary
key. Recall that for relative files, the primary key is the record number.
The log-file programming example from the subsection Using Relative Files will be
enhanced to show how alternate keys can be used with relative files. The old example
used a record to contain comments entered by the user. Here, two fields are added to
the record structure so that one field can contain the user's comments, on the date,
and a third field contains the length of the comments in bytes:
The date field serves as the alternate key, enabling the user to look up information in
the log using the date. DA” will be used for the key specifier, short for “date.” The
alternate-key and primary-key files look something like the example shown in
Figure 5-9.
Figure 5-9. Example of Alternate-Key File for Use With a Relative File
VST028.VSD
VST029.VSD