ABAP On SAP HANA
ABAP On SAP HANA
ABAP On SAP HANA
Core Data
Services
TOPICS:ABAP For BeginnersBeginners SAPCDS View In HANACore Data ServicesSAP
ABAP Tutorial
Let us start our encounter with Core Data Services (CDS) View with questions and answers.
Before we explain What is CDS View, let us ask, Why CDS View?
The issue with the above SQL: Large Semantic Gap between Requirement and SQL Code.
If you are not an experienced SQL developer, you would find it complex/difficult to
understand the meaning/semantic of the SQL. Therefore SAP wanted something simpler and
better. This is one motivation for CDS.
Being an ABAPer you find the above SQL complex and you decide to write your own Open
SQL in ABAP.
Issue with the above Open SQL: SQL Complexity Leads to Imperative Code (codes which
are like instructions/statements which change its state. Imperative programming focuses on
describing how a program operates.)
There are performance concerns in the above Open SQL. Loops in loops, nested queries with
many round trips is not advisable. This is another motivation for CDS.
Same requirement: Get the id, name and the respective zip code of the home address for all
employees in org_unit ‘4711’.
With CDS, SQL developers see small or no semantic gap and ABAPers do not need any
coding. You get the result directly from the CDS. Isn’t this motivation enough?
Question: We already have Database Views in ABAP (SE11), then why do we still need
“CDS views”? Or, What are the advantages of using “CDS views”?
Answer: CDS is much more powerful than what it appears. The CDS concept is far more than
simple view building but describes a DDL for building a meta-model repository involving
database tables, database views, functions, and data types.
CDS was invented by SAP, because the modeling capabilities of the ABAP Dictionary and
of the “SAP HANA Studio” are not sufficient for the needs of all fully blown business
applications with modern needs.
With “HANA CDS”, CDS is available for SAP HANA in the SAP HANA studio. With
“ABAP CDS”, the CDS concept is also made available for the AS ABAP, where the features
of CDS surpass the modeling capabilities of SE11. ABAP CDS is open and not restricted to
SAP HANA (i.e. database independent).
If we need meta-models for our application, that can be built with CDS, then we need CDS
views.
Question: OK, we read above that CDS was invented to facilitate needs which ABAP
Dictionary and HANA Studio could not meet. So, what are the types of CDS Views?
Answer: There are two types of CDS Views.
1. ABAP CDS
2. HANA CDS
(We will check the details of CDS View with and without Parameters in our next article)
Similar to the role of the DDIC in the traditional ABAP world, data models based on CDS
serve as central definitions that can be used in many different domains, such as transactional
and analytical applications, to interact with data in the database in a unified way . However,
CDS data models go beyond the capabilities of the DDIC, which were typically limited to a
transactional scope (think of traditional online transaction processing functionality). For
example, in CDS, you can define views that aggregate and analyze data in a layered fashion,
starting with basic views and then adding powerful views that combine the basic views.
Another difference is the support for special operators such as UNION, which enables the
combination of multiple select statements to return only one result set.
CDS artifacts are stored in the DDIC and can be accessed in ABAP programs via Open SQL
in the same manner as ordinary ABAP tables or views.
In simple words:
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 .
We can use the CDS specification to create a CDS document which defines the
following artifacts and elements:
Entities (tables)
Views
User-defined data types (including structured types)
Contexts
Associations
Annotations
Question: What is the fundamental difference between HANA CDS and ABAP CDS?
Answer: The subtle differences between CDS in native SAP HANA and CDS in ABAP lies in
the view definition. In both the ABAP and HANA scenarios, views are created on top of
existing database tables that are contained in the DDIC. With CDS in native SAP HANA, we
must create the basic entity types that correspond to the DDIC tables as part of the CDS view
definition. With CDS in ABAP, we can refer to any underlying DDIC table, view, or type
from within the CDS view definition, avoiding the need to “duplicate” the DDIC table
definitions on the CDS layer. In the ABAP scenario, the CDS definitions are considered
DDIC artifacts and need to be activated like any other DDIC artifact and when changes are
made, their impact is propagated to dependent artifacts.
Question: What is preferred ABAP CDS or HANA CDS if the client is in ABAP on
HANA DB?
Answer: If you use ABAP on HANA DB, you can work directly on the DB and also use
HANA CDS there. But then the CDS objects created are not managed by the ABAP
Dictionary meaning you cannot access them directly with Open SQL and they are not TYPEs
in the ABAP TYPE system.
Question: When should we use ABAP CDS and when should we use HANA CDS?
Answer: If you run SAP HANA standalone or in a side-by-side scenario (there is no ABAP
stack on top) you cannot use ABAP CDS. You must use HANA CDS.
If you have an ABAP stack on top of a HANA database (an AS ABAP uses the HANA
database as central database) then:
i) If you want to access the CDS entities in ABAP as data types or in Open SQL or if you
want to evaluate the CDS annotations in ABAP, you must use ABAP CDS.
ii) If you do not want to access the CDS entities in ABAP, but you want to transport and
upgrade them like ABAP repository objects, you can use ABAP CDS.
iii) If you do not want to access the CDS entities in ABAP as data TYPEs or in Open SQL,
you can use HANA CDS, which is better integrated into SAP HANA. An access from ABAP
is then possible using Native SQL (ADBC, AMDP) only.
Answer: Check the table TADIR in SE16; PGMID = ‘R3TR’, OBJECT = ‘DDLS’; here we
find all DDL sources and the package of each source in column DEVCLASS. Knowing the
package, we can use ADT (ABAP Development Tool in HANA Studio) to find the DDL
sources in ADT.
Examine table DDLDEPENDENCY in SE16; it contains the names of all DDL sources and
the names of the CDS entities (value STOB in column OBJECTTYPE) defined therein as
well as the names of the generated database views (value VIEW in column OBJECTTYPE);
(one row for each -> two rows for each DDL source). => Selecting VIEW for OBJECTTYPE
gives you all CDS database views.
Now let us try to open the DDL source of the CDS in SE11.
Now, let us open the DDL SQL View of the CDS. Note the warning below which says DDL
SQL views are only supported in a limited way by SE11.
Having one name is just not good enough in CDS; we need two names.
One name is for the SQL view that is going to be created in the dictionary (the one we will be
able to look at in SE11), and the other name we have is a name for the CDS view entity,
which is viewed and changed via Eclipse.
PS: We could name both the SQL view and the CDS view the same, but we should not as they
are different things, so the name should reflect the difference.
CDS View entity is the one we should refer to in SELECT statements in our ABAP
programs. Although we can use DDL SQL View in our programs, but we should not.
Seeing a CDS View in SE11 is kind of a technical artifact and we should not address the
database view that is shown there in our ABAP programs. From SE11 you can also navigate
to the database object that is generated from the definition. This database object can even be
accessed directly with Native SQL.
This means we can access our CDS Views directly in ABAP programs or from elsewhere. For
evaluating the semantic properties (annotations) of a CDS View (stored in system tables) we
should use an appropriate API (CL_DD_DDL_ANNOTATION_SERVICE if available in
your system).
The database views created from the CDS source code are merely “for technical” reasons.
The CDS source code and the CDS entity defined there should be the “real thing”.
SAP claims that whereas a traditional database view is just a linkage of one or more tables, a
CDS view is a fully fledged data model, which, in addition to having extra features that SE11-
defined views do not, can be used even by applications outside of the SAP domain.
Note: We cannot do OUTER JOINs in an SE11 database view (just one limitation to point
which CDS can overcome).
CDS views, like the well-known dictionary views created and maintained in transaction SE11,
are managed by the ABAP data dictionary. During activation, a database view is created on
the HANA layer, yet only the ABAP CDS view (defined in a so-called DDL source) has to be
transported via the ABAP Change and Transport System (CTS). Moreover, the functionality
provided by CDS views can be used on all SAP supported databases, we don’t have to worry
when transporting these objects in a heterogeneous system landscape.
CDS views are entities of the ABAP CDS in the ABAP Dictionary that are much more
advanced than the classical SE11 views. We can influence CDS views with parameters that
can be used at different positions of the DCL. As for classical SE11 views, for a CDS
View, a platform dependent runtime object is generated at the database that we can examine
in SE11. When accessing a (CDS) view with Open SQL (i.e ABAP), the database interface
accesses this runtime object. A CDS view is created with a source code based editor in Eclipse
using a DDL (which ha nothing to do with SQLScript).
For technical reasons, from the source code a classical DB view is generated in SE11 that we
can access like any classical view, but we shouldn’t. Instead, the so-called CDS entity should
be accessed because it carries more meaning than the mere technical DB view and involves
new kind of client handling.
PS: In an upcoming release, the direct access to the DB view of a CDS view will be declared
as obsolete. So, better not to use them if it can be avoided.
We use CDS to model large parts of our application in the Dictionary and use simple Open
SQL SELECTs in ABAP for relatively straight joins and subqueries in ABAP. Some day
Open SQL might have the same power like CDS but it doesn’t mean that those are redundant.
Already before CDS, we had the choice between creating a reusable view in SE11 or
programming a join in Open SQL in ABAP. As a rule of thumb, we created a view if it is used
in more than one program and programmed a join when we needed it only once. That is very
similar for CDS, but with much more possibilities for modeling semantically rich models for
reuse in ABAP programs.
CDS is open. It is not restricted to HANA (but performance can be different in different DB).
Hope these Q&A would help to clear out some cobwebs regarding Core Data Services. In the
subsequent articles, we would show how we can create the CDS Views and use them in
ABAP Programs.
If you want to get such useful articles directly to your inbox, please SUBSCRIBE. We
respect your privacy and take protecting it seriously.
If you liked this post, please hit the share buttons and like us on facebook.
Also, check our complete list of ABAP for SAP HANA Tutorials.
Source:
1. DEV200 –Core Data Services TechEd 2015 session
2. Blogs and answers from SAP Expert Horst Keller
3. SAPInsider
4. GIThub