Specification File Qualifier Identifies key field names, specifies sorting order, and changes the order of records in the output file. Formats /KEY=field-name /KEY=(field-name,order) /KEY=([IF condition-name THEN value ELSE]...value [,order])
1 – Qualifier Values
field-name Specifies the name of the key field. The field-name has been previously specified in a /FIELD qualifier. order Specifies the order of the sort. The ASCENDING option specifies ascending order for a sort or merge operation. This option is the default. The DESCENDING option specifies descending order for a sort or merge operation. value Specifies the key. The value can be a constant or a field-name that has been defined in a /FIELD qualifier.
2 – Full Description
If you are sorting on the entire record using character data, you do not need to specify your key field. Otherwise, specify a /KEY qualifier for each of the keys, in the order of their priority. You can sort on as many as 255 key fields. There are three ways to use the /KEY qualifier: o To identify the key field name. o To identify the key field name and to specify sorting order. In this case, enclose the field name and the order option in parentheses. o As a conditional qualifier, to change the order of records in the output file. First, specify a condition name in a /CONDITION qualifier, and set up a test for what meets that condition. Then, specify the relative order in a /KEY qualifier of the form: /KEY=(IF condition-name THEN value ELSE value) You can use any values to specify the relative order of the records.
3 – Examples
1./FIELD=(NAME=SALARY,POSITION:10,DIGITS:8,DECIMAL) /KEY=(SALARY,DESCENDING) This /KEY qualifier specifies that the key field is SALARY and that the sorting order is descending. 2./FIELD=(NAME=ZIP,POSITION:20,SIZE:6) /CONDITION=(NAME=LOCATION, TEST=(ZIP EQ "01863")) /KEY=(IF LOCATION THEN 1 ELSE 2) In this example, all the records with the zip code 01863 are to appear at the beginning of the sorted output file. The conditional test LOCATION (defined in a /CONDITION qualifier) is on the ZIP field (named in a /FIELD clause). The values of 1 and 2 in this /KEY clause signify a relative order for those records that satisfy the condition and those that do not.