Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 7
Alternate-Key Files
Alternate-Key Files
An alternate-key file is a key-sequenced file that has a special association with a
primary file. The primary file can be a relative file, an entry-sequenced file, or another
key-sequenced file. This association allows the file system to use the records in the
alternate-key file to keep track of records in the primary file.
An alternate-key file can be opened and read or updated by itself, just like any key-
sequenced file.
Although the main purpose of an alternate-key file is to provide alternate access to
records in primary files, the ability to manipulate the alternate file on its own is
sometimes useful. For example, when all data for some application function is
contained within the alternate-key file and the primary file is large, there can be
significant performance advantage to accessing the smaller alternate-key file on its
own.
A record in any structured file can be accessed by one or more alternate keys. For
example, it might be useful for a banking application to be able to access an account
by name as well as account number. Alternate-key files provide the access
mechanism.
An alternate-key file contains a record for each valid alternate key. This record
contains three fields:
The alternate-key value.
A key specifier: a two-byte value that distinguishes among different alternate keys
in the same alternate-key file. For example, an inventory application might use
part description and supplier name as secondary keys; the key-specifier field
indicates whether a given record uses a part description or a supplier name as the
secondary key.
The primary key of the corresponding data record. For a relative file, the primary
key is the record number. For an entry-sequenced file, the primary key is the
record address. For a key-sequenced file, the primary key is the key value
embedded in the record itself.
For alternate-key files containing nonunique alternate-key values, records with like key
specifiers are always contained in the same alternate-key file. An alternate-key file
may contain more than one key specifier. In other words, all alternate keys can be
contained in the same alternate-key file, or they can be segregated according to key
type. Figure 5-4 shows several key specifiers in the same alternate-key file.
Records with unique alternate keys are always contained in the same file. They are
never kept in the same file with keys that are a different length.