Enhanced ABAP Development With Core Data Services (CDS)
Enhanced ABAP Development With Core Data Services (CDS)
Articles | Case Studies | White Papers | Q&As | Webinars | Videos | Blogs | Podcasts | Events | Magazine | Books | Why Subscribe?
Search
FINANCIALS GRC HR SCM CRM BI HANA CLOUD ADMIN/DEV EMERGING TECH
Close -
Article
Enhanced ABAP Development with Core Data Services (CDS)
How CDS Brings a Modern Data Modeling Approach to ABAP
by Karl Kessler | SAPinsider, Volume 16, Issue 4
October 8, 2015
With the advent of SAP HANA, a new data modeling infrastructure called core data services (CDS) has been introduced by
SAP to simplify how developers define semantically rich data models. Read on to learn the concepts behind CDS and how it
works in ABAP development processes, and walk through a step-by-step guide on using CDS with SAP’s development
toolset.
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 (see the sidebar "CDS in SAP
Software" for more on how SAP itself is using CDS in its own applications).
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.
Originally, CDS was designed for native SAP HANA application development.
It was introduced with support package stack (SPS) 06 for SAP HANA as
part of SAP HANA extended application services (XS), an application server
for SAP HANA that includes a runtime environment for native development.
With SAP NetWeaver 7.4 SPS 05, the CDS concept was also fully
implemented in SAP NetWeaver AS ABAP. While differences have evolved
between the two variants — for example, SAP HANA-based CDS obviously
operates on SAP HANA, while ABAP-based CDS operates on most major
database platforms as well as SAP HANA, and each has a different type of
repository for development objects — both variants pursue the same goal: to
represent central data definitions as a common basis for application
development of all kinds.
ABAP-based CDS plays a substantial role in the foundation of SAP Business Suite 4 SAP
HANA (SAP S/4HANA). A large set of CDS artifacts — several thousand CDS views —
consisting of several hundred thousand lines of ABAP code, represent the underlying core
data model of the SAP S/4HANA solution. The main motivation for SAP S/4HANA was to
provide a semantic layer on top of the traditional physical SAP ERP tables, which often
act as physical data containers on the database and have a very complex inner structure
that, in most cases, cannot be evaluated without traditional ABAP processing. The
semantically rich data modeling provided by CDS enables this layer in SAP S/4HANA,
facilitating simplified, efficient access to the underlying data.
The CDS data model used by SAP S/4HANA can be considered a successor to the virtual
data model used by SAP HANA Live, which uses SAP HANA calculation views to provide
real-time operational reporting and analysis of content from SAP Business Suite and other
sources. While the calculation views used by SAP HANA Live are supported only on SAP
HANA, ABAP-based CDS has been engineered with complete transparency to the
underlying database, meaning that all major database vendors are supported in addition
to SAP HANA, which remains the optimal database choice.
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.
To start ABAP in Eclipse, open the Eclipse project explorer and switch to the
ABAP development perspective. To begin development work, establish a
connection to the ABAP back end by creating an ABAP project (in the
example, M36_001_d002831_en). With this connection, you can create new
ABAP repository artifacts, such as ABAP programs, classes, and, as in our
example, CDS artifacts.
You can create these repository artifacts as local objects belonging to the
$TMP package, but in this example we use an existing package called
ZDEV201 to house the CDS artifact. Simply right-click on the package icon,
and from the context menu select New > Other ABAP Repository Object (see
Figure 1).
Note that one of the fundamental differences between CDS in native SAP
HANA and CDS in ABAP lies in the view definition. In both the ABAP and
SAP HANA scenarios, you begin your development work by creating views on
top of existing database tables that are contained in the DDIC. With CDS in
native SAP HANA, you must create the basic entity types that correspond to
the DDIC tables as part of the CDS view definition. With CDS in ABAP, you
can simply 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.
request for the view (see Figure 3). After assigning the view’s DDL source to
an existing ABAP package, either select an open transport request or create a
new one, which you can use to keep track of the changes that make up your
development tasks. This transport request can be bundled with tasks from
other developers and later transported to a subsequent system for test and
then production.
The templates include placeholders for code that you fill in step by step. If
you later discover the need to change or extend the nature of your CDS view,
you can always change the source code directly in the DDL editor and freely
edit all parts of it as needed. This is particularly helpful if you want to copy
portions of the source code from example code, for instance.
You can view the details of any of the syntactical elements that make up a
CDS view definition on the fly by pressing the F2 key. The tooltip pop-up
shows all the attributes, the corresponding data elements and types, and the
associations (relationships) between the element and other tables or views,
including their cardinality. For instance, in the example, the tooltip pop-up
shows that the invoice header table contains a number of associations,
including an association with a buyer table. With the tooltip functionality, there
is no need to navigate deeply inside the DDIC — all of the relevant
information is visible in one place.
statement and choose Add Group by Clause, which automatically inserts the
group by clause containing the elements you defined for the count (see
Figure 11). To restrict the result set, we manually add a simple where clause
that returns results with a payment status other than “P” for paid (see Figure
12).
Now you can rerun the CDS view by pressing the F8 key, which reveals that
the result set of the view is still raw — it contains address keys, which are
GUIDs pointing to address records, when the actual city and street names
would be more useful (see Figure 13).
On the transport request screen (Figure 15), assign the newly created view
to the open development request, and on the view template screen (Figure
16), choose Define View with Association. The syntax for this is slightly more
complicated — the association contains an “on” condition, which is similar to
a join operation.
After selecting the template, open the DDL editor to complete the view
definition. As with the first view, specify an ABAP repository name for the
corresponding ABAP view (ZV_CUSTCLSFY_201 in the example). Again, the
text label and view name are filled in automatically. Then specify a data
source for the view, which is the first view created in this example
Figure 17 — Define the view and its association in the DDL editor
Next, fill out the “on” condition defining the source and target columns that
are connected by the association. For the source, specify the first view
Zddls_E2e_Inv_Count_201 and select address_key from the displayed list of
available columns (see Figure 18). For the target, specify the target data
source (referenced as “_address”) for the association and select the
corresponding address_key from the displayed list of available columns (see
Figure 19).
Figure 21 — The completed definition of the view fields for the association
Finally, to demonstrate the versatility of CDS, let’s add a calculated field that
is based on conditions that need to be met. To define this field, manually add
a case expression (see Figure 22). The completed case expression for the
example (Figure 23) delivers a category field that assigns a certain value
depending on the number of open invoices: “C” for less than 5,000; “D” for
between 5,000 and 10,000; and “S” for more than 10,000.
Lastly, add view fields that contain address information by specifying the
target data source — “_address” (see Figure 24) — and then selecting
country, street, city, and postal code from the list of available columns (see
Figure 25).
The association details defined in the DDL editor are also integrated into the
data browser. As in the DDL editor, you can navigate along the various
associations, meaning that you can select a row and view a list of
associations, such as address (see Figure 28). Selecting an association will
display the resulting record that is referred to by the association (see Figure
29), which can be used for testing and analysis.
Figure 29 — Displaying the record referred to by the association in the data browser
Figure 30 shows our completed CDS artifacts in the Eclipse project explorer.
Summary
SAP NetWeaver 7.4 brings the CDS concept introduced for native SAP
HANA development to the ABAP development world. Powerful CDS functions
such as associations and annotations are fully integrated into ABAP in
Eclipse, and assist developers at each step of the definition process. And
since CDS is executed at runtime directly on the database layer, it facilitates
the code pushdown paradigm pioneered by SAP HANA right from the
beginning. With these features on hand — along with the CDS enhancements
included in the upcoming 7.5 release of SAP NetWeaver 2 — developers will
have the tools they need to succeed in a modern business landscape.
1 Learn more about the SAP HANA implementation of CDS at http://bit.ly/1jDYMss. [back]
2 Learn more about CDS enhancements in SAP NetWeaver 7.5 in my article “A Foundation for the
Future” in the July-September 2015 issue of SAPinsider (SAPinsiderOnline.com). [back]
Karl Kessler
Karl Kessler (karl.kessler@sap.com) joined SAP SE in
1992. He is the Vice President of Product Management
ABAP Platform — which includes SAP NetWeaver
Application Server, the ABAP Workbench, the Eclipse-
based ABAP development tools, and SAP Cloud Platform
ABAP environment — and is responsible for all rollout
activities.
A Foundation for the Future SAP Fiori Application A Guide to SAP's Development
Development in the Cloud Environments for SAP HANA
and the Cloud
In this column, SAP’s Karl Kessler
reveals what to expect with the Gain a comprehensive
upcoming release of SAP understanding of the new ways in Read this in-depth column for a
NetWeaver 7.5. He highlights the which SAP Fiori applications can be comprehensive understanding of
market changes that have built using SAP Web IDE on SAP SAP’s current main tooling
necessitated a new foundation, HANA Cloud Platform, as well as environments for supporting SAP
details... how to... HANA and the cloud, including both
desktop- and browser-based
environments. You will gain...
COMMENTS
Please log in to post a comment.
Ivan Panchev
2/23/2018 11:48:31 AM
Thank you
bose
1/7/2018 8:21:18 AM
WAa
10/3/2017 7:05:16 AM
Great article.
ahns
9/26/2017 6:49:09 AM
good
ahns
9/26/2017 6:43:05 AM
works for me
ahns
9/26/2017 6:35:37 AM
works for me
ahns
9/26/2017 6:33:53 AM
ahns
9/26/2017 6:33:26 AM
ahns
9/26/2017 6:27:49 AM
ahns
9/26/2017 6:23:52 AM
ahns
9/26/2017 6:23:35 AM
ahns
9/26/2017 6:22:36 AM
ahns
9/15/2017 8:47:45 AM
Great
Jim D
3/16/2017 1:11:33 PM
This was a great and very useful article. I was able to create CDS views with JOINS on our ECC (SAP_BASIS) 740-009.
Development system. Should we see any performance gains on ECC? If yes, are there guidelines? Multiple CPU's
required? As a test, I wrote a program to do selects from the CDS views using MARA JOINing MARC and MARC joining
MARA against ECC SELECT Joins returning the same fields. I captured actual run times and they are almost identical from
an ECC report. In ECLIPSE there appears to be a slight advantage to the CDS views. Thank you-Jim