Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 47
Using Key-Sequenced Files
Using Key-Sequenced Files
This subsection discusses the way the programmatic interface to key-sequenced files
differs from that of the other structured file types. Specifically, it discusses how to
create and access a key-sequenced file. At the end of the subsection is a working
example of a program that uses a key-sequenced file.
The discussion here is limited to primary-key access. Alternate keys are discussed
later under the heading Using Alternate Keys.
Creating Key-Sequenced Files
You can create a key-sequenced file either interactively using the FUP CREATE
command or programmatically using the FILE_CREATE[LIST]_ procedure. In either
case, you need to supply information about how to build the file, such as the following:
The file-type parameter must be set to 3 to specify a key-sequenced file.
Key compression and compaction can also be specified on file creation. These
features are used to eliminate leading or trailing parts of similar keys to save
space. For details, see the Enscribe Programmers Guide.
The block size is the number of bytes that are transferred between the disk and the
disk process. The block size can be 512, 1024, 2048, or 4096 bytes (including a
few bytes of overhead). Records cannot span blocks, therefore the block size
must be at least large enough to contain one record plus the overhead. A block
usually contains multiple records.
The maximum record length must be set to some value within the limits imposed
by the block size.
The key length specifies the number of bytes in the primary key.
The key offset is the number of bytes into a record where the primary key starts.
The default offset is zero, the first field in the record.