Key Data Option

The key data is used to reduce the time required to access frequently used items.

When key data is declared, each entry in the set is extended to include a copy of the specified data items and group items. Application programs can access key data items directly from the set using the host language statement FIND KEY OF. This statement locates the specified set entry, and then moves the key and key data items from the set to the user work area. The data set record is not retrieved; consequently, items which are not keys or key data have undefined values. The key data is useful because it eliminates the need to perform an I/O operation on the data set.

The key data information is maintained by the system. When a user program changes a record in the data set, the system automatically makes any needed changes to the data stored in the set.

If several sets exist for a data set, any or all of them can include key data. When the same item appears as a key data item in two or more sets, a separate copy of the item is kept with each set.

The following example illustrates the key data option:

CUSTOMERS DATA SET
 (
  ACCT-NO       NUMBER(6);
  NAME          ALPHA(20);
  CREDIT-LIMIT  NUMBER(S9,2);
  ACCT-BAL      NUMBER(S9,2);
 );
BY-NAME SET OF CUSTOMERS
   KEY IS NAME,
   DATA ACCT-BAL;
BY-ACCT-NO SET OF CUSTOMERS
   KEY IS ACCT-NO,
   DATA (ACCT-BAL,CREDIT-LIMIT);

The following restrictions apply to key data items:

  • All key data items must be declared in the data set referenced by the set; they cannot appear in the set alone.

  • Signed numeric data items must have a precision of 22 or less, and unsigned numeric data items must have a precision of 23 or less. The scale factor must not exceed the precision or 11.

  • Occurring items cannot be named as key data items, but they can be contained in groups which are key data items.

  • Items which use the SIZE or STORED option cannot be key data items.

  • Key data items within variable-format records must be contained in the fixed part of the record.

  • Key items must not be named as key data items.

  • The maximum character length for one key data field is 2047.

  • An item specified with the DATAENCRYPT option cannot be used as key data. If the last key item in the key clause is encrypted, the key data will be aligned on the next word boundary.