SORT

Generates a sorted and formatted listing of items and attributes from a specified file based on the selection criteria entered.

Syntax

SORT file-specifier {item-list} {selection-criteria} {USING file-specifier} {sort-criteria} {output-specification} {format-specification} {macro-call} {(options}

Refer to Sentence Structure for descriptions of these parameters and the standard options.

Sort sequence

The SORT processor sequences values by comparing the ASCII characters from left to right. If the field is left-aligned, the data is sequenced in ASCII collated order. For example:

01
123
21
A
ABC
BA

If the field is right-aligned and the data is numeric, a true numeric compare is performed.

If the right-aligned field is alphanumeric, data is collated in an alphanumeric sequence. For example:

   A
01
123
ABCD

Unless a different sort order is specified, the listing is arranged in an ascending order based on the item-id.

If a descending listing of item-ids is required, the BY-DSND modifier must be used. The modifier must be immediately followed by an item-id that has been set up to describe attribute 0 (item-id). For example, to sort either the GUESTS or the ROOMS file in descending order by item-id, specify: "BY-DSND ROOM."

The SORT processor retrieves multivalued attributes as they are found. To sort data in multivalued attributes, use the BY-EXP or BY-EXP-DSND modifier.

Examples

The first example shows the use of selection criteria, an output specification, a format specification, and an output option.

:SORT ROOMS WITHOUT GUEST ROOM-CODE BED-TYPE RATE HDR-SUPP (P

ROOMS Room Bed............ Rate....
      Code Type
179   S    King             72.00
186   S    King             72.00
321   DL   King             82.00
329   DL   Waterbed        104.00
600   ST   Waterbed        104.00

The same selection criterion is used with the next two examples (BILL-TOTAL > "245.00"), but in the second of them an EXPloding modifier is used to sort multivalued attribute information. Note the asterisk (*) indicating a dependent attribute.

:SORT GUESTS WITH BILL-TOTAL > "245.00" BY-DSND BILL-TOTAL NAME BILL-TOTAL HDR-SUPP

GUESTS Guest Name.......... Bill Total
535    Linda P. Evans          $281.42
411    Alyson Gallagher        $249.76
:SORT GUESTS WITH BILL-TOTAL > "245.00" BY-DSND BILL-TOTAL BY-EXP BILL-CODE BILL-CODE
BILL-AMOUNT BILL-TOTAL BILL-DESC HDR-SUPP

GUESTS Bill Amount.. Bill Total Description
       Code
            *
535       2   $98.00    $281.42 Room
535       2   $98.00    $281.42 Room
535       5    $6.65    $281.42 Lunch
535      13   $45.00    $281.42 Bar (2)
535      15   $33.77    $281.42 Telephone
411       2   $93.00    $249.76 Room
411       2   $93.00    $249.76 Room
411       4   $18.76    $249.76 Breakfast
411      10   $45.00    $249.76 Rest. (Bar)

A report can be organized to show totals and eliminate the repetition of Bill Totals by using the BREAK-ON and TOTAL connectives.

:SORT GUESTS WITH BILL-TOTAL > "245.00" BY BILL-CODE BILL-CODE BILL-AMOUNT BILL-DESC
BREAK-ON ROOM TOTAL BILL-TOTAL GRAND-TOTAL "Total:" HDR-SUPP

GUESTS Bill Amount.. Description..Room.. Bill Total
       Code
            *
411       2   $93.00  Room        411       $249.76
         10   $45.00  Rest. (Bar)
          2   $93.00  Room
          4   $18.76  Breakfast
                                   ***      $249.76
535       2   $98.00  Room        535       $281.42
         13   $45.00  Bar (2)
         15   $33.77  Telephone
          2   $98.00  Room
          5    $6.65  Lunch
                                   ***      $281.42
Total:                                      $531.18