Mentor SAP

Aggregate Expressions

 

 

An aggregate expression calculates a single value from an operand by calling an aggregate function for multiple rows of a result set. An aggregate expression can be used in the field list of a SELECT statement or in a HAVING clause.

 

Regarding the result type, the following rules apply:

 

Usually, an operand is a column or field in the data source of the current CDS view. Other options for operand are:

 

 

The example above shows one example for each aggregate function. The last two elements of the field list are examples of alternative operands.

 

 

Addition GROUP BY groups those rows in the result set that have the same content in the elements specified by the field field1, field2,…as a single row. The fields must be specified using the same names as the fields in the data source.

 

Any elements of the CDS view that is not specified after GROUP BY must be defined in the SELECT list using aggregate expressions. Conversely, GROUP BY must be used if aggregate expressions are contained in the SELECT list and all elements not defined using aggregate must be specified after GROUP BY. Literals and other expressions cannot be specified after GROUP BY. If expressions or calls of predefined functions are specified as elements of the SELECT list using aggregate expressions, all the fields used must be specified in the GROUP clause.

 

Restriction in ABAP CDS

In CDS, several restrictions apply for the usage of aggregate functions.