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

Chapter 2 21
Getting Started With SORT-MERGE/XL
Key Data Items
Figure 2-3. Numerical Sort By Social Security Number
NOTE
All entries in a file to be sorted for a key data item must start in exactly the
same column. In Figure 2-1. all last names start in column 1 and the number
of characters must not extend into the next data item field. Therefore, if Boris
Tscherbakhanovski were added to the list of last names in Figure 2-1. his last
name would have to be shortened to Tscherbak so it would not extend into the
next key data item field containing first names. If you want to merge this file
with other files, the key data items in all files must be located in exactly the
same position and have the same data format.
Sorting Files By Multiple Key Data Items
SORT-MERGE/XL allows you to specify more than one key within a record for sort or
merge purposes. For example, the data in Figure 2-1. can be arranged according to four
different key data items (last name, first name, occupation, or social security number). The
command to specify the last name as the single key data item to be sorted is:
>KEY 1, 9
This specifies that the key data item to be sorted begins in character position (column) 1
and is 9 characters (columns) long. The result of a sort done using the command >KEY 1, 9
is shown in Figure 2-2..
The command to specify a multiple key data item sort with the last name as the major key
data item, and the first name as the second key data item, is:
>KEY 1, 9; 10, 14
This specifies that the major key data item to be sorted is located in character position
(column) 1 and is 9 characters long; the second key data item begins at character position
10 and is 14 characters long.
If there were two identical last names, the sort program would look to the second key data
item to break the tie. Multiple >KEY commands may be entered one to a line, or all on one
line, each separated by a semicolon:
>KEY 1, 9
>KEY 10, 14
>KEY 25, 15
Or:
1 2 3 4
1234567890123456789012345678901234567890123456789
SOUSE EGBERT DETECTIVE 123234454
WELBY MARCUS PHYSICIAN 242244444
JONES SMOKEY TRUCKER 333887777