ABAP Core Data Services
SAP S/4HANA - Best Practice Guide
PUBLIC.
Document Version: February 7, 2020
ED un simple‘ywwww.sap.com/eontactsap
cae ee ym
SAP AT SimpleTABLE OF CONTENTS
CONTRIBUTORS.
Authors
Acknowledgements...
Feedback Welcome
Raab
INTRODUCTION ..
What's new about ABAP Core Data Services...
About this Guide.
ABAP CORE DATA SERVICES.
Availability and Core Capabilities
CDS features vs. SAP Release...
Documentation Links
Development Framework..
Services Based on CDS Views... sstsennnnnnnnnnnnnnnnnininnesennnnn ssnnnnnnnsee 9
SAP Applications using CDS... sstnsennnnnnnnnnnnnnnnninnneennnnn sanmnrssssee A
BEST PRACTICES . M2
SAP Applications. 2
Custom Applications nnn seen sannnnsnnee 12
Development Rules and Governance 13
Performance Safeguarding. 4
DATABASE SPECIFICS...... 15
Goneral Remarks... 15
SAP HANA DB 16
TRAINING ... 17
APPENDIX. 18
List of changes...... 18
Figures. 18
References 18CONTRIBUTORS
Authors
Coordination
General content
SAP ABAP Platform | Gaspar Zoltan Erdelyi | gaspar
[email protected]
Bernd Kohler
[email protected]
Performance RandolfEilenberger | randolf
[email protected]
SAPHANADB [Irena Kofman rena
[email protected]
Acknowledgements
‘The authors would like to thank the following SAP colleagues for their valuable contributions:
Timm Falter
Frank Hoffmann
Jérg Maier
Carine Tchoutouo Djomo
Feedback Welcome
ABAP Core Data Services (CDS) is still a rather new technology. Therefore, this guide is “work in progress”
and an update will be published regularly.
You can help improving the content. WWe are looking forward to any type of feedback: questions, corrections,
technical insights, problem cases, user experiences, or requests for additional topics to be covered,
Please, send your comments directly to bernd,
[email protected]!INTRODUCTION
What's new about ABAP Core Data Services
‘ABAP Core Data Services* (CDS) is a data dictionary infrastructure that was introduced with SAP
NetWeaver 7.40. It allows for defining and consuming semantically rich data models. The undertying
principles are depicted in Figure 1
Application
Programming
Classic Approach Data Centric Approach
Avoid costly computation on Get the algorithm to the data
database level ‘Only transfer computation
Transfer data to application results to the application
server and compute there server
Figure 1: Principles of ABAP Core Data Services
Without CDS (labelled as “Classic Approach” in Figure 1), intensive calculations are done on the application
layer avoiding costly computations in the database. This results in rather simple SOL queries between
application and database layer. The drawback is however that lots of data needs to be transferred back and
forth between those two layers. Often, this is very time-consuming
CDS allows for a data centric approach. Intensive computations are pushed into the database by using
complex views and functions (see Section “CDS features vs. SAP Release" on page 7). Depending on the
Use case, this may dramatically reduce execution time and simplify application coding as compared to the
traditional approach
This is especially improving performance for calculations that are close to the data, by reducing the data
volume of communication between the application server and the database.
‘As shown in Figure 2, the major purpose for pushing down logic to the database is to spare on
communication costs between the application server and the database server.
ABAP Core Data Services should not be mixed up with SAP HANA Core Data Services. The latter serve
to build design-time data-persistence models in SAP HANA Extended Application Services (SAP HANA XS)
~ for both XS classic and XS advanced models (see https://help.sap.com/viewer/search?q=hana%20cds).Figure 2: Reduction of communication costs,
About this Guide
Purpose
‘The CDS framework was introduced to leverage the computational power of HANA DB. This guide gives
hands-on information on how to implement, run and optimize CDS based applications,
Agreat deal of online documentation covering CDS is already available. Whenever possible, the guide will
reference these sources rather than replicate the related information.
Note that some links are only accessible with an SAP User Account (also known as S-user ID). SAP
administrators in your company are usually able to provide one (without additional privileges).
Audience
This document is useful for the following audience:
* ITarchitects — to design CDS based applications (data structure, database layout, queries, etc.) and
guideline application development
* Application developers — to understand database capabilities and potential limitations related to CDS
+ Software quality engineers — to understand typical issues with ABAP CDS and tools for mitigating them
+ SAP Basis administrators ~ to ensure the required SAP maintenance level
+ Database administrators — to provide the correct database maintenance level and optimize the
database performance
Structure and Content
‘The guide is made up of three pars:
1) Section “ABAP Core Data Services” provides a technical overview and describes the CDS framework. In
addition, it lists some of the services provided on top of CDS and shows how it is used in SAP
applications.
2) Section “Best Practices” gives general recommendations on how to deal with CDS within SAP solutions
and home-grown applications.
3) Section ‘Database Specifics’ lists database specific recommendations and requirements when using
CDS. Maintenance levels, settings and tuning measures are clarifiedABAP CORE DATA SERVICES
Availability and Core Capabilities
‘ABAP CDS? has been an integral part of S/4HANA since it became available with version SHANA 1511. Its
benefits can be summarized as follows:
4) Semantically rich data-models ~ is declarative and close to conceptual thinking (refer to
https:/tinyurl,com/SAP-ABAP-CDS--Dats-Model for details)
2) Completely based on SQL - offers many standard SQL features like joins or build-in functions
3) Annotations - supports domain-specific annotations which can be easily evaluated by other components,
such as Uls, analytics, or OData services
4) Associations — enables simple definition of views on top of views and path expressions to navigate
along relations
5) Extensibility — allows simple extension of CDS views with fields either on model level through extensions
or on meta-model level through annotations
‘A detailed introduction to ABAP CDS is available at httos:/tinyurl.com/SAP-ABAP-CDS- Introduction
CDS features vs. SAP Release
Many CDS specific enhancements have been added to SAP NetWeaver after the framework was initially
released with SAP NetWeaver 7.40 SPOS, among them:
+ SQL joins: INVER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, CROSS JOIN
* SQL SET operations: UNTON, UNION ALL.
* SELECT clauses: WERE, GROUP BY, HAVING, AS
+ Literals, arithmetic operators, conditional expressions: +, -, *, /, NOT, AND, OR, BETWEEN,
+ Aggregate functions: ave, MAX, MIN, SUM, COUNT
+ Numeric functions: CE1L, NOD, ABS, DIV, DIVISION, FLOOR, ROUND, FLTP_TO_DEC
‘String functions: suBsTRING, LPAD, CONCAT, CONCAT_WITH_SPACE, REPLACE, INSTR, LEFT, LENGTH, LTRIM, RIGHT,
PAD, RTRIN, UPPER, LOWER
+ Byte string functions: BINTOHEX, HEXTOBIN
* Date and time functions: DATS DAYS_ BETWEEN, DATS_ADD_DAYS, DATS_IS VALID, .
‘© Special functions: CAST, COALESCE, CURRENCY CONVERSION, UNIT CONVERSION, DECIMAL, SHIFT, —
* Session variables: ss
* View extensions: new fields can be added
jon.client, $3
sion. system_date,
The following blag provides an excellent overview about the availability of certain features:
hitps:tinyurl com/SAP-ABAP-CDS-Feature-Matrix
SAP Help Portal also serves as a comprehensive source of information (see table below):
2 ABAP Core Data Services should not be mixed up with SAP HANA Core Data Services. The latter serve
to build design-time data-prsistence models in SAP HANA XSDocumentation Links
reo [SAHANA TST | syytcomSAPABAP-CDS-D0e-750 | nul com'SAP-ABAP.CDS-Nowin.750
Tet [Sanana 1610 [unytiaaniSAP-ABAP.COS Dac 761_| yu con/SAP-ABAP-ODS Non 761
762 [Sawan 1700 | unyricomSAP-ABAE.COS.Doeu-752_[ ny. com/SAP-ABAP.CDS-Nowin752
Suenana 168
z63 [Satan t608 | snytcomSAPABAE-CDS.0n0-755 | nul com/SAP-ABAP.CDS-Nowin753
i [sanana 1000 |snyurtconiSAPABAP-O0S-D500764 | wana on/SAP-ABAPLCDS Newin 754
Development Framework
CDS views are developed and maintained in ABAP in Eclipse (see Figure 3) whose textual editor provides a
rich feature set for fast development including:
Code completion
Data preview
Quickefix function
‘Syntax highlighting
Dependency analyzer
Display of CREATE statement
Figure 3: ABAP in Eclipse development framework
There is lots of information available on how to develop CDS based applications by using the ABAP in
Eclipse framework. Refer to the following links:
* Configuration: htto:help sao comdownloadinetweaveriadt'SAP ADT Configuration Guide Backend en odf
* Guides:
—_ hittps:iitinyurl.com/SAP-NW750SP16-CDS-User-Guide
—_ hittps:iitinyurl.com/SAP-NW750SP16-ABAP-in-Eclipse
+ Tutorials:
— hittps://developers.sap.com/aroup abap-cds. htm!—_ https:/iwmw.sap.com/developer/tutorials/abap-create-project htm!
— hitos://www.sap.con/developer/utorials/abap-dev-adt-create-cds-view. html
— https: //blogs.sap com/2016/09/26/core-data-services-cds-in-sap-s4-hana
Services Based on CDS Views
‘The full potential of the CDS framework is only realized by using the services built on top of it. The following
sections serve as an introduction to some of them.
Data Clients
CDS views can be easily exposed via OData by adding annotation ¢OData. publish: true to the view
definition. Figure 4 illustrates the components that participate in the exposure process. The view activation
process generates several service artefacts. Subsequently, these services are added to the SAP Gateway
service catalog (using transaction /IWFND/MAINT_SERVICE) and become thus available for consumption by
an OData client (e.g. an SAP Fiori app).
SAP Gateway Hub
oe
acthate serve
AS ABAP Backend System
Figure 4: Components and activities when exposing CDS views to ODats
|ABAP Development Tool
More information is available here:
© https:/tinyurl.com/SAP-ABAP-CDS-and-ODate
© https:/blogs.sap.com/2015/04/20/creating-odata-services-out-of-cds-views
* https:/blogs.sap.com/2018/08/13/beauty-of-odata
SAP Fiori
Based on the OData exposure of CDS described above, its then rather straightforward to create an SAP
Fiori app using the development framework SAP WEB IDE (either locally or within SAP Cloud Platform). As
depicted in Figure 5 the SAP Fiori User Interface connects to SAP Gateway using the OData services.WW
‘SAP Fo User nec
Fr Sar Tor
Figure 5: CDS consumption by SAP Fiori - architecture overview
A detailed step-by-step description on how to create such an app Is provided here:
1. https:/tinvurl.com/SAP-ABAP-CDS.Create-Fiori-Apo1
2. https:/itinvurl,com/SAP-ABAP-CDS-Create-Fiori-Apo2
Lots of information is available at the SAP Community Wiki for SAP Fiori
* https:/iwiki sen.sap.comiwiki/display/Fior/All+Things*SAP-+Fiori
SAP BusinessObjects Analysis for Microsoft Office
SAP BO Analysis for MS Office is @ business intelligence (B!) and multidimensional data analysis software.
It allows to filter and manipulate data, to identify trends and outliers right within Excel, and to share findings
in live PowerPoint presentations (Figure 6 shows an example)
Figure 6: Analysis for Microsoft Office with Excel and PowerPoint
CDS views can easily be added as @ data source, for more information refer to:
+ _https:/iblogs.sap.com/2017/05/12/consumption-of-cds-views-in-analysis-for-office
10© https://tinyurl. com/SCN-Analysis-for-MS-Office (Product tutorials)
SAP Applications using CDS
S/MHANA
In SI4HANA, ABAP Core Data Services is an essential part of the architecture. Its virtual data model (VDM)
uses ABAP CDS views to offer a simplified, easy-to-understand and harmonized data model on top of
the suite tables (but avoiding their cryptical technical names). Itis enriched with business semantics
and enables an easy consumption of the business data.
Refer to the following links for more details:
+ httos:/imww. sap.com/products/s4hana-erp/features htm| (general information related to SHANA)
© httpvihelp.sap.com/s4hana_op 1909 (central S/4HANA entry point)
© https:/blogs.sap.com/2018/01/30/implementation-patterns-for-cds-views-in-sap-s4hang
BW on HANA or BW4HANA
ABAP CDS views can also be used within an SAP BW on HANA or SAP BW/4HANA context
Refer to the following links for details: https//tinyurl,com/SAP-ABAP-CDS-and-BW,
"BEST PRACTICES
SAP Applications
SAP applications using CDS views ere extensively checked and tested on HANA DB by SAP before being
released and shipped. So, the related transactions run out-of-the-box.
In addition, we recommend the following:
1) Check the database: Lift the underlying databases to the minimum versions and patch levels specified in
Section “Database Specifics” (page 15ff.). Also, ensure that the database settings are according to the
recommendations mentioned there,
2) Update the SAP Patch Level: Apply all SAP Patches and Notes recommended for HANA DB. Refer to
Section “Database Specifics’ (page 15if.) for details
3) Keep an eye on CDS based workload: Regularly monitor the performance and workload impact of CDS
based appiications, e.g. by using the ABAP SQL Monitor (see https:/tinvurl.com/ABAP-SQL-Monitor) or
the Expensive Statement Trace,
4) Establish a remote support connection: In case SAP support is needed for the analysis of CDS related
problems, the required support infrastructure should already be in place, Refer to Section “Incident
Support” (page 15) to set it up.
In case of performance issues, refer to the database specific "Tuning Measures” within Section "Database
Specifics” (page 15ff.).If that fails open an incident using component HAN-DB.
Custom Applications
‘The benefits of the CDS framework laid out in Section “ABAP Core Data Services” (page 7) are by no means
only restricted to SAP applications. For customers, home-grown applications are an essential part of their
SAP related portfolio and workload. Many of these apps could significantly benefit from using CDS features.
For custom development, the following recommendations apply:
4) Start small: It is important to gain in-house experience with the ‘new’ database centric development
model as well as the performance and life-cycle management of CDS views. Therefore, start with a small
project that does not affect business critical transactions and gradually expand the footprint of CDS within
your SAP landscape.
2) Check the database: Lift the underlying databases to the minimum versions and patch levels specified in
Section "Database Specifics” (page 15if.). Also, ensure that the database settings are according to the
recommendations mentioned there.
3) Implement a governance process: To avoid any surprises once CDS views have arrived in the
productive environment, you should establish clear rules and checks for the development process. More
details are covered in Section “Development Rules and Governance" (page 13).
4) Ensure quality assurance: Testing with realistic data is a must for newly developed CDS-based
applications. It is highly recommended to specify annotations with respect to service qualities, data sizes,
data categories and VOM view type so that related static checks could be used.
5) Keep an eye on CDS based workload: Regularly monitor the performance and workload impact of CDS
based applications, e.g. by using the ABAP SQL Monitor (see https:/tinyurl. com/ABAP-SQL-Monitor) or
the Expensive Statement Trace.
6) Establish a remote support connection: In case SAP support is needed for the analysis of CDS related
problems, the required support infrastructure should already be in place. Refer to Section “Incident
Support” (page 15) to set it up.
In case of performance issues, refer to the database specific “Tuning Measures’ within Section “Database
Specifics” (page 15ff.)
12Development Rules and Governance
This section lists recommendation on how to pursue it
“custom development’) using CDS capabilities.
The CDS development framework offers enormous possibilities. However, the laws of physics and computer
science still apply.
house application development (also known as
‘Therefore, we advise to stick to some basic development rules:
1. General Rule
Use SQL best practices when using CDS views,
2. OLTP and OLAP
‘The idea of the Virtual Data Model (VOM) using ABAP CDS is that there is one data model for both OLAP.
and OLTP. It can happen however that traditional, existing data models do not support this. Then, the model
must be re-shaped — or secondary tables for analytical consumption must be hold redundantly,
Different authorizations of a user in the OLAP & OLTP world may require the introduction of a thin
consumption layer.
3. DB Limits
Pay attention to database limits (Section “Database Specifics’ 15tf.)
4. Complexity
+ Build ontity-relationship models before defining CDS views. Take a careful decision on normalized
models vs. redundant storage of data, in particular with respect to avoiding JOIN operations on huge
database tables.
* Restrict the complexity of CDS views depending on their usage. Follow the "SAP S/4HANA Requirements
‘for Partner Solutions: On Premise Guide" (httpsy/tinyurl.com/Sé-for-Partner-Solutions, Chapter 7.1):
“Categorize CDS Views by Using Performance Annotations and Verify Their Compliance with the
‘Associated Response Time KPIs”
A Nghrvoumetancscions [£2 [NO No
8 Winin business ogo | 5 | nly for rau sot No
° wane urtorsnacbee [545 [vee vos
> Analyical opening |= 100 [Yes Yos
x aepcaton code 6 HANA Yee Yee
This also allows certain static code checks as long as annotation @VDM. viewType is specified correctly.
* Avoid cyclic references in the definition of CDS views (to @.
prevent problems during activation), :
@ &
5. Performance @
* For secondary indices on HANA refer to SAP Note 1794297. Additional indexes can be helpful in tables
with many entries (> 1 million) for selective fields that are used as filter of frequently executed queries.
HANA secondary indices are predominantly single column indices.
13* Avoid access to compatibility views for performance-intensive applications (if runtime is critical or if
frequently executed)
+ Avoid calculated fields in WHERE-clauses and ON-clauses of CDS views, especially when tables with many
entries are involved. Calculated fields result from functions like string functions (CONCAT, RTRTH, ...) and
CASE expressions. Note that all fields provided by a table function act as calculated. For a calculated
field to be used (as fier or join condition) the values of this field for every row must be evaluated at this
point of processing. That may be very time-consuming.
+ Avoid constants in ELSE branches within CASE especially for views to be reused in joins as it potentially
limits DB optimization due to not preserving the null value. The same limitation applies to fields defined as
constant ifthe view in which they are defined is on the right side of a LEFT OUTER JOIN.
* Avoid cyclic associations or cyclic joins with involvement of left outer join, especially when tables with
many entries are involved,
+ To achieve a certain business purpose, choose the simplest CDS view possible. Do not create the all-in-
one complex view covering all demands.
* Use associations to improve performance: If they are just defined and exposed within the projection list
without direct exposition of fields, they are pure metadata; only if used in @ path expression they become
standard joins.
* IF CDS views contain LEFT OUTER JOIN relationships between tables, use the MANY TO ONE clause if
Possible. Check if UNION clauses could be safely replaced by UNION ALL without changing the semantics.
‘* Prefer UNION [ALL] over CASE expressions in the models as they allow more room for preferable choices
for the database optimizer.
6. Life-cycle management
* Ensure an identical SAP maintenance level on all involved SAP systems (development, Q&A,
production).
+ Do not rename generated views after their release to the SAP landscape.
7. Approval Process
Review your approval processes before starting CDS based development,
Consider the following
* Communicate the development rules lined out in this section
* Review and approve complex CDS hierarchies before releasing them to the SAP landscape.
+ Ensure that new CDS workloads do net impair important business processes in the same system (review
of workload management, capacity planning, etc.)
Performance Safeguarding
In case of performance issues related to the database refer to the database specific “Tuning Measures
within Section “Database Specifics" (page 1517.)
The following blogs introduce into the performance of CDS views and described how to safeguard it:
+ https://blogs.sap.com/2018/03/02/performance-of-abap-cds-on-sap-hana-at-sap-teched-2017
+ itos:ftinyurLcom/1-CDS-View.Complexity
+ tostinyurl,com/2-SOL-Optimizer-Plan-Cache
«ls: /tinyur.comy/3-Rules-for-Good-Performance
4DATABASE SPECIFICS
General Remarks
Hardware Requirements
Standard sizing with SAP Quick Sizer applies. CDS views may pose rather individual memory and CPU
requirements to the infrastructure depending on their complexity end the data volume. Tuning can only be
done hands-on. Refer to Section “SAP HANA DB” (page 16) for hints on how to improve the performance of,
CDS based queries,
Incident Support
In case of persistent database issues with a CDS Query, create an incident in the appropriate SAP database
component HAN-DB.
For analyzing CDS related issues, an SAP RI3 standard support connection is not enough as access by
ABAP Development Tools outside the SAPGUI are required. To ensure that SAP support has full access to
the system for problem determination, enable one of following remote access options:
+ WTS Connection to a desktop with the ABAP development tools installed
+ RI Support and SAP NI Connection to allow remote connection of ABAP Development Tools by SAP
Service or Development staff
Details on SAP service connections are available at https://tinyurl,com/SAP-Remote-Service-Connections.
Also, ensure that support users are authorized to execute the following transactions:
* DBACOCKPIT, STo4
* SQLMD
© STON
© SAT, ST05, S712
‘The authorization for transaction DBACOCKPIT in combination with STOS and ST12 is particularly helpful
because it allows PlanViz files to be saved — in case Plan Visualizer (PlanViz) is enabled in the system,
18SAP HANA DB
DB Levels
Itis recommended to use latest available SAP HANA DB version and patch level.
10 2021789 _| SAP HANA 1.0 Revision and Maintenance Strategy
20 2378962 _| SAP HANA 2.0 Revision and Maintenance Strategy
DB Settings
x Configuration paramotors for the SAP HANA system
DB Limits
Ayoid cyclic OUTER joins,
SAP Notes & Patches for CDS
1973033 |740 [ABAP Dictionary/CDS enhancements and corrections for SAP HANA database
234244 |750 ABAP Dictionary/DB consistency check reports errors for CDS views:
2azs642 [751 Activation error for CDS view with FLTP_TO_DEC conversion
ziszo11_|740 CDS: Incorrect resulting set for view with SUBSTRING function
SAP Life-Cycle Management
For the SAP Software Update Manager, all prerequisites (version, patches, etc.) are checked during the
initial phases of the tool
Tuning Measures
To learn about SAP HANA DB and its administration in general refer to the following links
© httos:/ihelp.sap.comiviewor/pSAP_ HANA PLATFORM
. hel jewerlp! PI
(covers monitoring, managing, and analyzing performance within the SAP HANA Cockpit)
Particularly helpful in case of database specific problems are the following sources of information.
+ httos:/wiki.waf.sap.corp/wikildisplay/SuiteCDS/CDS+View+Performance
+ SAP HANA Troubleshooting and Performance Analysis Guide available at:
htips:/tinyurl com/HANA-Performance-Analysis-2-04
16TRAINING
The table below lists SAP training options related to ABAP CDS.
8C430_| ABAP Dictionary
$4430 _| Building Views in Core Data Services ABAP_
HOS4D__| Hands-on Introduction to Application Programming on SAP S/4HANA
S/MHANA embedded analytics and Modeling Basics with Core Data
Services
S4H410
S4FO7__| Financial Reporting with SAP S/4HANA,APPENDIX
List of changes
February 2020
+ Reviewed and updated all web inks
+ Added Figure 2 (page 6)
* Added minor changes to:
Section “Audience” (page 6)
Section “CDS features vs. SAP Release” (page 7)
Section “Documentation Links" (page 8)
Chapter “Best Practices” (page 12ff)
July 2019
+ Updated section “Documentation Links” (page 8)
+ Reviewed and updated web links
January 2019
First version of this guide
Figures
Figure 1: Principles of ABAP Core Data Services. © 5
Figure 2: Reduction of communication costs 6
Figure 3: ABAP in Eclipse development framework 8
Figure 4: Components and activities when exposing CDS views to OData 9
Figure 5: CDS consumption by SAP Fiori - architecture overview 10
Figure 6: Analysis for Microsoft Office with Excel and PowerPoint 10
References
SAP Roadmaps
https:/iwww. sap com/products/roadmaps.htm!
SAP Community
https://ao.sap.com/community htm!
SAP Products
https:/iwww. sap comiproducts. htm!
ABAP Development
https://waww.sap.com/community/topies/ebap. htm
SAP Fiori / SAP User Experience
iN miproducts\fior
18