Key Clause

The key clause identifies the key or keys of the Access.

All key items must be data items or group items in the data set referenced by the Access. When multiple key items appear, the key items are listed from left to right in order of significance. The leftmost key item is the major key.

When group key items contain signed numeric or real items, the set cannot necessarily be ordered ascending by key. Normalization or transformation is not performed on signed numeric and real items that are within group items because group items are aligned on an 8-bit byte boundary. To ensure correct ordering for sets, change the group key to a multiple key item.

When group keys contain alpha items or numeric items, the set can contain some extra padded digits if the numeric items are not byte-aligned. To ensure no extra padded digits are in the set, use multiple key items rather than a group item key, or make all numeric items within the group byte-aligned.

The following restrictions apply to key items:

 
  • Signed numeric items that are used as keys must have a precision of 22 or less; unsigned numeric items must have a precision of 23 or less. The scale factor must not exceed the precision of 11.

  • Items which use the OCCURS, SIZE, or STORED options cannot be used as keys.

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

  • Key items are automatically required for automatic subset.

  • The key for an Access to a direct data set must be a single unsigned numeric item not exceeding 11 digits, or a single group item with subitems of the form NUMBER(n) not exceeding 11 digits in total. The numeric item declaration must not specify a null value.

The ASCENDING and DESCENDING options can be specified only for Accesses to ordered data sets. When the ASCENDING option is used, records with low key values precede records with high key values. When the DESCENDING option is used, records with high key values precede records with low key values. If neither the ASCENDING nor DESCENDING option is specified, an ascending order is assumed.