Using ABAP Annotations in CDS Views

Objectives

After completing this lesson, you will be able to:

  • Use ABAP annotations in CDS views
  • Work with translatable texts in CDS

ABAP Annotations for CDS Views

SAP annotations are CDS annotations created and delivered by SAP. Dependent on the evaluation, we distinguish two groups of SAP annotations: ABAP annotations and framework-specific annotations.

ABAP annotations

ABAP annotations define technical and semantic attributes of a CDS object. They are evaluated when the object defined in the CDS source code is activated or when the object is used in the ABAP runtime environment. ABAP annotations can modify the behavior of ABAP SQL statements that access a CDS object.

Framework-specific annotations

Framework-specific annotations define the technical and semantic properties of CDS objects that are required by specific software components, such as ODATA, UI, Analytics, and so on. They are evaluated by the frameworks of the corresponding software components using a suitable API and are not relevant for activations and the ABAP runtime environment.

Dependent on the scope, we distinguish five groups of annotations:

Entity annotations

Annotations for CDS views and CDS view entities. Placed in front of the DEFINE VIEW statement or the DEFINE VIEW ENTITY statement.

Element annotations
Annotations for an element of the SELECT list of a CDS view. Placed in front of the element.
Parameter annotations
Annotations for a parameter of a CDS view. Placed In front of the parameter.
Extension annotations
Annotations for a CDS view extension. Placed in front of the EXTEND VIEW statement or the DEFINE VIEW ENTITY statement.
Function annotations
Annotations for a CDS table function. Placed in front of the DEFINE TABLE FUNCTION statement.

Important ABAP Annotations for CDS View Entities

For CDS view entities, the following important ABAP annotations exist:

AbapCatalog.dataMaintenance

Can be used to restrict data preview for a CDS view entity.

ABAPCatalog.viewEnhancementCategory

Specifies how the view entity is extended using CDS view extensions. A comma-separated list of values can be specified in the square brackets of the annotation array.

AccessControl.authorizationCheck

Defines the implicit access control when ABAP SQL is used to access the CDS view.

ObjectModel.usageType.<...>

Characterize CDS view entities with respect to their performance-relevant properties.

AbapCatalog.entityBuffer.definitionAllowed

Can be used to enable or disable table buffering for a CDS view entity.

ABAP Annotations for View Elements

Most Semantics annotations are just this: semantic information to be evaluated by the frameworks that build on top of CDS.

There are only a few annotations in the Semantics category, which are ABAP annotations.

In CDS view entities, it is mandatory to use the annotation @Semantics.amount.currencyCode to link amount elements (predefined dictionary type CURR) to a currency code element (predefined dictionary type CUKY). In the same way, it is mandatory to use annotation @Semantics.quantity.unitOfMeasure to link quantity elements (predefined dictionary type QUAN) to a unit element (predefined dictionary type UNIT). Without these annotations, a user of the CDS entity will have difficulties correctly interpreting and processing the values provided in these fields.

ABAP Annotations for Translatable Texts

ABAP annotations starting with EndUserText are used to define translatable semantic texts for CDS objects.

EndUserText.label is available as view annotation or as element annotation. The value is limited to a length of 60 characters.

EndUserText.quickinfo is only available as element annotation. The value is stored as a string and can have an arbitrary length.

Note
When a view element is based on a dictionary data element, the CDS framework derives a label and a quickinfo from the Field labels that are maintained in data element. For such fields the text annotations are only needed, in case you want to override the texts that come from the data element.

Active Annotations View

The Active Annotations view summarizes the semantic information of the CDS entity and its elements. It lists all entity and element annotations contained in the data definition. It also lists semantic information that is derived (inherited) from other repository objects, for example dictionary table definitions and data elements.

To open the Active Annotations view, proceed as follows:

  1. Right-click Data Definition. (Either in the editor window or in the Project Explorer.)
  2. Choose Open WithActive Annotations.

In the default configuration of the ABAP perspective, the Active Annotations view is displayed in a new tab in the tabstrip below the editor view.

In the example above, you can see that element AnnualSalary of CDS view entity Z00_R_Employee has a label Annual Salary that is not defined in the CDS data definition. This label is derived (inherited) from the source field in database table Z00_EMPLOYEE and originates from data element Z00_SALARY, with which the table field is typed.

How to Use ABAP Annotations in CDS Views

Play the video to see how to use ABAP annotations in CDS views.

Log in to track your progress & complete quizzes