SORT-MERGE/XL General User's Guide (32650-90883)

88 Chapter6
SORT-MERGE/XL Commands
KEY
be contiguous or separated in a record or they can overlap each other, provided the
collating sequence is not altered, or a user-defined sequence is not used. An entire record
can be considered as a single key.
As explained in Chapter 3, each >KEY command can specify one or more key fields which
are separated by semicolons. Multiple key fields can also be specified with more than one
>KEY command. All the key fields do not have to be specified in the same command. The
most significant key is called the major key and is declared first in the command. Other
keys have decreasing significance according to their relative positions following the major
key. They are compared if a comparison or more significant keys results in an equal
condition.
Consider a file containing the records of all the students in a high school. Each record can
contain information such as name, address, grade level, grades in individual courses, as
well as data on other information. You can specify the order in which the records are
sorted. If the first record is of the student with the highest grades (A) in English and Math,
you specify an ascending order. If the major key is English and the other key is Math, the
data in the Math fields are compared only if the data in the English fields are the same.
The sorting order is specified in the same commands that specify the keys. An order is
declared for each key. This order does not have to be the same for all the keys in a record.
For example, in the high school file, you can declare English (major key) with an ascending
order and Math with a descending order. Note even if the sorting order is different for each
key, only one collating sequence is used for a particular operation.
EXAMPLES
The following examples show using the >KEY command and some of its options:
>KEY 10, 5
BYTE key of length 5 starting in position 10, sorted in the ascending order.
>KEY 20, REAL
REAL key of length 4, starting in position 20 and sorted in an ascending order since four is
the default for the
length
parameter when the key data type is REAL.
>KEY 30, 20, INT, DESC
20-byte integer key starting in position 30, and sorted in a descending order.
For information on making corrections to the key specification, refer to the >RESET
command in this chapter.
ADDITIONAL DISCUSSION
Refer to the >RESET command in this chapter.