Key Data Option

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

When the key data option is declared, each entry in the subset is extended to include a copy of the specified data items and group items. Application programs can access key data items directly from the subset using the host language statement FIND KEY OF. This statement locates the specified subset entry, and then moves the key and key data items from the subset 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 option is useful because it eliminates the need to perform an I/O operation on the data set.

The key data information in automatic subsets 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 subset.

The key data information in manual subsets is not maintained by the system. When a user program changes a key data item in the data set, it must delete the corresponding entry from the manual subset and insert it.

If several subsets 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 subsets, a copy of the item is kept with each subset.

The following DASDL description illustrates the use of the key data option:

BOOKS COMPACT DATA SET
 (
  TITLE         ALPHA(20);
  AUTHOR        ALPHA(20);
  SUBJECT       ALPHA (20);
  DESC          ALPHA(500) SIZE VARYING;
  CHECKED-OUT   BOOLEAN;
 );
BY-AUTHOR SUBSET OF BOOKS
  WHERE NOT CHECKED-OUT
  KEY IS AUTHOR,
  DATA (SUBJECT,TITLE);
BY-SUBJECT SUBSET OF BOOKS
  WHERE NOT CHECKED-OUT
  KEY IS SUBJECT,
  DATA (AUTHOR,TITLE);

The following restrictions apply to key data items:

  • All key data items must be declared in the data set referenced by the subset; they cannot appear in the subset 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.