Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions →  ABAP CDS - DEFINE VIEW →  ABAP CDS - SELECT →  ABAP CDS - SELECT, clauses 

ABAP CDS - SELECT, HAVING

Other versions: 7.31 | 7.40 | 7.54

Syntax


... HAVING cond_expr ...

Effect

Defines a HAVING condition for the results set of a CDS view after a GROUP BY clause is evaluated. A HAVING condition can only be specified together with GROUP BY. Special rules apply when specifying the condition.

Removes all rows from the results set that do not meet the condition cond_expr specified after HAVING.


Note

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


Example

When accessed, the CDS view sales_order returns the number of business partners for each business partner role in which the total gross amount in euros is greater than 100000.00.

@AbapCatalog.sqlViewName: 'SALES_ORDER_VW'
define view sales_order as
  select from snwd_so
    inner join
      snwd_bpa on buyer_guid = snwd_bpa.node_key
  {  key bp_role as role, //e.g. customer or supplier
     count(distinct buyer_guid) as partners_count,
     sum(snwd_so.gross_amount) as sum_gross_amount }
  where snwd_so.currency_code = 'EUR'
  group by bp_role
  having sum(snwd_so.gross_amount) > 100000.00;