In the previous blog"SAP CDS View basic syntax (create your first CDS View)"
In , I introduced the basic syntax of CDS View. In this blog, I will introduce some advanced usage of CDS operations, including three parts: aggregation, JOIN and UNION.
use:
Complete aggregation operations, such as MIN, MAX, COUNT, SUM, etc.
grammar:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sflight
{
planetype,
min(price) as min_price,
max(price) as max_price,
sum(price) as sum_price,
count(*) as count_planes
}
group by
planetype
Explanation:
running result:

use:
Specify the filter conditions during the aggregation operation
grammar:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sflight
{
planetype,
min(price) as min_price,
max(price) as max_price,
sum(price) as sum_price,
count(*) as count_planes
}
group by
planetype
having
planetype = '747-400'
or count(*) > 60
Explanation:
running result:

use:
CDS supports Inner Join, Left Outer Join, Right Outer Join
grammar:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sbook as a
inner join sflight as b on a.carrid = b.carrid
and a.connid = b.connid
and a.fldate = b.fldate
{
a.carrid as airline_code,
a.connid as connection_number,
a.fldate as flight_date,
a.customid as customer_id,
b.planetype as planetype
}
where
a.carrid = 'DL'
Explanation:
running result:

use:
UNION the result set of two SELECT
grammar:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select distinct from sbook
{
carrid as airline_code,
connid as connection_number,
fldate as flight_date
}
where
carrid = 'DL'
union
select distinct from sflight
{
carrid as airline_code,
connid as connection_number,
fldate as flight_date
}
where
planetype = '747-400'
Explanation:
running result:

In this article, we further introduce the operation syntax of SAP CDS View. I believe that through these two blogs, all students should have learned to create CDS View and complete operation logic with CDS View. There are many other uses of CDS View, and interested students can check the help files of ABAP.
High-quality SAP technical blog, welcome to follow ️, like , forward !
Consuming CDS View Entities Using ODBC-Based Client Tools This article introduces the method of visiting the ABAP system CDS View data based on the ODBC (Open DataBase Connectivity) SQL statement. ODB...
Business scenario, today found a problem in the creation of CDS VIEW, ANLA and ANLB through the company + asset number join up no problem, but as soon as you join the ANLC will not find the data, SE16...
In part1 of this tutorial, the old way to create OData service on top of CDS view is introduced. In SAP Help Generate Service Artifacts From a CDS View a new annotation is described: @OData.publish: t...
You paste the following source code for a simple CDS view into ABAP development studio and activate it: And you would like to know what objects are automatically generated during CDS view activation. ...
table of Contents Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically generate after you activate one CDS view Part3 – how i...
Let’s try to resolve one real issue now. What we want to achieve is: in CRM we need a CDS view which returns the service order guid together with its Sold-to Party information, “Title&rdqu...
So far we have a working CDS view ready for us to create a UI5 application on top of it via Smart Template in WebIDE within just a couple of minutes. Once done, the UI5 application will display the da...
From my colleague Xu Miles Authorization Objects are business concept, they are distinguished by business scenario. Therefore, there might be a lot of Authorization Objects using the same Authorizatio...
We write in ABAP Development Tool in SAP CDS view, a view that begin with @ to maintain these comments, like annotation Java Spring applications in a wide range, is a way for the development object ma...
(1) create a CDS view with following source code: Once activated, you see two fields in SQL view as expected. (2) Create another CDS view which extends the view created in step one with additional two...