Enscribe Programmer's Guide
For key-sequenced files and any of their partitions, you can change the MAXEXTENTS value
dynamically during program execution using either the SETMODE 92 system procedure or the FUP
ALTER command.
Primary Keys
For key-sequenced files, you must define both the offset from the beginning of the record where
the primary-key field begins and the length of the key field. A few things to consider when choosing
the offset of the primary-key field are:
• The primary-key field can begin at any offset within a record and can be of any length up to
2048:
$min(record-length minus offset, 2048)
• If you will be using key compression in data blocks, the primary-key field must reside at the
very beginning of the record.
• If the primary-key field is the final field in the record, it can be of variable length.
• If the key field is to be treated as a data type other than STRING, the offset should be
chosen so that the field begins on a word boundary.
Note that the collating sequence by which the records within a key-sequenced file are arranged
is by ASCII code (actually unsigned binary). Consequently, if the data type of the key field is binary,
the presence of the sign bit will cause negative values to be treated as being greater than positive
values.
Key Compression
When creating a file, you can specify that the keys be compressed in data and/or index blocks.
The Enscribe software compresses keys by eliminating leading characters that are duplicated from
one key to the next and replacing them with a 1-byte count of the duplicate characters. For example,
if these three records are inserted into a file with data compression enabled:
JONES, JANE
JONES, JOHN
JONES, SAM
what is actually written to the disk is:
0JONES, JANE
8OHN
7SAM
where the first character (0, 8, and 7, respectively) indicates the number of leading characters
that are identical to those of the primary key in the immediately preceding record.
When you are creating a file by using FUP, the DCOMPRESS, ICOMPRESS, and COMPRESS
parameters of the SET command designate whether key compression is to be applied to the data
blocks, the index blocks, or both. When you are creating a file by using the FILE_CREATE_
procedure, bits 11 and 12 of the options parameter designate what type of key compression, if
any, is to be used. If you use the FILE_CREATELIST_ procedure, item codes 68 and 69 designate
key compression.
When deciding whether or not to use key compression, consider these:
• Key compression can require one additional byte per record. Moreover, key compression will
always require additional system processing to expand the compressed records.
• Key compression requires that the primary-key field begin at offset [0] of each record.
Consequently, you cannot use variable-length primary keys unless the entire record is the
primary-key field.
• If there is considerable similarity among the records' primary-key values, then key compression
in data blocks is desirable.
Creating Key-Sequenced Files 75