SAP SQL EXPR IN AGGREGATES ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_SQLAGG - Use in Aggregate Expressions
This example demonstrates SQL expressions as an argument of aggregate functions.

ABAP_SOURCE_CODE
DEMO CL_DEMO_SQL_EXPR_IN_AGGREGATES

ABAP_DESCRIPTION
The DDIC database table DEMO_EXPRESSIONS is filled with random values in the static constructor.
The first SELECT statement reads the filled columns individually. Here, the total and the product of the numeric columns NUM1 and NUM2 are calculated using arithmetic statements in the SELECT list.
The second SELECT statement performs a grouping by the columns CHAR1 and CHAR2. For each group, aggregate functions are used to determine aggregated values whose arguments are arithmetic expressions
The third SELECT statement performs the same grouping as the second SELECT statement, but restricts the selected groups using a HAVING clause in which a condition is set on an aggregate expression that has an arithmetic expression as an argument.
See also the executable example for using aggregate expressions in SQL expressions. Here, the roles of the expressions are switched, and different results are produced.