Previous Topic: SORT StatementsNext Topic: Designating Control Breaks


Sorting Groups Within Groups

To sort a group within a group, include additional sort control-columns. The data is sorted according to the order in which the sort columns are specified.

Sample

For example, the SORT statement in the following sample specifies ORD-ID and SHIP-ID as the two sort columns. CA Dataquery first sorts the ORD-ID data and then sorts by SHIP-ID within each order.

    FIND 10 CAI-SLSHST-REC ROWS
        WITH SHIP-QTY > 100
      RELATED BY SLMN-ID TO CAI-ORDERS-REC
    SET NET-COST (8.2) = CAI-SLSHST-REC SHIP-QTY * UNIT-PRICE
    SET DISCOUNT (5.2) = NET-COST * DISC-PCT
    SORT CAI-ORDERS-REC BY ORD-ID AND SHIP-ID
    PRINT FROM CAI-ORDERS-REC ORD-ID
           SHIP-ID
          FROM CAI-SLSHST-REC ITM-ID
           SHIP-QTY
           UNIT-PRICE
           NET-COST
           DISCOUNT

Output

The following sample output is generated from executing the preceding query.

=> 01/02/2010 CA Dataquery PAGE 1 18:11:54 DETAIL ORD-ID SHIP-ID ITM-ID SHIP-QTY UNIT-PRICE NET-COST DISCOUNT ------ ------- ---------- -------- ---------- ------------- --------- 08811 00001 O50006 0000203 00014.75 00002994.25 00010.00 08811 00002 O70001 0000002 00010.00 00000020.00 00010.00 09012 00007 C00006 0000100 00004.00 00000400.00 00002.00 09013 00003 O50006 0000112 00100.00 00001112.00 00002.01 -------------------------------- LAST PAGE --------------------------------- <PF1> HELP <PF2> RETURN <PF3> TOTALS ONLY <PF4> DETAIL <PF5> NO TOTALS <PF6> STATS <PF7> BACKWARD <PF8> FORWARD <PF9> NOT USED <PF10> NOT USED <PF11> LEFT <PF12> RIGHT