Core Data Services

  1. Structure of the VDM
  2. View types, naming conventions and possible uses
  3. Classification of CDS Views
    1. Supported Functions
    2. Modeling patterns
  4. CDS View Modeling Options
    1. Type definitions
      1. Simple Types
      2. Enumerated Types
  5. Table Functions
  6. Annotations
    1. Syntax
    2. SAP Annotations
  7. Data Definitions
    1. What are Data Definitions?
    2. DDIC-based views - OBSOLET
    3. View Entities
    4. Projection Views
    5. Table function
    6. Hierarchies
    7. Custom Entities
    8. Abstract Entities
    9. External Entities
    10. Tuning objects
  8. Access Control
    1. Properties
  9. Associations
  10. Extensibility
    1. Stability contracts
    2. Extensions of SAP standard CDS views
  11. BW integration, embedded analytics and ODP
    1. Requirements for the transfer to SAP BW/4HANA
    2. Requirements for Embedded Analytics
    3. How ODP works
  12. Tips and Tricks

What are CDS Views and why are they important? In SAP S/4HANA, the developer should no longer access the databases directly, but rather use the Virtuelle Datenmodell (VDM) to access the data in SAP S/4HANA, e.g. for analytics or interfaces. The VDM is represented in SAP S/4HANA by CDS views. These CDS views follow fixed rules for modeling and naming. They represent business data from database tables based on business logic, making the data easier to use. CDS Views are the key elements for on-stack extensibility or also ABAP Cloud - see Chapter Clean Core. The use and extension of a data model is the key to the VDM concept. CDS Views are used for many purposes, such as an interface between different applications and add-ons in the same system as well as to external systems and applications. You can also create your own views by using the views provided and shared by SAP as a data source, following the Clean Core thought.

Structure of the VDM

CDS overview

Source: SAP Help representation of the VDM

Various CDS view layers are placed in front of the database tables. For example, the VDM ensures that the database fields are understandable and the user can identify the proprietary SAP data model, for example MARA-MATNR, as a product number. The Basic Interface Layer accesses the database. The Composite Interface Views combine logic and basic interface views; the VDM can contain different abstraction layers. The consumption views expose the data model for the use case.
As part of the ABAP RESTful Application Programming Model (RAP), SAP also provides further definitions of terms, e.g. Business Object Projection Layer.

Here is a list of the view types. All standard views also include the identifier/annotation:

@VDM.viewType:[..]

View types, naming conventions and possible uses

View Type / Suffix Description Annotation
I_* Basic and composite interface views: These CDS views are used to read data and can be used for extensions. @VDM.viewType: #BASIC @VDM.viewType: #COMPOSITE
C_* Consumption views: Restricted reusable views. @VDM.viewType: #CONSUMPTION
P_* Private views: These views must not be used, as SAP may modify them during system upgrades. @VDM.private: true
R_* Views for transactional processing: These CDS views enable not only reading data, but also actions such as creating, changing or deleting instances of a RAP business object in the context of the ABAP RESTful application programming model (RAP).  
A_* Remote API views: These CDS views form the basis for external APIs. For more information about APIs, see SAP Business Accelerator Hub. @VDM.viewType: #CONSUMPTION @VDM.lifecycle.contract.type: #PUBLIC_REMOTE_API
X_* View extensions: These CDS views can only read data indirectly in the context of another CDS view. They provide access to industry or country/region specific fields defined by SAP. @VDM.viewExtension: true
E_* Extension Include Views: These CDS views can only read data indirectly in the context of another CDS view. They provide access to custom fields created in the Custom Fields app. See section “Extensions to SAP Standard CDS Views” @VDM.viewType: #EXTENSION
F_* Derivation functions: Derive context-specific values that can be used to restrict data in analytical queries. For more information, see Derivation Functions for Finance  
D_* Abstract Entities: Form the basis for modeling event signatures and action parameter/outcome structures.  

In addition, the identifier is used as a suffix depending on the intended use of the CDS view.

Suffix View Type Annotation
Query, Qry, Q Analytical query view @VDM.viewType: #CONSUMPTION
@Analytics.query: true
Cube, C Analytical cube view @Analytics.dataCategory: #CUBE
Text, Txt, T Provider of language-dependent text @ObjectModel.dataCategory: #TEXT
TP View for transactional processing @VDM.usage.type: [ #TRANSACTIONAL_PROCESSING_SERVICE ]
VH, StdVH (By default) View for value help @ObjectModel.dataCategory: #VALUE_HELP

CDS views can be used for many different purposes, such as creating Fiori applications or analyzing data. You can create your own CDS views using many views released by SAP. To make it easier for you to find the right CDS view, SAP has introduced two features: supported functions and modeling patterns. These features are specified as annotations and can be defined for each CDS view. You can see the supported functions and modeling patterns of CDS views in the View-Browser App. In the ABAP Development Tools you will find this information as an annotation at the beginning of each CDS view.

For more details, see SAP Help

The following SAP community page ZSCV_SEARCH_CDS_VIEWS offers an open source solution for searching CDS views.

Classification of CDS Views

Supported Functions

According to SAP, the supported functions indicate the best use cases for a CDS view. A CDS view can have multiple supported functions, as it may be suitable for various purposes.

These features describe the best use of a CDS view. For example, you can use a CDS view as:

  • Datenquelle
  • Target for joins in CDS modeling
  • Data provider for analytical queries

The supported functions of a CDS view are specified in a single annotation:

@ObjectModel.supportedCapabilities: [ ..., ... ].

Modeling patterns

A modeling pattern describes the main purpose of a CDS view. A CDS view can only have one modeling pattern. The value of the modeling pattern may or may not be equal to the value of a supported function.

The annotation for a modeling pattern looks like this:

@ObjectModel.modelingPattern: ...

CDS View Modeling Options

This section describes the various type definitions, function definitions, and data models within ABAP Core Data Services. It explains basic types, SQL-based functions (scalar functions), and various view types, such as DDIC-based views, view entities, and projection views. This is supplemented by advanced concepts such as table functions, hierarchies, custom, external, and abstract entities, as well as tuning objects for optimizing CDS models.

Type definitions

Simple Types

This allows you to define elementary data types that you can use in CDS objects or in ABAP.

Beispiel

define type myDate : abap.dats

Details finden Sie unter SAP Help (CDS Simple Types)

Enumerated Types

Define an enumerated type with constants. You can use the type and constants in CDS objects.

Beispiel

Definition

define type Weekdays : abap.int1 enum
{
    Monday = initial;
    Tuesday = 1;
    Wednesday = 2;
    Thursday = 3;
    Friday = 4;
    Saturday = 5;
    Sunday = 6;
}

Usage

define ... as select from ...
{
    ...
}
where
  weekday = Weekdays.#Friday

Details can be found in SAP Help (CDS Enum Types)

Table Functions

Currently, SAP only supports the definition of a scalar function. There are two different types of functions.

  • Analytical scalar functions
    • This type of function can currently be defined only by SAP. However, you can use the functions that SAP provides.
  • SQL-based scalar functions
    • You can define and implement your own functions of this type. The usage is like the built-in SQL functions (such as CONCAT()). A scalar function can have multiple parameters and always has a single return value.
    • You need three development objects for a scalar function:
      • A scalar function definition (CDS object)
      • A scalar function implementation reference, as a link between the definition and the implementation
      • A AMDP Function representing the implementation of the scalar function

Details finden Sie unter SAP Help (CDS-Skalarfunktionens)

Annotations

Annotations can appear anywhere within a CDS object. Where exactly an annotation can or may be specified depends on the annotation itself. Annotations are intended to enrich the CDS object with metadata that can then be interpreted by a user. For example, you can add annotations to a CDS View Entity that can ultimately be evaluated by a Fiori Elements app (using an OData service as an intermediate step).

It is even possible to define your own CDS annotations.

Details dazu finden Sie unter SAP Help (CDS - Definition of Annotations)

Syntax

To specify an annotation, use the following syntax:

@[<]Anno[: value ]
       |[: { subannos } ]
       |[: [ arrelem ] ]
       |[.subAnno[ ... ]]

Beispiel

@MainAnnotation.SubAnnotation: 'Value'

Details finden Sie unter SAP Help (CDS DDL - Annotation Syntax)

SAP Annotations

SAP has already defined a wide range of annotations that can be used. These cover various areas and aspects.

A large part are the ABAP Annotationen (SAP Help). This allows, among other things, metadata to be specified about the type of data, data access, expandability and semantics of data. These annotations are evaluated by the ABAP runtime.

Beispiel

...
@Semantics.currencyCode
Currency,
...

There are also framework-specific annotations (SAP Help). These can define metadata for OData services, user interfaces, or analytics. Such annotations are interpreted by a framework rather than by the ABAP runtime; Fiori Elements is a prominent example.

Beispiel

...
@UI.lineItem: [{ position: 10 }]
Field,
...

Data Definitions

What are Data Definitions?

Data Definitions are CDS entities created in the ABAP Development Tools (ADT). They define the structure and behavior of data models based on database tables or other CDS views. They make it possible to model data in an abstract, semantically rich way, regardless of the underlying database technology.

DDIC-based views - OBSOLET

As of Release 7.55, DDIC based views have been replaced by view entities, which are no longer dependent on DDIC objects. Please use the View Entities.

A DDIC-based view can be created for DDIC database tables, DDIC views, and other CDS views. When defining the view, you must specify an SQL view name via an annotation, which is created in the ABAP Dictionary as a DDIC view. When the CDS view is activated, a CDS entity and the annotated DDIC view are created or updated. You access the data of the referenced objects via SQL.

Beispiel

@AbapCatalog.sqlViewName: 'CDS_DB_VIEW'
define view ddic_based_view as select from ...
{
  field,
  ...
}
where
  field = 'ABC'

Details finden Sie unter SAP Help (CDS DDIC-Based Views)

View Entities

With a CDS view entity you can access fields of a data source (database tables, other CDS entities), as well as: perform calculations, define relationships, enrich metadata with annotations, etc. The view entities serve as the basis for the ABAP Data Models and are used by the ABAP RESTful Application Programming Model. So they are an important component for a modern ABAP development.

Beispiel

view entity view_entity as select from ...
{
  field,
  ...
}
where
  field = 'ABC'

Details finden Sie unter SAP Help (CDS View Entities)

Projection Views

A projection view is based on another CDS view entity and is used for service-specific use cases. These include:

Details finden Sie unter SAP Help (CDS Projection Views)

Table function

A table function consists of two parts. A CDS entity, which can be used for example with the CDS view entities or projection views, and a AMDP Function, which represents the implementation of the function. The result of a table function is data sets. An AMDP function can only be used in an environment whose database system supports AMDP (e.g. SAP HANA). With the AMDP Function you can apply platform-specific SQL commands. The advantage is that you can perform specific queries on the database and provide the results as a data source for other CDS entities.

Details can be found in SAP Help (CDS table function)

Hierarchies

This type of CDS view allows you to provide hierarchical data. Only parent-child hierarchies are supported. You must specify a CDS view entity as the basis, which has an association with itself. This association describes the relationship to the parent node. In the field list, you can specify fields of the CDS view entity and special hierarchy attributes, such as the entry’s level in the hierarchy.

Details finden Sie unter SAP Help (CDS Hierarchies)

Custom Entities

CDS Custom Entities are non-SQL entities, meaning they do not create an SQL view in the HANA database. Custom Entities are linked to an ABAP class via an annotation, in which you can implement business logic and data queries that go beyond SQL, such as data in a file, a BLOB, or from a web service. To actually access the data, you must create an ABAP class that implements a specific interface. In the definition of the CDS Custom Entity, you must specify the class using an annotation. You also define possible input parameters and the resulting field list there.

However, the use of CDS custom entities is limited. You cannot use them in connection with SELECT statements, i.e., neither in another CDS view nor via ABAP SQL. You can, however, define associations on them and make them available in the field list. In general, custom entities are processed by the RAP Query Engine, and when a query is executed—for example, in connection with an OData service.

Details finden Sie unter SAP Help (CDS Custom Entities)

Abstract Entities

CDS abstract entities are a type of non-SQL entity. You can use them as complex data structures for RAP actions, RAP functions, and RAP business events. In other CDS views, you can only define associations for these entities. However, you cannot access them via SQL or view their contents.

Details finden Sie unter SAP Help (CDS Abstract Entities)

External Entities

CDS External Entities offer a modern way to manage secondary database connections in ABAP Cloud. They enable ABAP programs to retrieve and process data from other database systems using SQL. Unlike traditional secondary connections, which are limited to SAP HANA databases, CDS External Entities support connections to various database systems, including SAP S/4HANA Cloud, SAP BTP ABAP Environment, and SAP HANA Cloud, based on SAP HANA Smart Data Access technology.

Details finden Sie unter SAP Experten Blog: )

Tuning objects

Currently SAP only offers one configuration type: Define View Entity Buffer. This allows data buffering to be defined (no buffering, single record, ranges, complete). This setting can impact performance.

Performance details can also be found here: See SAP Help pages SQL Hint and Tuning Objects

Access Control

Using access controls, you can define which users or user groups have access to specific data by specifying roles, rules, and conditions. CDS views provide access controls via Data Access Controls / Data Control Language (DCL), similar to the traditional authority check.

Properties

Access controls in CDS allow you to precisely define which records are accessible to each user.

  • These access controls work in conjunction with the usual SAP permission objects.
  • SAP authorization objects always refer to a specific field in a table and an activity, such as creating, changing or displaying data.
  • Access to a CDS View is controlled via the so-called Data Control Language.

Whether access control is applied is determined by the following annotation:

@AccessControl.authorizationCheck: []

The standard VDM always includes access controls. A common approach is to inherit the access controls from the underlying CDS views into your custom CDS views.

Beispiel

define role ZC_BusinesspartnerAddress_DAC {
    grant select on ZC_BusinesspartnerAddress_Custom  
        where inheriting conditions from entity C_BusinesspartnerAddresstp_2;
}

There are other features you can check out here: SAP ABAP CDS - Access Control Documentation

Using transaction SACMSEL, authorization check results can be displayed in a simplified manner.

Associations

Associations can be used to link CDS entities. The source is always the CDS view entity itself. DDIC tables and other CDS entities can be defined as targets. The cardinality and the link condition are important. Cardinality determines the relationship, e.g., 1:1 or 0:n. The condition determines which fields connect the source and the target. An association is always defined in only one direction. If you want to link two entities in both directions, you must specify the association to the other entity in both of them. The association can also be specified in the field list, allowing users to access the association as well.

Beispiel

association [0..*] to OtherView as _Other on _Other.ForeignKeyField = $projection.KeyField

Attention! From release 2023, a different syntax will be used. See blog post

Details finden Sie unter SAP Help (CDS View Entity, SELECT, Associations)

A special form of the association is a so-called ASSOCIATION TO PARENT. This allows you to define a CDS entity as a parent entity. This is particularly relevant in the context of RAP. The association in the other direction, i.e. to the child entity, is defined using COMPOSITION. You must first enter the association to the parent entity and only then can you enter the association to the child entity.

For details see SAP Help (ASSOCIATION TO PARENT) and SAP Help (COMPOSITION)

Extensibility

Stability contracts

To ensure the reliable use of CDS views, SAP has introduced three stability contracts (release contracts). These contracts define how CDS views can be used in different usage scenarios:

  1. Contract for Extensions (C0): For the use and adaptation of existing views.
  2. Contract for system-internal use (C1): For views within the same system.
  3. Agreement for Remote API Use (C2): For the use of Views by external systems and applications.

For more information, see Stability contracts for CDS views.

Extensions of SAP standard CDS views

A big advantage is the ability to expand any CDS views with the contract for extensions (C0) and higher. A CDS view classified with the C0 contract for extensions provides stable points for extensions. SAP guarantees stability, so S/4HANA upgrades cannot result in incompatible changes. But this also poses a danger! For example, if you use fields from an existing CDS view in your extended CDS view (ZE_), then these can be changed during S/4HANA upgrades. Make sure to only “add” CDS views in the designated E_ CDS views. We recommend this Learning Journey by SAP, the facts are explained here.

BW integration, embedded analytics and ODP

The Operational Data Provisioning Framework (ODP) enables the transfer of data from various SAP repositories to SAP BW, SAP BW/4HANA and other systems or services. CDS Views can serve as a source for data extraction.

Requirements for the transfer to SAP BW/4HANA

The classic CDS View or CDS View Entity should have the following annotations:

  • @Analytics.dataCategory
  • @Analytics.dataExtraction.enabled

Requirements for Embedded Analytics

Embedded analytics is not limited to analytical Fiori apps or key-user extensibility apps. Through the Online Analytical Processing (OLAP) engine, CDS views can also be consumed directly by business-intelligence tools, particularly SAP Analytics Cloud (SAC) and Analysis for Office (AO).

For more information, see in this blog entry.

Here would be the structure to consume a CDS view directly from the SAC, for example. To do this, two additional CDS views must be created and provided with the annotation.

  1. Composite CDS View (Entity) @Analytics.dataCategory: #CUBE / '#FACT / #DIMENSION
  2. Consumption CDS View (Entity) @Analytics.query: true

CDS overview Musteraufbau: Direkter Zugriff vom SAC

It should be noted that a contract for system-internal use (C1) must be assigned for the Consumption CDS View. In addition, the following authorization objects are required in the user roles.

S_RS_COMP
		RSINFOAREA   *
		RSINFOCUBE   *
		RSZCOMPTP		REP (for analytical reporting) / SOB (for planning functions)
		RSZCOMPID		2C<SQLViewName of Analytical Query>
		ACTVT				03, 16

S_RS_COMP1
		RSZCOMPID		2C<SQLViewName of Analytical Query>
		RSZCOMPTP		REP (for analytical reporting) / SOB (for planning functions)
		RSZOWNER		 * (Only in the catalog role not in authorization default)
		ACTVT				03,16
  
S_RS_AUTH
		BIAUTH		  0BI_ALL

For more information, see SAP Help Portal.

How ODP works

The ODP interface enables access to transaction data and master data (attributes, texts, hierarchies). The SAP BW/4HANA system subscribes to operational delta queues and replicates the data. The data change sources also support delta processes.

For more information, see SAP Help Portal.

Tips and Tricks

  1. Performance Tracing - Always examine every CDS view! No matter whether SAP standard or self-created. You can trace the SQL execution using an SQL trace in ST05. To do this, you must extract the .PLV file and display it in Eclipse. This allows you to analyze time distributions and execution plans. Be sure to check the total number of records returned to identify design issues. See DSAG Eclipse ADT Guides - Performance “Selecting a concrete selection”
  2. Massive JOINs and complex queries - For massive JOINs (e.g. 7-14 tables), CDS views can be more efficient by splitting them into layers with associations to improve performance. For complex queries, CDS views allow code pushdown, but be careful with AMDPs on large tables (>1 million entries) as this can impact performance. Please note that AMDPs select per table row. What selection do you have going into the AMDP?
  3. Fast Queries - Keep selections small and specific to optimize performance and avoid AMDPs on large tables to speed up database access. We recommend the Note 2000002 - FAQ: SAP HANA SQL Optimization. If the optimization should take place on the SQL engine itself, please use this page HINT Details.
  4. Check for potential SAC queries – For recurring, user-defined data queries, BAPIs, function modules, or ABAP SQL are often more suitable, since CDS views are intended for standardized, reusable models. CDS views are extremely useful for SAC reports, as they can be consumed directly by SAC.
  5. Providing data to subsystems - RAP can be used to expose CDS Views as OData Services, which is ideal for providing data to subsystems. This provides modification-free extensibility, especially in Cloud environments. See chapter ABAP - RAP

← Solution approach Modern ABAP Development →

This site uses Just the Docs, a documentation theme for Jekyll.