CDS General
CDS General
What & Why CDS: To take advantage of SAP HANA for application development,
and to push down the code to the DB layer and to perform all operations on DB
layer, ABAPer needs a tool so that they Define & Consume Objects in DB layer itself,
hence SAP introduces a new data-modeling infrastructure known as Core Data
Services. With CDS, data-models are Defined and Consumed on Databases rather
than on Application Server.
Originally CDS was available only in Design time and Run time of SAP HANA
only( DB Backend). Now the CDS concept also implemented in SAP NetWeaver
Application Server(), enabling developers to work on ABAP layer with ABAP
development tools while the code execution is pushed down to DB layer.
Definition: Code Data Services are a collection of domain specific languages &
services for defining and consuming semantically rich data-model.
CDS Views: While the data in SAP is still physically stored in transparent tables,
CDS views are an abstract layer on top of the DB tables for data modelling
purposes. CDS views understand the relationship between data base tables and
hide the complexity from the ABAP developer. Created using an enhanced version
of Open SQL, CDS Views reside in the application server (Data Dictionary) but
process the logic in database as the data stored in the DB Tables.
CDS Simplify and Harmonize the way you define and consume your data-models
regardless of consumption technology. Technically it is an enhancement of SQL
which provides you with Data Definition Language for defining semantically rich
table view and user-defined types in the DB.
ABAP CDS provides a framework for defining and consuming semantic data models on the
DB of the ABAP AS. The data models are based on data definition language [DDL] and data
control language [DCL].
CDS comes in two flavours: ABAP CDS and HANA CDS. They share the same specification,
but their implementations differ. ABAP CDS initial focus is on view building and integration
into ABAP dictionary where HANA CDS focus is on building models from scratch.
HANA CDS is located on the SAP HANA DB directly and are used to develop native SAP
HANA applications (SAPA HANA XS), bypassing the ABAP application layer. If you are using
a SAP ERP system you should focus on ABAP CDS technology which is located on the
application server and fully integrated in the ABAP dictionary and the ABAP transport
system as its purpose is to support the implementation of ABAP applications.
Example,
The data model that results from this process provides a framework of relationships
between data elements within a database as well as a guide for use of the data.
Data models are a foundational element of software development and analytics.
They provide a standardized method for defining and formatting database contents
consistently across systems, enabling different applications to share the same data.
If you are familiar with ABAP Dictionary Views, then you can think of a CDS views as
a much more sophisticated version.
ABAP Dictionary views just link the DB tables, but the CDS views bring many more
features such as calculations, aggregations, more variations of table joins, and they
can also be stacked with each other. The comparison is illustrated in the diagram
below.
Why ABAP CDS Views? – Classic vs Code Pushdown approach
The classic SAP development approach has been to keep the unnecessary load
away from the database. Developers would select the required data from a
database and do further processing and manipulation on the application server. The
code would become complex (as its majority has been built for performance
reasons) through the use of indexes and added no value to core business functions.
With the invention of SAP HANA database and consequent introduction of ABAP CDS
Views this approach has changed. The new programming paradigm is called ‘code
pushdown’ or “code to data”. The rule-of-thumb is to ‘do as much as possible in the
database to get the best performance’.
And “as much as possible” means: all expensive calculations, aggregations and
string operations should be done on the database level with only the resulting
sets to be transferred to the application layer. SAP HANA database is
optimised to complete such tasks. This leads to performance gains and reduction of
the the complex application code. For comparison – huge amounts of data had to be
transferred for processing with the classic approach. In some cases this could cause
short dumps due to memory consumption limits.
SAP HANA is capable of aggregating on the fly. There is no need for pre-built
aggregates and indexes since the data is organized using column stores. Also, in an
S/4HANA system the data model has been simplified, by getting rid of tables
necessary for aggregations and indexes.
So, what does ‘code pushdown’ really mean? I am using an example of a CDS View
below to explain:
Apart from regular fields selection from database table SBOOK this CDS view:
Uses a cases statement, based on the value of CLASS field it will return a
corresponding value: ‘Economy’, ‘Business’, ‘First’.
Does a currency conversion from source currency to USD using a built-in
function
Calculates the difference between order date and flight date using a built-in
function
In the classic approach, all these calculations and conversions would have been
done on the application server in ABAP. With CDS Views it is possible to do so on the
database level.
CDS Views can be consumed in many ways as a data source. Whether it is well
known ALV report using ALV with Integrated Data Access (IDA) or modern SAP Fiori
application with the CDS view exposed using SAP Gateway in the oData format. You
can also quickly build FIORI apps on top of CDS Views with SAP FIORI Elements
templates. CDS Views also work very well with SAP’s analytical apps using analytics
related annotations and analytical engine. Below is a simplified diagram of CDS
Views consumption:
ABAP CDS Entities are data-models based on the Data Definition Language [DDL] and
managed by the ABAP Dictionary.
The ABAP CDS Entities are:
A CDS view is defined on the existing database tables/views/other CDS views in ABAP
dictionary using specific DDL statement Define View. It serves to define the structure of
the CDS database view and represents a project on several database tables/views in ABAP
dictionary.
The CDS Data Base (SQL) View & the Entity associated with a CDS View are part of same
namespace, so different names must be assigned to the Data Base View and to the CDS
entity.
SAP HANA supports SQL as a mean to Define, Read & Manipulate data. On top of
SQL many technologies introduce higher level models to add semantics and its
consumption.
These above high-level models share many commonalities but are usually specific
to their technology. This prevents their reuse across the stack and increases the
effort for application developers to address these.
SAP introduces set of domain-specific Languages & Services called Core Data
Services for Defining& Consuming semantically rich data-models.
CDS Simplify & Harmonize the way you define and consume your data-models
regardless of consumption technology. Technically it is an enhancement of SQL
which provides you with Data Definition Language for defining semantically rich
table, view and user-defined types in the DB.
https://help.sap.com/doc/
1fa4facf5a4d49b0b8d9f5f28c678f70/1511%20001/en-US/frameset.htm?
7c078765ec6d4e6b88b71bdaf8a2bd9f.html
CDS: CDS is an extension of the ABAP Dictionary that allows you to create
semantically rich data models in the database and to use these data models in your
programs.
The CURRENT variants are the database-independent ABAP CDS and HANA CDS.
ABAP CDS:: ABAP CDS implement the general CDS concept for AS ABAP.
1. They use the platform independent CDS DDL to define CDS Views and CDS
Table Functions that implement a semantic data model in ABAP Dictionary.
ABAP CDS is independent of database system.
***The entities of the models defined in ABAP CDS provide enhanced access
functions compared with existing
database tables and views defined in ABAP Dictionary, making it possible to
optimize Open SQL-based
applications. This is particularly clear when an AS ABAP uses a SAP HANA database,
since its in-memory
characteristics can be implemented in an optimum manner. ***
The data models are defined in the form of CDS objects using the data definition
language (DDL) and data control language (DCL) provided by ABAP CDS in the ABAP
CDS syntax in CDS source code. The CDS objects defined with these languages are
integrated into ABAP Dictionary and managed here.
Core data services are a new infrastructure for defining and consuming semantically
rich data model in SAP HANA. Using a data definition language (DDL), a query
language (QL), and an expression language (EL), CDS is envisioned to encompass
write operations, transaction semantics, constraints, and more .
CDS DDL:
Data definition language (DDL) of the ABAP CDS. CDS DDL contains language
elements for CDS data definitions in DDL source code, language elements for CDS
annotation definitions in DDLA source code, and language elements for CDS
metadata extensions in DDLX source code.
Data Definition Language. Subset of SQL. DDL statements create and delete
the objects of a relational database. In Application Server ABAP, DDL
functions are integrated into ABAP Dictionary in ABAP Workbench. ABAP CDS
offers a separate CDS DCL that covers SQL and expands on it.
CDS DCL: A platform-independent CDS DCL makes it possible to develop CDS roles
for the CDS access control.
CDS annotation:
A CDS annotation (or annotation for short) adds metadata to a CDS object
that expands the syntax options of SQL. The annotation is specified in a fixed
annotation syntax in the CDS source code of the CDS object. CDS annotation
definitions can be used to create CDS annotations themselves as CDS
objects. A definition of this type determines the semantics of the annotation
and dictates how it is specified in CDS source code. SAP delivers a
predefined set of SAP annotations.
Syntax
@[<]Anno[: value ]
|[: { subannos } ]
|[: [ arrelem ] ]
|[.subAnno[ ... ]]
Effect
A CDS annotation is specified in CDS source code by using fixed annotation
syntax. This syntax dictates the following:
Example
The following DDL source code for defining a CDS view contains ABAP
annotations and other annotations at the allowed positions (in other words,
for the entire view, for the elements of the SELECT list, and for an input
parameter).
CDS data definitions are made using the CDS DDL of the ABAP CDS.
They define the following CDS entities. These units can be accessed as
a data type (in ABAP programs) and as a data source (in Open SQL
read statements).
1. CDS views
The CDS DDL of the ABAP CDS also contains language elements that
enhance CDS entities.
CDS access controls are based on CDS roles that are defined in CDS
DCL. When CDS entities that are assigned a CDS role are accessed,
additional access conditions are evaluated by default.