SAP GROUPING FUNCTION



Get Example source ABAP code based on a different SAP table
  


• GROUPING SELECT

ABAP_SQLAGG - GROUPING

ABAP_SYNTAX
... GROUPING( col )

What does it do?
The result of the grouping function GROUPING indicates whether a specific column is part of the aggregation. After the grouping function GROUPING, a column name in parentheses is expected as an argument.
The return value of the grouping function GROUPING has the data type INT1. The following return values of the grouping function are possible here: ValueMeaning 0The column is not part of the aggregation. 1The column is part of the aggregation.
The columns that are part of the aggregation contain the null values as placeholders in the corresponding results. More specifically, the grouping function GROUPING determines whether the column that contains a null value in the result was part of the aggregation or whether it was already the null value in the data source.

Rules
The grouping function can only be used in the SELECT list and in the HAVING clause.
The grouping function can be used only if the GROUP BY clause contains the addition GROUPING SETS.
The column used as an argument of the grouping function GROUPING must also be added to the GROUP BY list.


ABAP_EXAMPLE_VX5
The following example calculates the number of Lufthansa flights depending on the plane type (the column planetype) and the connection (the column connid). Here, the grouping function for the plane type column or connection column is used to determine whether they are part of the aggr egation.
ABEXA 01045
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
GROUPING, Aggregate Function
ABAP_EXAMPLE_END