Using Key Definitions

Key definitions can be very simple or very complex. Key definition elements and functions may be used freely together and within each other.

For example, if you wish to create a key definition that is sorted on a portion of the item-ID, use a group extract function to create the key as in:

OCONV(0,’G2*1’)

Multiple BY clauses may be used to create exploding keys. For example, to create a key by company name, individual last name, then individual first name, you could use a key definition of:

BY 3 BY 2 BY 1

In a similar fashion, you could create a key by account balance in descending order followed by customer name as:

BY-DR 4 BY 3

This causes the account balance to sort in descending right-justified order, followed by customer name in ascending left-justified order.

BTREE KEYFILES

The actual BTREE key structure is stored in duplicate data portions that must be created after the key file is defined. To create this file for a CUSTOMERS file, type:

CREATE-KEYFILE CUSTOMERS 37

This creates the BTREE file with a modulo of 37. For a system with 2048 byte frames, a customer file with only a single key that is 20 character long, and 5 character long item-ids, this modulo would be a good choice for a file with about 2600 items. Alternately, you could simply type:

CREATE-KEYFILE CUSTOMERS

CREATE-KEYFILE then prompts you for the number of items that are to be indexed. The number entered, along with the average key size (which is a part of the key definitions), is used to calculate an appropriate file modulo. The CREATE-KEYFILE command creates the key data file with the specified modulo.

The CREATE-KEYFILE command will not function if:

The CREATE-KEYFILE command will also automatically rebuild the keys for the data file after the file has been created.

To delete an existing key file type:

DELETE-KEYFILE filename

The above command:

See Also

Defining Key Structures

Activating the BTREE Key Definition Program

Displaying and Printing Key Structures

Entering Key Definitions

Saving and Compiling Key Definitions

Suppressing Automatic Uppercase in Keys

Key ICONV Functions

Key Browse Column Definitions

Algebraic Expressions