 |
» |
|
|
 |
The >KEY command specifies the location of the key data
items in a file's records which are to be sorted or merged. SYNTAX |  |
>K[EY] keyspec1 [; keyspec2]...[; keyspecN] |
PARAMETERS |  |
| keyspec | A group of
parameters used to specify a key data item to be sorted or merged.
The syntax of the keyspec parameters follows: position, length [,type][,DESC] |
| | position | A positive number
(integer) specifying the position of the first character of the
key data item within the record. (The first position of a record
line is numbered one.) | | length | A positive number
(integer) indicating the length of the data item key field in bytes. | | type | Defines the type
of data contained in the data item key field. The type of data can
be one of the following: | | B[YTE] | A direct byte comparison
is used. It is the default value for the type parameter and should be used for ASCII or EBCDIC
data. The specification of an alternate collating sequence via the >DATA and >ALTSEQ commands affects the collating of this key type
only. | | C[HARACTER] | The collating sequence
for the native language defined in the >LANGUAGE command is used. If no >LANGUAGE command has been issued, SORT/XL and MERGE/XL
use the default data language of the system (usually ASCII). Refer
to the Native Language Programmer's Guide for
additional information on the default data language. | | I[NTEGER] | The key data item
field contains a two's complement number of the specified length
in bytes. Any value may be specified for length. The length parameter defaults to two bytes. | | R[EAL] | The key data item
field contains a floating-point number in standard HP 3000 format.
Any value may be entered for length. The length parameter defaults to four bytes. | | L[ONG] | LONG is the same as REAL except that length defaults to eight bytes. | | F[POINT] | The key data item field contains
a floating-point number in IEEE standard format. The length parameter defaults to four bytes. Any value may be
entered for length. |
 |  |  |  |  | NOTE: NANs (Not A Number) will collate at the beginning or
end for IEEE floating-point numbers. The method of reporting (or
ignoring) these entities has not been determined. |  |  |  |  |
| F8[POINT] | Same as FPOINT except that length defaults to eight bytes. | | F16[POINT] | Same as FPOINT except that length defaults to sixteen bytes. | | T[WO-BYTE] | Key data item field
contains 16-bit data. The length specified for this key type must be an even number
of bytes. | | P[ACKED] | Key data item field
contains a packed decimal number. In this format, each character
except the last contains two digits. Each digit occupies four bits.
The rightmost character contains the least significant digit of the
number in its four leftmost bits, and the sign of the number in
its four rightmost bits. The sign is considered minus if it has
the value 1101 (binary) and plus otherwise. | | PACKED* | Same as PACKED except there are an even number of digits and
a sign. The leftmost four bits are not treated as part of the field. | DI[SPLAY- TRAILING-SIGN] | Key field contains
a numeric display quantity. Numeric display items are represented
by ASCII-coded decimal digits (0 through 9) except for the rightmost
digit, which carries the sign of the data item. The sign is determined
according to the table shown in Figure 6-1. (Sign is optional.)
For example, 123 is represented by 12C. | | DISPLAY-L[EADING-SIGN] | In this case, the
leftmost digit carries the sign of the data item. For example, -123 is represented by J23. Refer to the table shown in Figure 6-1. (Sign
is optional.) | | DISPLAY-TRAILING-SIGN-S[EPARATE] | The sign is contained
in the character position to the right of the rightmost digit. For
example, 123 is represented by 123+. (Sign can be blank.) | DISPLAY-LEADING- SIGN-S[EPARATE] | The sign is contained
in the character position to the left of the leftmost digit. For
example, -123 is represented by -123. (Sign can be blank.) | | DESC | Indicates the records are to
be arranged in descending order. If this parameter is not specified,
the records are arranged in the default ascending order. |
 |
Display Digit Positive Negative No Sign 0 { (%173) } (%175) 0 (%60) 1 A (%101) J (%112) 1 (%61) 2 B (%102) K (%113) 2 (%62) 3 C (%103) L (%114) 3 (%63) 4 D (%104) M (%115) 4 (%64) 5 E (%105) N (%116) 5 (%65) 6 F (%106) O (%117) 6 (%66) 7 G (%107) P (%120) 7 (%67) 8 H (%110) Q (%121) 8 (%70) 9 I (%111) R (%122) 9 (&71) |
DISCUSSION |  |
SORT-MERGE/XL sorts keys contain binary, ASCII, or EBCDIC
data according to an eight-bit binary sequence (00000000 to 11111111),
except for the type CHARACTER, which is sorted according to the collating sequence
of the native language specified in the >LANGUAGE command. Refer to Appendix C for further information
on native language collating. Other types of data (integer, real,
etc.) are sorted according to the standard arithmetic relational
operators. For example, 2 is greater than -5. The keys can contain alphabetic,
numeric, or alphanumeric (alphabetic and numeric intermixed) data.
They can 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: BYTE key of length 5 starting in position 10, sorted
in the ascending order. 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. 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.
|