SAP CDS HAVING CLAUSE V2



Get Example source ABAP code based on a different SAP table
  


• HAVING ABAP_CDS_SELECT

ABAP_CDS_DDL - CDS View Entity, SELECT, HAVING

ABAP_SYNTAX
... HAVING cds_cond ...

What does it do?
Defines a HAVING condition for the result set of a CDS view entity after a GROUP BY clause is evaluated. A HAVING condition can only be specified together with GROUP BY. The HAVING condition removes all rows from the result set that do not meet the condition cds_cond specified after HAVING.
If the view entity makes use of multiple data sources by using join expressions, then all fields listed after HAVING must be prefixed with the name of their data source separated by a period (.). The prefix is required in all cases, even if the field names are unique.
The following rules apply to the condition specified after HAVING :
As relational operators, comparison operators, LIKE, and IS [NOT] NULL can be used. BETWEEN and IS INITIAL are not supported.
The Boolean operators NOT, AND, and OR are allowed.
lhs can be a field of a data source data_source, a path expression, an aggregate expression, a case expression, or an arithmetic expression.
rhs can be an element of the SELECT list, an aggregate expression, a literal, a parameter, a path expression, a case expression, or an arithmetic expression. ABAP_EXCEPTION when using the operator LIKE, then rhs must be a character literal.
A field of a data source can be specified using a path expression path_expr.element, as long as the CDS associations of the expression do not have any non-SQL CDS entities as association targets and all associations traversed have the cardinality to-one:
The cardinality of the contained CDS associations is to-one.
The path expression contains the cardinality specification attribute to-one. element can be used to specify an element of the association target of the last CDS association of the path.
Other expressions and function calls are not allowed.



Latest notes:

Aggregate expressions can be specified in the HAVING condition, which is not possible in the WHERE condition.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
When accessed, the CDS view entity DEMO_CDS_VIEW_ENTITY_HAVING returns details about all flights that have a maximal seats capacity of more than 500 seats.
DDLS DEMO_CDS_VIEW_ENTITY_HAVING
ABAP_EXAMPLE_END