# Data Dictionary Maintenance

Defining Keys |

A key is a string of characters that are used to identify the records in a file. Define the Primary and Alternate keys for the physical file by clicking the Define Keys button on the Data Dictionary Maintenance tool bar or by selecting File > Define Keys from the menu bar.

Primary Key

If a primary key has not yet been defined, clicking the Define Keys button will display a message, asking to define it. Respond Yes to invoke the Key Definition window, which is used to select the data fields and the sort order that will make up the primary key. Key segments can be composed of one or more strings or sub-strings.

If the key is external, select the External check box option; otherwise, the key will be considered internal. An external key can be made up of segments and can include a mixture of external-only and duplicated elements. The Unique check box option is selected by default.

Alternate Keys

Once a primary key is defined, you will be able to include up to 15 alternate keys with a total of 96 segments (FLR/VLR). EFF files can have a maximum of 255 keys and 255 segments per key.

## Key Definition

Keys that have been defined are displayed in the Key Definition list when the Define Keys option is selected on the tool bar or from the File menu.

This window consists of the following:

New Key | Invokes the Key Definition window for defining a new key.
Modify | To modify an existing key, select the key from the list and then click the Modify button, which invokes the Key Definition window for the selected key.
Delete | To remove an existing key, select the key from the list and then click the Delete button. Prior to deletion, a message will display. #### Note: Deleting a key will affect alternate keys with higher key number values, as their key numbers will be reduced by one. This will result in possible code changes where alternate keys are referenced using the KNO= clause. In addition, if the key being deleted is an external key, the replacement key will also remain external, and any fields that are defined as "external only" will become redundant. (The Delete button was added in PxPlus 2021.)
Move Up Move Down | To change the order of alternate keys, use the Move Up/Down buttons to move the selected key up or down within the Key Definition list. #### Note: The primary key will always be the first entry in the list and cannot be moved. Changing the order of the alternate keys will change the key numbers. This will result in possible code changes where alternate keys are referenced using the KNO= clause. (The Move Up/Down buttons were added in PxPlus 2023.)

The Key Definition window identifies the new or selected key in the title bar, either as a Primary Key or as an Alternate Key (displaying the Key # number/KNO).

This window consists of the following:

Data Fields | Lists the defined Data Elements for the selected file. You can select these to construct the key.
Key Segments | Lists of all the data elements that currently make up the key.
Ascending | Button used to insert the selected element from the Data Fields list into the Key Segments list. Sort order for this portion of the key is ascending.
Descending | Button used to insert the selected element from the Data Fields list into the Key Segments list. Sort order for this portion of the key is descending.
Binary Increment | Button used to define binary auto increment for the key, record-based, by the Record Offset (base 1) and Length (1, 2 or 4 bytes). Segments may be designated as swapped (same as SWP( ) type 7, Intel x86 type swapping only).
Remove | Button used to remove the selected segment from the key definition.
Key Options |
External | Select this option if the primary key is external. External keys are unique by default. They cannot have auto-increment segments or segments consisting of partial fields with offsets greater than one. #### Note: Descending sequence is not supported. Segment options are not supported.
Unique | Must be unique.
Null Key Null Character | If all characters of the key match the null character, the key is not added to the key tree. The Null Character is represented by the ASCII hexadecimal value.
Partial Field | Defines a portion of a data field (sub-string options). A separate window displays with the following options:
Field Offset | Indicates where the sub-string begins (first position offset = 1). #### Note: External keys do not support offsets greater than one.
Field Length | Number of characters in the sub-string. If Field Length = 0 (zero), the data element is read from the offset value, and all remaining characters in the data element will be used as the key segment. #### Note: The maximum key field length, including the field offset value, is 3839.
Segment Options | Sets different segment options for the selected segment. A separate window displays with the following options:
Auto Increment | Zero-filled, right-justified ASCII numeric (e.g. "0001") or space-filled, right-justified ASCII numeric (e.g. " 1"). This is for sequential numbering of records in the order that they are inserted.
Byte Swapped | Designates segments as swapped, which is the same as SWP( ) type 7 (Intel x86 type swapping only).
Case Sensitivity | Allows key segments to be stored in uppercase or lowercase.
Null Segment/Character | Definition attribute for any segment. If all characters of a segment match the null character, the key is not added to the key tree. Character is represented by ASCII hexadecimal value.
Translate | Force automatic accent translation for individual key segments (i.e. to translate accented/extended characters to their non-accented counterparts). Useful when sorting multilingual characters into a single unified sort sequence.
Signed Integer | Key segment stored as a signed binary integer.
#### Note: External keys do not support segment options.
Key Name | Used for entering a valid key name.
OK | Saves any changes and exits the Key Definition window, returning to the Key Definition list. If a new key was defined, it will be added to the bottom of the list.
Cancel | Closes the Key Definition window without saving any changes.