Skip to content

ABAP Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Annotations →  ABAP CDS - Definition of Annotations →  ABAP CDS - DDL for Annotation Definitions →  ABAP CDS - DEFINE ANNOTATION 

ABAP CDS - DEFINE ANNOTATION, annotation_annot

Other versions: 7.31 | 7.40 | 7.54

Syntax

... @annotation ...

Effect

Specifies an annotation annotation as an annotation definition annotation in front of the statement DEFINE ANNOTATION or in front of a subannotation in an annotation definition in ABAP CDS. The character @ must be placed in front of the name annotation of the annotation. The annotation must be defined as a CDS object in a CDS annotation definition and the annotation definition annotation @Scope must be specified here using the value #ANNOTATION.

The annotations of an annotation definition can be specified in front of the name of the main annotation and in front of the names of subannotations. If an annotation is not specified directly in front of a subannotation, it is inherited by the next higher annotation in the hierarchy.

The following tables show the possible ABAP annotations that can be specified and their meanings. Annotations with other identifiers are usually framework-specific annotations. These are not evaluated by the ABAP runtime environment but by other SAP frameworks instead.

The first column of the table displays the (possibly structured) name annotation of an ABAP annotation and the second column displays its meaning. The third column shows the possible annotation values. The fourth column shows the value set implicitly for the annotation value if the annotation is not used explicitly. The fifth column displays the default value set implicitly for value in accordance with the annotation definition if the annotation is specified without a value. If nothing is specified for the annotation value, the annotation should be specified without a value.

AbapAnnotation Annotations

Specify how the annotation can be used.

Annotation Meaning Annotation Values Default Value if Not Used Default Value if Used Without Value
AbapAnnotation.definitionHidden Hidden annotation true:
The annotation is used for tests and demonstrations. Itis not detected using source code color and or by Code Completion and cannot be used in production CDSsource code
false:
Public annotation for use in production CDS source code
false true

API Annotations

Specify how the annotation can be released.

Annotation Meaning Annotation Values Default Value if Not Used Default Value if Used Without Value
API.state[ ] Defines how the annotation can be released. #RELEASED_FOR_SAP_CLOUD_PLATFORM:
The annotation can be used in CDS entities defined inABAP for SAP Cloud Platform.
#RELEASED_FOR_KEY_USER_APPS:
The annotation can be used in CDS entities defined inABAP for Key Users.This is not yet possible.
#NOT_RELEASED:
The annotation cannot be used in CDS entities defined in ABAP for SAP Cloud Platform.
#NOT_RELEASED -

CompatibilityContract Annotations

Define the usability of the annotation in CDS entities as specified by a release contract.

Annotation Meaning Annotation Values Default Value if Not Used Default Value if Used Without Value
CompatibilityContract.rc.usageAllowed Defines the usability in CDS entities with release contract rc. true:
The annotation can be used
false:
The annotation cannot be used
false true
CompatibilityContract.rc.allowedChanges.annotation[ ] Defines whether the annotation can be added or removed in a CDS entity with release contract rc after its release #ANY:
The annotation can be added and removed
#ADD:
The annotation can be added but not removed
#REMOVE:
Theannotation can be removed but not added
#NONE:
The annotationcannot be added or removed
#CUSTOM:
The way the annotation can be modified is defined and checked specific to the framework in question
- -
CompatibilityContract.rc.allowedChanges.value[ ] Defines whether the annotationvalues can be modified in a CDS entity with release contract rc after its release #ANY:
All annotation values can be changed as required
#UPDATE:
Specific annotation values can be changed as required
#FALSE_TO_TRUE:
Specific truth values can be changed from falseto true.
#TRUE_TO_FALSE:
Specifictruth values can be changed from true to false.
#ADD:
Annotation values can be added toannotation arrays but not removed
#REMOVE:
Annotation values can be removed fromannotation arraysbut not added
#NONE:
Annotation values cannot be modified
#CUSTOM:
The way the annotation values can be modified is defined and checked specific to the framework in question
- -

Here, the subannotation rc specifies a release contract in the annotation syntax. The following can be specified:

  • c0
The release contract C0 permits extension fields to be added at specific extension points.
  • c1
The release contract C1 guarantees a stable interface for use within AS ABAP.
  • c2
The release contract C2 guarantees a stable interface for uses outside AS ABAP too.

In annotation definitions delivered by SAP, the annotations @CompatibilityContract must be specified for the release contract C1 and C2, both for the main annotation and for every subannotation. They define the usability of the main annotations and subannotations in the CDS source code of a CDS entity with respect to their release contract. A CDS entity is mapped to a release contract using tools such as ADT or in special transactions, and not in its CDS source code.


Note

When specified, the annotation @CompatibilityContract can be governed by framework-specific conditions, such as the features of analytic frameworks that consume CDS views. SAP reserves the right to modify @CompatibilityContract if these framework-specific conditions change.


Example

Example of the use of the annotation @CompatibilityContract in an annotation definition. The annotation that follows can be used in CDS entities with the release contract c1. Here, it can added and removed even after the release of a CDS entity and the annotation values can be modified. It cannot be used in CDS entities with the release contract c0 and c2.

@CompatibilityContract: {
   c0: { usageAllowed: false },
   c1: { usageAllowed: true,
         allowedChanges.annotation: [ #ANY ],
         allowedChanges.value: [ #ANY ] },
   c2: { usageAllowed: false } }

LanguageDependency Annotations

Define the translatability of texts with the type String.

Annotation Meaning Annotation Values Default Value if Not Used Default Value if Used Without Value
LanguageDependency.maxLength Specifies that the annotation value is a translatable text. The maximum usable length of the text. The recommended length is determined by the length determined in thetype. No values greater than the recommended value can be specified. - -


Notes

  • The annotation LanguageDependency.maxLength can only be specified for annotations of String with lengths between 10 and 255. This means that it can usually only be used directly in front of subannotations of this type.

  • The value of an annotation like this is saved in special tables that have a language key and that are translatable. The value specified in the source code should consist of text in the original language of the CDS source code and is translated into the required languages. The methods of the class CL_DD_DDL_ANNOTATION_SERVICE read these texts as specified by an input parameter for the language. If no language is passed to the input parameter, the text environment language is used as the default. If no text is found for the language, the secondary language in AS ABAP is used.

MetadataExtension Annotations

Specify how annotations are moved to CDS metadata extensions.

Annotation Meaning Annotation Values Default Value if Not Used Default Value if Used Without Value
MetadataExtension.usageAllowed Specifies whether the annotation can be specified in a metadata extension when the statement ANNOTATE is used. true:
The annotation can be specified in a metadata extension
false:
The annotation cannot be specified in a metadata extension
false true


Note

Alongside @MetadataExtension.usageAllowed:true, the scope specified using the annotation @Scope determines where the annotation can be specified in a metadata extension. The scope must match the annotation and metadata extensions must be permitted for this scope.

Scope Annotations

Define the scope of the annotation.

Annotation Meaning Annotation Values Default Value if Not Used Default Value if Used Without Value
Scope[ ] Defines the scope of the annotation. #ACCESSPOLICY:
CDS access policy
#ANNOTATE:
CDS metadata extension
#ANNOTATION:
CDSm annotation
#ASPECT:
not yet documented
#ELEMENT:
Element
#ENTITY:
CDS entity
#EXTEND_VIEW:
CDS view extension
#PARAMETER:
Parameter
#PFCG_MAPPING:
PFCG mapping
#ROLE:
CDS role
#SERVICE:
not yet documented
#SIMPLE_TYPE:
currently not used
#TABLE_FUNCTION:
CDS table function
#VIEW:
CDS-View
- -

The scope of each annotation must be defined using @Scope. It determines the places in CDS source code where the annotation can be specified. @Scope is an annotation array, which means that multiple annotation values can be specified in square brackets. If no scope can be determined for an annotation or subannotation, a syntax error occurs.


This translation does not reflect the current version of the documentation.