Entering content frame

ORDER Clause (order_clause) Locate the document in its SAP Library structure

The ORDER clause specifies a sort sequence for a result table (see result table name).

Syntax

<order_clause> ::= ORDER BY <sort_spec>,...

<sort_spec> ::= <unsigned_integer> [ASC | DESC] | <expression> [ASC | DESC]

unsigned_integer, expression

Explanation

The sort columns specified in the order clause determine the sequence of the sort criteria.

A number n specified in the sorting specification (sort_spec) identifies the nth column in the result table. n must be less than or equal to the number of columns in the result table.

Scalable subqueries are not permissible in an ORDER clause.

ASC/DESC

ASC: the values are sorted in ascending order.

DESC: the values are sorted in descending order.

The default setting is ASC.

Further information

If a QUERY expression consists of more than one QUERY specification, sort specifications must be specified in the form <unsigned_integer> [ASC | DESC].

If a query specification was specified with DISTINCT, the total of the internal lengths of all sorting columns must not exceed 1016 characters; otherwise it can comprise 1020 characters.

Column names in the sort specifications must be columns in the tables of the FROM clause or a result_column_name in the selected columns of the QUERY specification.

If DISTINCT or a set function in a selected column was used, the sort specification must identify a column in the result table.

Values are compared in accordance with the rules for the comparison predicate. For sorting purposes, NULL values are greater than non-NULL values, and special NULL values are greater than non-NULL values but less than NULL values.

See also:

Restrictions

Leaving content frame