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

//SORTCNTL DD *
 options - -
/*

Syntax

ORDER BY v1 [IN DESCENDING SEQUENCE]

Usage

  • Only one ORDER BY statement is allowed per report set.
  • Only one variable can be specified with ORDER BY. It can be either a user-defined or predefined variable.
  • If DETAIL or SUMMARY is used, the ORDER BY variable must be the same as the first variable in the USING statement, as shown below.
  • IN DESCENDING SEQUENCE orders the data from high to low values.

Example

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



 

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