Choose your location
Europe
Asia
America
Go back

Introduction to SAP CDS Views

Introduction

With the release of SAP HANA the introduction of the concept of the in-memory database and the columnar tables, SAP has introduced a change regarding the development of the management layers from the ERP tables.  

As data processing has improved, the new recommendation is: do as much as you can at a database level. This is the code-to-data approach. The idea behind it is to remove the logic from the application server and bring it to the database to decrease data runtime. Indeed, since data processing is optimized, the new recommendation is to be as close as possible to the database (the code-to-data approach). The objective is to transfer the logic from the application server to the database in order to obtain the best performance.   

What are the functionalities of the CDS views?

CDS views allow bringing the logic used in the SAP ABAP applications to the database perspective. They are created and maintained using Data Definition Language (DDL) and were enriched with the following features: 

  • Entities – structured tables with custom-defined types. 
  • Associations – ability to create joins on-demand, i.e., the join is only executed when the data from the table associated are needed. 
  • Expressions – used to create calculated fields. 
  • Annotations – used to add component-specific metadata to the source code of any CDS entity.

ABAP CDS views versus HANA CDS views

There are two types of views: ABAP CDS views and HANA CDS views.  

They are similar regarding the fact that they both bring a large part of the ABAP code to the views, however they differ in terms of implementation and platforms. 

Below are the main characteristics of each type: 

In this document, we are going to focus on ABAP CDS views. 

ABAP CDS view is defined for existing database tables or other CDS views in the ABAP Dictionary. We must use the ABAP CDS statement ‘DEFINE VIEW’ in Eclipse Editor to create it. 

help.sap.com © SAP SE or an SAP affiliate company

Example 1 

A custom view Z_CDS_FLIGHTS which shows the Airlines Flights. 

The CDS Entity Z_CDS_FLIGHTS defines a projection into the database tables sflight and scarr by joining both tables. 

 

When the CDS view is activated, the CDS entity and the SQL view are created in the ABAP Dictionary. 

CDS Entity and SQL view in Eclipse Editor after Z_CDS_FLIGHTS activation 

Z_CDS_FLIGHTS Entity 

Result of SQL View ZCDSFLIGHTS execution in Eclipse Editor 

Standard CDS views

Moreover, SAP has provided standard CDS views for each SAP module. We can find all of them in the SAP Help Portal: 

  • Choose your SAP S/4HANA version 
  • Choose the corresponding SAP module  
  • Check the CDS view documentation 

Note: If you choose to use a standard CDS view to meet your business requirements, it is a best practice to duplicate it and make your customizations in the copy. The standard views may undergo updates and overwrite your code. 

CDS view extension  

One of the main features of CDS views is that they can be easily extended, which makes the reuse of views even more feasible. 

Enhancements are available through the template ‘Extend View’.  

Extend View Template in Eclipse Editor 

Where: 

 view_name is the CDS view which will be extended and  

ddl_source_name_editable is the extension view 

 An extension can have all the elements of an ordinary CDS view except for: 

  • Joins – it is mandatory to use associations instead 
  • Elements are only accepted when the base view already contains them (as of release 7.51)

Aggregate expressions  

– Group By clause  

– Union  

Example 2: 

An extended Z_MAXSEATS_ENHANCED view which adds 3 new fields seatsmax, seatsmax _b and seatsmax_f from table sflight to the view Z_CDS_FLIGHTS. 

The CDS Entity Z_MAXSEATS_ENHANCED 

When the CDS view extension is executed, we can see the base view Z_CDS_FLIGHTS with the new 3 fields added: 

Base View Z_CDS_FLIGHTS extended with the fields seatsmaxseatsmax_b and seatsmax_f 

When we check the base CDS View Z_CDS_FLIGHTS, we can see it was extended with Z_MAXSEATS_ENHANCED view:  

Base view Z_CDS_FLIGHTS with the extension view Z_MAXSEATS_ENHANCED 

Note: A base CDS view can have several extension views, nevertheless an extension view can not be extended. 

There are more interesting features to be discovered in this new way of modeling. To take a deeper dive in CDS views, please check the sites below: 

SAP – ABAP CDS Development User Guide 

SAP Community – All blogs Posts 

SAP HANA Developer Guide 

Conclusion

In summary, SAP CDS views represent the new data modeling framework developed to take advantage of fast data processing in the SAP HANA database.  

Application performance is significantly improved once CDS views are consumed at the database level rather than on the application server.  

The big advantage of CDS views is that they provide a unified data model for multiple applications. They can be used as data sources for different SAP applications such as SAP Fiori, S/4 HANA Embebbed Analytics, BW/4 HANA and others, as well as for third party applications such as PowerBI.  

The Teamwork Canada team offers expertise, and the following CDS view training:  

  • SAP Abap CDS View – Basic 
  •  SAP Abap CDS View – Advanced   

 Do not hesitate to contact us at info_twca@temwork.net for more information!  

Contact us
x
* Required
x
Choose your location
Canada FR Canada EN USA France Geneva Bern/Zurich Luxembourg FR Luxembourg EN Germany Slovakia India China Vietnam Singapore
TeamWork news
Our events
Our webinars