Enscribe Programmer's Guide
Here are two reasons why you do not want to have separate alternate-key files:
• System control-block space is allocated for each opening of an alternate-key file (that is, each
opening of the primary file).
• A file control block (FCB) is allocated for the first opening of an alternate-key file.
Figure 10 (page 35) illustrates the record structure of an alternate-key file. The length of a record
in an alternate-key file is:
2 bytes for the key-specifier
+ the key-length of the longest alternate key included in
the record
+ the key-length of the associated primary key
The user defines the data file’s primary key length if the data file is key sequenced. If it is a relative
or entry sequenced data file, then its primary key length is 4 if it is format 1 or 8 if it is format 2.
Figure 10 Record Structure of an Alternate-Key File
Key Specifier
(two bytes)
Alternate
Key
Data File's
Primary Key
Note that if the primary-key file is audited, the alternate-key files also must be audited, unless keys
are not automatically being updated. The primary-key length of an alternate-key file, as distinguished
from the data file's primary key, depends on whether the file contains unique key references. With
nonunique key references, the file's primary key is the entire record, so its primary-key length is
the same as its record length.
If an alternate-key file contains a single, nonunique key, that key can be no longer than
2048 (maximum key-length of the alternate-key file for
key-sequenced files with increased limits)
- 2 for the key-specifier
- the key-length of the data file's primary key
Thus, if a data file's primary key is 33 bytes long, nonunique alternate keys within that file cannot
be more than 2048 - 2 - 33 = 2013 bytes long. If the alternate-key file contains unique key
references, its primary key is the key specifier and the unique key. Therefore, the primary-key length
is:
2 for the key-specifier
+ key-length of the unique alternate-key field
Thus, a unique alternate key can be as long as 2048 - 2 = 2046 bytes, regardless of the data
file's primary key.
Alternate Keys and Record Locking
There are important considerations for alternate key locking particularly when aborting transactions.
This section describes Enscribe’s handling of record locks for alternate key files and assumes a
typical scenario in which an application opens a primary file and Enscribe internally opens the
primary file’s alternate key files but does not make those internal opens available to the application.
Alternate Keys 35