ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Reads → SELECT clauses → SELECT - GROUP BY
GROUPING, Grouping Function
This example demonstrates the grouping function GROUPING
.
Other versions:
7.31 | 7.40 | 7.54
Source Code
SELECT FROM sflight
FIELDS carrid,
connid,
planetype,
SUM( seatsmax ) AS sum_seatsmax,
grouping( carrid ) AS grouping_carrid,
grouping( connid ) AS grouping_connid,
grouping( planetype ) AS grouping_planetype
WHERE carrid = 'LH'
GROUP BY GROUPING SETS ( ( carrid, connid, planetype ),
( carrid, connid ),
( carrid, planetype ),
( connid, planetype ),
( carrid ),
( connid ),
( planetype ),
( ) )
INTO TABLE @DATA(result_grouping).
cl_demo_output=>display( result_grouping ).
Description
For Lufthansa flights, this example calculates the sum of the maximum available seats with respect to
the plane type (column planetype
), the connection (column connid
), and the carrier (column carrid
).
The grouping function for the plane type column, connection column, or carrier column is used to determine whether they are part of the aggregation. The following combinations of the grouping sets are used to do this:
( carrid, connid, planetype )
( carrid, connid )
( carrid, planetype )
( connid, planetype )
( carrid )
( connid )
( planetype )
- Empty grouping set
( )
.