ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT → 

SELECT - HAVING

Quick Reference

Syntax

... HAVING sql_cond ...

Effect

The addition HAVING limits the number of rows in groups in the results set by using the logical expression sql_cond on these rows. The syntax of the logical expression sql_cond matches the syntax of the logical expression sql_cond of the WHERE condition. The logical expression evaluates the content of row groups.

The operands of the relational expressions of the logical expressions can be as follows:

If a HAVING clause is specified, all columns in the SELECT list that are not arguments of aggregate functions here must be specified after GROUP BY. If the SELECT list is specified as *, HAVING clauses without GROUP BY clauses cannot be used. The addition HAVING cannot be specified for pooled tables and cluster tables.

Notes

Example

Reads the number of booked smoking and non-smoking seats for each flight date of a particular flight connection.

PARAMETERS: p_carrid TYPE sbook-carrid,
            p_connid TYPE sbook-connid.

TYPES: BEGIN OF sbook_type,
         fldate  TYPE sbook-fldate,
         smoker  TYPE sbook-smoker,
         smk_cnt TYPE i,
       END OF sbook_type.

DATA sbook_tab TYPE TABLE OF sbook_type.

SELECT fldate, smoker, COUNT( * ) AS smk_cnt
       FROM sbook
       WHERE connid = @p_connid
       GROUP BY carrid, fldate, smoker
       HAVING carrid = @p_carrid
       ORDER BY fldate, smoker
       INTO CORRESPONDING FIELDS OF TABLE @sbook_tab.

Example

See SQL Expressions, Use in Aggregate Expressions.