Saturday, December 5, 2020

Aggregate Expression in CDS View

 Aggregate Expression in CDS View:

Aggregate expression in a SELECT statement of a CDS view in ABAP CDS. An aggregate expression calculates a single value from an operand operand by calling an aggregate function from multiple rows of a results set. The following table shows the possible aggregate functions:

Aggregate Function Meaning
MAX Greatest value of operand
MIN Least value of operand
AVG Average value of operand (the operand must be numeric). The type INT8 and the types DF16_... and DF34_... for decimal floating point numbers are not supported.
SUM Sum of operand (the operand must be numeric).
COUNTIf DISTINCT operand is specified, the number of distinct values of operand; if * is specified, the number of rows in the results set.

 


 

 


     @AbapCatalog.sqlViewName: 'ZV_CDS_AGGR'
    define view ZCDS_AGGR as
      select from snwd_so
      { key buyer_guid,
           @Semantics.currencyCode
            currency_code,
           @Semantics.amount.currencyCode: 'currency_code'
            sum(gross_amount) as sum_gross_amount,
           @Semantics.amount.currencyCode: 'currency_code'
            min(gross_amount) as min_gross_amount,
           @Semantics.amount.currencyCode: 'currency_code'
            max(gross_amount) as max_gross_amount,
           @Semantics.amount.currencyCode: 'currency_code'
            avg(gross_amount) as avg_gross_amount,
            count(*) as sales_orders_count }
      group by buyer_guid, currency_code