ABAP Core Data Services-887
ABAP Core Data Services-887
ABAP Core Data Services-887
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company.
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable
for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality
mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or platform directions and functionality are
all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation
to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are
cautioned not to place undue reliance on these forward-looking statements, and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other
countries. All other product and service names mentioned are the trademarks of their respective companies. See http://www.sap.com/corporate-en/legal/copyright/index.epx for additional trademark
information and notices.
TABLE OF CONTENTS
CONTRIBUTORS ...............................................................................................................................................4
Authors ............................................................................................................................................................. 4
Acknowledgements ......................................................................................................................................... 4
Feedback Welcome ......................................................................................................................................... 4
INTRODUCTION ................................................................................................................................................5
What’s new about ABAP Core Data Services ............................................................................................... 5
About this Guide .............................................................................................................................................. 5
TRAINING ........................................................................................................................................................17
APPENDIX .......................................................................................................................................................18
List of changes .............................................................................................................................................. 18
Figures ............................................................................................................................................................ 18
References ..................................................................................................................................................... 18
3
CONTRIBUTORS
Authors
Task / expertise Name Mail address
Coordination
Bernd Kohler bernd.kohler@sap.com
General content
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. We 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.kohler@sap.com!
4
INTRODUCTION
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 SQL 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 (especially for calculations that are close to the data, by reducing the data volume of
communication between the application server and the database).
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.
A great deal of online documentation covering CDS is already available. Whenever possible, the guide will
reference these sources rather than replicate the related information.
1 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).
5
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:
• IT architects – 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
• SAP Basis administrators – to ensure the required SAP maintenance level
• Database administrators – to provide the correct database maintenance level and optimize the
database performance
6
ABAP CORE DATA SERVICES
2 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 XS.
7
Documentation Links
Release
(SAP NetWeaver / SAP Applications Link to SAP Help Portal
ABAP Platform)
S/4HANA 1511
7.50 https://tinyurl.com/SAP-ABAP-CDS-Docu-750
BW/4HANA 1.0
S/4HANA 1809
7.53 https://tinyurl.com/SAP-ABAP-CDS-Docu-753
BW/4HANA 2.0
Development Framework
CDS views are developed and maintained in ABAP in Eclipse (see Figure 2) whose textual editor provides a
rich feature set for fast development including:
• Code completion
• Data preview
• Quick-fix function
• Syntax highlighting
• Dependency analyzer
• Display of CREATE statement
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: http://help.sap.com/download/netweaver/adt/SAP_ADT_Configuration_Guide_Backend_en.pdf
• Guides:
− https://tinyurl.com/SAP-NW750SP10-CDS-User-Guide
− https://tinyurl.com/SAP-NW750SP10-ABAP-in-Eclipse
• Tutorials:
− https://www.sap.com/developer/groups/abap-cds.html
− https://www.sap.com/developer/tutorials/abap-create-project.html
8
− https://www.sap.com/developer/tutorials/abap-dev-adt-create-cds-view.html
− https://blogs.sap.com/2016/09/26/core-data-services-cds-in-sap-s4-hana
OData Clients
CDS views can be easily exposed via OData by adding annotation @OData.publish:true to the view
definition. Figure 3 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 Fiori
Based on the OData exposure of CDS described above, it is 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 4 the SAP Fiori User Interface connects to SAP Gateway using the OData services.
9
Figure 4: CDS consumption by SAP Fiori - architecture overview
CDS views can easily be added as a data source, for more information refer to:
• https://blogs.sap.com/2017/05/12/consumption-of-cds-views-in-analysis-for-office
10
• https://tinyurl.com/SAP-Analysis-for-MS-Office (Product tutorials)
S/4HANA
In S/4HANA, 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). It is enriched with business semantics
and enables an easy consumption of the business data.
Refer to the following links for more details:
• https://www.sap.com/products/s4hana-erp/features.html (general information related to S/4HANA)
• http://help.sap.com/s4hana_op_1809 (central S/4HANA entry point)
• https://blogs.sap.com/2018/01/30/implementation-patterns-for-cds-views-in-sap-s4hana
BW on HANA or BW/4HANA
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
11
BEST PRACTICES
SAP Applications
SAP applications using CDS views are 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 15ff.) for details.
3) 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.
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:
1) 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 15ff.). 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 12).
4) Ensure quality assurance: Testing with realistic data is a must for newly developed CDS-based
applications.
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.).
12
The CDS development framework offers enormous possibilities. However, the laws of physics and computer
science still apply.
Therefore, we advise to stick to some basic development rules:
1. General Rule
Use SQL best practices when using CDS views.
3. DB Limits
Pay attention to database limits (Section “Database Specifics” 15ff.).
4. Complexity
• Build entity-relationship models before defining CDS views.
• Restrict the complexity of CDS views depending on their usage. Follow the “SAP S/4HANA Requirements
for Partner Solutions: On Premise Guide” (https://tinyurl.com/S4-for-Partner-Solutions, Chapter 7.1):
“Categorize CDS Views by Using Performance Annotations and Verify Their Compliance with the
Associated Response Time KPIs”
Number
Service
Usage of Functions Aggregation
Quality
tables
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.
• 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, RTRIM, …).
• 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.
• Avoid cyclic associations or cyclic joins with involvement of left outer join, especially when tables with
many entries are involved.
13
• 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,
they are pure metadata; only if used in a 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.
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 not 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 15ff.).
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
• https://tinyurl.com/1-CDS-View-Complexity
• https://tinyurl.com/2-SQL-Optimizer-Plan-Cache
• https://tinyurl.com/3-Rules-for-Good-Performance
14
DATABASE 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 and 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 R/3 standard support connection is not sufficient 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
• R/3 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, ST04
• SQLMD
• ST03N
• SAT, ST05, ST12
The authorization for transaction DBACOCKPIT in combination with ST05 and ST12 is particularly helpful
because it allows PlanViz files to be saved – in case Plan Visualizer (PlanViz) is enabled in the system.
15
SAP HANA DB
DB Levels
It is recommended to use latest available SAP HANA DB version and patch level.
DB Settings
DB Limits
Avoid cyclic OUTER joins.
1973233 740 ABAP Dictionary/CDS enhancements and corrections for SAP HANA database
2342494 750 ABAP Dictionary/DB consistency check reports errors for CDS views
2423642 751 Activation error for CDS view with FLTP_TO_DEC conversion
2183911 740 CDS: Incorrect resulting set for view with SUBSTRING function
Tuning Measures
To learn about SAP HANA DB and its administration in general refer to the following links:
• https://help.sap.com/viewer/p/SAP_HANA_PLATFORM
• https://help.sap.com/viewer/p/SAP_HANA_COCKPIT
(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:
• https://wiki.wdf.sap.corp/wiki/display/SuiteCDS/CDS+View+Performance+-+Good+to+Know
• SAP HANA Troubleshooting and Performance Analysis Guide available at:
https://tinyurl.com/HANA-Performance-Analysis-2-03.
16
TRAINING
The table below lists SAP training options related to ABAP CDS.
Training
Title
ID
17
APPENDIX
List of changes
January 2019
First version of this guide
Figures
Figure 1: Principles of ABAP Core Data Services 5
Figure 2: ABAP in Eclipse development framework 8
Figure 3: Components and activities when exposing CDS views to OData 9
Figure 4: CDS consumption by SAP Fiori - architecture overview 10
Figure 5: Analysis for Microsoft Office with Excel and PowerPoint 10
References
SAP solutions
http://go.sap.com/solution.html
http://solutionexplorer.sap.com
SAP Community
https://go.sap.com/community.html
SAP Products
https://www.sap.com/products.html
SAP NetWeaver
https://go.sap.com/community/topic/netweaver.html
18