SAP HANA has introduced new paradigms to SAP ABAP application programming. Before SAP HANA, development paradigm in SAP was based on DATA-to-Code where intensive calculation was done at the application layer and database utilization was minimized. New programming paradigm in SAP HANA is Code-to-Data, where the intensive calculation is done at the database layer and less programming at application layer.
Core data services (CDS) is based on new programming paradigm in SAP HANA. CDS is a new data modelling technique in SAP HANA. It can be defined as below:
It is an infrastructure that can be used by database developers to create the underlying (persistent) data model which the application services expose to UI clients.
Above definition can easily be explained in below diagram
With CDS, data models are defined and consumed on database server rather than on application server. CDS also offers capabilities beyond the traditional data modelling tools, including support for conceptual modelling and relationship definitions, built-in functions, and extensions. CDS simplifies and harmonizes the way you define and consume your data models, regardless of the consumption technology.
Technically, it is an enhancement of SQL which provides you with a data definition language (DDL) for defining semantically rich database tables/views (CDS entities) and user-defined types in the database.
Earlier ABAPer’s were always asked to reduce database hits to improve program performance. All required data was fetched from database in one, two or more select queries and then the fetched data was filtered in ABAP program using loops, sorting, binary search or sometimes with nested loops. All these activities took place at the application layer. In ABAP versions before SAP HANA, all required data is fetched from database layer to application layer and for this, a connection is set up from application layer to database layer. Some resources are utilized in making this connection that could impact the performance of the program.
With the introduction of CDS, there is no need to fetch data from database layer to application layer. CDS is a technique to push the code down to the database layer. It means when CDS view is used in ABAP program, it automatically runs at the database layer. It fetches all required data and does filtration at the database layer. Only results are passed from database layer to application layer.
Let us take an example to understand this technique.
We need to fetch all customers id, name, and address for organisation unit 1710.
If the code is written in simple ABAP program, the code would be written as follows. Three select queries would execute to fetch data from the database and then 3 nested loops to filter that data.
The same code can be written in one select query using CDS views as follows:
The question can be asked whether this can also be achieved using SE11 views. The answer is that the same can be done in SE11 view also, but there are performance implications.
It is true that a view can be created in SE11 by joining 3 tables but the SE11 view and CDS views work completely differently.
SE11 view resides at application server as it is created in the data dictionary. It creates a connection between application layer and database layer in which some resources are utilized and performance is degraded.
CDS view is database object which resides at database layer and is also known to ABAP layer. Consumption of CDS View in ABAP program invokes Database Object which is residing at Database Layer. This way, an SQL can be executed without creating a database connection between ABAP Layer and Database. Only results are transferred back to ABAP layer. This will save resources for creating a database connection from ABAP Layer to Database Layer. Hence, CDS views are much faster than SE11 views.
CDS views are more powerful with use of UNION and outer joins which is not possible in SE11 views.
CDS concept was designed for all platforms. It is database independent. It means core data services can also be used without HANA database. So, we have 2 types of CDS views:
HANA CDS is available for SAP HANA in the HANA Studio. The DDL of CDS allow to define database tables, database views, data types by wrapping the according to native HANA SQL statements and enriching them with semantical properties.
CDS concept is incorporated in ABAP to enhance data dictionary capabilities at the application server. An ADT based source code allows to create ABAP CDS views. On activation of CDS, one entity is also defined in ABAP dictionary as dictionary object which can be used as data types and access in open SQL as a data source.
CDS view contains the power of SQL which resides at database layer and its use depends on Reusability. CDS view should be created when it is required in multiple programs and there is a need for semantical and technical capabilities of CDS views.
ABAP CDS plays a substantial role in the foundation of SAP S/4HANA. S/4 HANA is designed to use the real power of HANA DB and for that, we need a semantic rich data model.
A large number of CDS artefacts with several thousand lines of ABAP code have been defined in S/4 HANA system that creates a semantic layer on top of traditional physical SAP ERP tables. These tables that are physically present at database layer and have a complex inner structure which can be evaluated with traditional ABAP processing. The semantically rich data modelling provided by CDS enables this layer in SAP S/4HANA, facilitating simplified and efficient access to the underlying data.
SAP developers are also using CDS for new SAP Business Suite developments, especially in newer software components, although it is a bit more challenging to take advantage of the full breadth of the unifying characteristics of CDS in SAP Business Suite, as its data model has evolved over time.
Core Data Services (CDS) aims to be Building Block for Timeless Software. It is next generation data definition and access for database centric applications. It provides cross platform unified abstraction layer- similar to ODATA for UI abstraction. It helps build a maximum transparency for different programming models. It can be easily integrated with platform lifecycle – management.
In next blog, we will discuss how to create CDS views in ADT tool.