SAP CDS GROUP BY V1



Get Example source ABAP code based on a different SAP table
  


• GROUP BY ABAP_CDS_SELECT_V1

ABAP_CDS_DDL - DDIC-Based View, 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 ABAP_CDS_V1_VIEW 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. It is not allowed to use the alias names defined in the current CDS view using with AS.
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 . Literals and other expressions cannot be specified after GROUP BY .
When the CDS view is accessed, the results of the aggregate expressions are calculated from the values of the corresponding fields of the combined rows and the results are placed in the element of the resulting row in the result set.
The fields specified after GROUP BY cannot be of the type 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 a CDS view is accessed, the view returns sales_order for every role of a business partner and returns the number of business partners and the total of all gross amounts for every currency. @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
{ bp_role as role, //e.g. customer or supplier
count(distinct buyer_guid) as partners_count,
@Semantics.currencyCode snwd_so.currency_code,
@Semantics.amount.currencyCode: 'currency_code'
sum(snwd_so.gross_amount) as sum_gross_amount }
group by bp_role, snwd_so.currency_code;
ABAP_EXAMPLE_END