Sort Command [SO]. Robelle Suprtool 5.7
Annonce
Annonce
Sort Command [SO]
Specifies the next sort key via an IMAGE field name, or a field in a self-describing file, or a Defined field. See "Key Command [K]" on page 216 for sort keys specified by explicit byte position. Up to 20 Sort and Key commands can be specified per extract task. The first key entered is the major sort key.
SORT field [(subscript)] [DESCENDING]
(Default: Ascending order)
Field
The field specified must be an IMAGE data item that is a field of the input source, or a defined field, or a field from a self-describing file.
Subscript
If the field is a compound item (e.g., 2X25), the first sub-item is the default if no
subscript is specified. You can sort on any sub-item by specifying the subscript. For example,
>sort address(2) {sorts on 2nd sub-item}
Descending vs. Ascending Order
By default, sorts are done in ascending order. Descending specifies that the field is to be sorted in descending order.
Examples
The most common use of the Sort command is to specify a sort field of a database field. You may use the Key command to specify all sorts. We recommend that the
Sort command be used wherever possible. If the structure of your database changes, your Suprtool tasks still work if sort fields are specified with the Sort command:
>base store,5
>get d-sales {input from an IMAGE dataset}
>sort cust-account {primary sort field}
>sort purch-date,desc {newest transactions first}
>output dsales {write the sorted records to an MPE disc file}
>exit
In the next example we sort an MPE file. We create a field using the Define command. Rather than using the Key command, we use the Sort command to specify the sort field. If the MPE file changes, only the Define command must be changed:
>input dinvent {input is from an MPE file}
>define a,11,2,int {"A" is an integer that starts}
>output outfile { at the 11th byte of Dinvent}
>sort a {sort the input records by the "A" field}
>exit
With the =dataset form of the Input command, we can have even greater flexibility to use the Sort command. We assume that the MPE file Mcust has the same structure as the m-customer dataset. We sort the file using the first of the two street addresses in m-customer:
268 • Suprtool 5.7 for MPE
Suprtool Commands
Suprtool Commands
>base store,5,READER {open for read access only}
>input mcust=m-customer {same format as m-customer}
>sort street-address {a repeated field, but only}
>exit { the first address is used}
Notes
The Verify command shows all of the current Sort command values and the Reset command cancels them. If you have not defined any sort fields before the Xeq or
Exit command, Suprtool performs a copy only, no sort.
It is important to note that if the field being sorted is the result of a $function, then you may not be sorting on the value of the field after the function has transformed the field. For example the following task may not give you the result you expect:
>base store,5
>get d-sales
>def cust-accountx,1,6,byte
>ext cust-accountx = $edit(cust-accout,"zzzz99"
>sort cust-accountx {sorting on transformed field before it has value from function}
>dup none keys
>output dsales
>exit
In this instance you will not be sorting on cust-accountx as transformed by the $edit function, but rather the first six bytes of d-sales. Therefore it is important to note when you are using extract to transform a field, you will not be sorting on that transformed value.
Therefore the way to do the transformation would be to either divide into two tasks or if you can logically sort on the field before the transformation in order to achieve the result, so the task could be:
>base store,5
>get d-sales
>def cust-accountx,1,6,byte
>ext cust-accountx = $edit(cust-accout,"zzzz99"
>sort cust-account {Note sorting on source field}
>dup none keys
>output dsales
>exit or if two tasks are necessary:
>base store,5
>get d-sales
>def cust-accountx,1,6,byte
>ext cust-accountx = $edit(cust-accout,"zzzz99"
>output tempsales
>xeq
>in tempsales
>sort cust-acctx
>dup none keys
>output dsales
>exit
Suprtool 5.7 for MPE• 269
Download
Annonce