SAP CDS GROUP BY V2



Get Example source ABAP code based on a different SAP table
  


• GROUP BY ABAP_CDS_SELECT

ABAP_CDS_DDL - CDS View Entity, SELECT, GROUP BY

ABAP_SYNTAX
... GROUP BY field1, field2, ...
path_expr1, path_expr2, ...

What does it do?
Groups those rows in the result set of a CDS view entity that have the same content in the elements specified by the fields field1, field2, ... or path expressions path_expr1, path_expr2 ... as a single row. The fields must be specified using the same names as the fields in the data source data_source. The use of alias names defined in the current CDS view entity with AS is not allowed.
If the view entity makes use of multiple data sources by using join expressions, then all fields listed after GROUP BY 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 GROUP BY clause is mandatory if the SELECT list contains any aggregate expressions. All elements that are not defined using an aggregate expression must be listed after GROUP BY .
After GROUP BY, only fields or path expressions that are listed in the SELECT list can be specified. Other elementary operands or expressions cannot be specified after GROUP BY.
When the CDS view entity is accessed, the results of the aggregate expressions are calculated from the values of the grouped rows. Several rows are condensed into one row and the result of the calculation is one field of the result set.
The fields specified after GROUP BY can have any built-in data type except for LCHR , LRAW, STRING, RAWSTRING, or GEOM_EWKB.



Latest notes:

A WHERE condition is evaluated before the rows are combined using GROUP BY.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
When the CDS view entity DEMO_CDS_VIEW_ENTITY_GROUP_BY shown below is accessed, all flights that have the same carrier ID and connection ID are condensed into one row. The number of rows and the average occupation is calculated for each group. The fields carrid and connid, which are used in the string function concat_with_space in the SELECT list, must be listed after GROUP BY.
DDLS DEMO_CDS_VIEW_ENTITY_GROUP_BY
ABAP_EXAMPLE_END