Goodbye CDS View, Hello CDS View Entity – Part 1

This article is the first part of a blog series. It explains the differences of the CDS View Entity compared to the legacy CDS View. Part two will focus on optimizations and new features.

1. Introduction

The CDS view has been deprecated by SAP. It is still supported but will not get any new features. The successor is the so-called CDS View Entity, which is a new type of CDS view. Both types can be used side-by-side or in combination with each other.

The CDS View Entity is available since ABAP release 7.55, which comes e.g. with BW/4HANA or S/4HANA 2020 or newer.

2. Differences

2.1. View Header

You can see a few differences immediately when creating a new View and comparing the header. For the legacy CDS View the template looks like this:

Please note that in the description “obsolete as of AS ABAP 7.57” is now mentioned. In the preview you can see several annotations in the header, which have become obsolete when comparing with a CDS View Entity.

Here is the template for the new CDS View Entity:

Please note the additional keyword “entity” and the change of the default annotations.

2.2. No More SQL View

To understand why some of the header annotations have been changed, it’s important to know what’s going on in the background. When activating the Design Time Object (DDLS) of a legacy CDS View, two further database artifacts are created:

  • Runtime Object (STOB)
  • SQL View (DDIC)

In contrast, a CDS View Entity will only generate a Runtime Object, but not an additional SQL View anymore. Side note: the DDLS and STOB names are always identical for a CDS View Entity, for a legacy CDS View those could have been different.

Advantages are a) simplification: fewer potential inconsistencies or confusions about different names and b) performance: faster object activation because of less dependencies.

However, there are some further implications:

  • The annotation @AbapCatalog.sqlViewName has become obsolete. Please note that this does not affect just the SQL View name, but also the name of a generated DataSource. It’s still possible to set the DataSource name in a CDS View Entity via @Analytics.technicalName.
  • The annotation @AbapCatalog.preserveKey has become obsolete as well, because it served the key fields definition of the now non-existent SQL View.
  • For a legacy CDS View you could previously access the SQL View directly e.g. in an ABAP report or as a source for a BW OpenODSView. Since there is no SQL View anymore for a CDS View Entity, you need to ensure that it’s read from the Runtime Object (ddl_source_name) instead. For usage within a BW OpenODSView it’s required to expose the CDS View as a BW DataSource first and then build on top of that.

2.3. Annotations

Besides the already mentioned @AbapCatalog.sqlViewName and @AbapCatalog.preserveKey there are further changes for some of the annotations. Here are the most noticeable ones:

  • The annotation @AbapCatalog.compiler.compareFilter defines how filters are handled so that joins may be optimized. It is not supported anymore in a CDS View Entity because it’s always implicitly set to true and cannot be changed.
  • The syntax for CDS View Extensions has changed with CDS Views Entities. In that context, the annotation @AbapCatalog.viewEnhancementCategory by default indicates that no extension is used.
  • The annotation @Metadata.ignorePropagatedAnnotations has been set to true by default because that’s now mandatory in union views. If no union is used, then it can still be changed to false, which was the previous default setting.
  • The annotation @ObjectModel.usageType is now set by default. It documents for which kind of application the View is intended and which kind of data and performance is to be expected. A discussion with SAP employees revealed that this annotation is optional, as it actually has no impact on the runtime performance, see: https://blogs.sap.com/2020/02/06/cds-view-performance-annotation-for-cds-view-performance
  • The Annotations @ClientHandling.type and @ClientHandling.algorithm are not supported anymore because the client is now handled automatically, to reduce complexity and development effort.
  • Post element annotations are allowed in CDS Views but not anymore in CDS View Entities. Therefore, element annotations must always be specified before an element. Example:
     element1 @<EndUserText.label:'name1', //valid in CDS View but not in Entity
     @<EndUserText.label:'name2' element2, //valid in CDS View and Entity
  • The element annotations @Semantics.currencyCode  and @Semantics.unitOfMeasure are not supported anymore in a CDS View Entity, instead @Semantics.amount.currencyCode and @Semantics.quantity.unitOfMeasure shall be used. Previously this specification was optional, but it’s now mandatory for data types CURR or QUAN.

2.4. Syntax Changes

  • A prefix for each single element is required when using join or association.
  • Alias names must be specified using AS, previously this was optional.
  • Access parameters via $parameters.pname, but no longer via :pname.
  • In union view, element annotations are allowed only in the field list of the first SELECT statement, but not in subsequent branches. Furthermore, the key elements must match now. Be careful with choosing a field length within the first union branch, because it will automatically apply to all further branches, and if too small then content may be cut off.
  • SELECT * to select all elements from a data source is not supported anymore. Instead $PROJECTION enables reusage of expressions from the SELECT list.
  • The function DECIMAL_SHIFT is not supported anymore in CDS View Entities. Instead, the following functions may be used: CURR_TO_DECFLOAT_AMOUNT or GET_NUMERIC_VALUE
  • The function AVG now requires to explicitly specify the data type.

2.5. Unsupported Scenario

Please note that a CDS View Entity does not support DDIC database views or DDIC external views anymore. This means it’s not possible to select, join or associate with such view types, see error message:

If you need to access those view types then this may be the one reason to prefer the older legacy CDS View, because there such scenarios still work fine.

The full CDS data source matrix can be found here:

https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_data_source_matrix.htm


Related blogs