ORDER BY (sort selected records)


ORDER BY sorts variables into a different order from that presented by the SELECT verb.

If the report is to be in chronological order, you do not need to sort your data because all of the records are time stamped with CMRDATE and CMRTIME. Occasionally, you might want to arrange the report by transaction code or by response time. This order is useful if you are interested in summaries based on a group of transactions, a range of execution periods, or other similar information.

The ORDER BY statement relies upon the IBM Sort Facility to pass user data to a sort exit as the second parameter in the list. Other sort facilities can be used if they are compatible with the IBM Sort Facility (use standard sort exits E15 and E35).

The ORDER BY statement can be overridden with your own sort control statement, such as the following:

//SORTCNTL DD *
 options - -
/*

Syntax

ORDER BY v1 v2 v3 v4 [IN DESCENDING SEQUENCE]

Usage

  • Only one ORDER BY statement is allowed per report set.
  • Specify 1 to 4 variables with ORDER BY. They can be either user-defined or predefined variables.
  • ORDER statement with more than 1 variable must specify the same fields, placed in the same order, with the USING statement right after the word USING
  • IN DESCENDING SEQUENCE orders the data from high to low values. The default is ascending order.

Examples

SELECT TYPE 6E RECORDS FROM CMRDETL
USING T6ETRID -
      T6ERESP -
      T6ECPUR -
      T6EFCWT -
      T6ESHWM -
      T6EPAGCT
ORDER BY T6ETRID
SUMMARY
REPORT
END
SELECT TYPE 6E RECORDS FROM CMRDETL
USING T6ETRID -
      T6ERESP -
      T6ECPUR -
      T6EFCWT -
      T6ESHWM -
      T6EPAGCT
ORDER BY T6ETRID T6ERESP
SUMMARY
REPORT
END


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*