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, type
Other versions:
7.31 | 7.40 | 7.54
Syntax
... dtype [enum { SYMBOL1; SYMBOL2; ... }] [default val|#SYMBOL]
Effect
Defines the annotation values to be specified when a CDS annotation defined using define annotation is used.
dtype is used to define the type. The following tables show the possible options for dtype and their meaning for the annotation values. dtype and any predefined values are case-sensitive.
Value Types
dtype | Annotation Value |
---|---|
Boolean | Truth values true and false. |
Decimal(len,dec) | Numeric literal without quotation marks and with an optional decimal point and a maximum of len minus dec integer digits and a maximum of decdecimal places. A number between 1 and 31 can be specified for len anda number between 0 and 14 can be specified for dec, but dec cannot be greater than len. |
DecimalFloat | Numeric literal without quotation marks. The same values can be specified as in the source fieldof an ABAP conversion from c to decfloat34 |
Integer | Numeric literal without quotation marks and decimal separator in the value range of the ABAP type i . |
String(len) | Character literal in quotation marks with a maximum length len. A number between 0 and 1298 can be specified for len. |
Reference Types
dtype | Annotation Value |
---|---|
AssociationRef | Name of a CDS association |
ElementRef | Name of an element |
EntityRef | Name of an entity |
KeyElement | Name of a key field |
ParameterRef | Name of a parameter |
When used, the annotation value of a reference type must be specified as a character literal in quotation marks and without blanks. The object specified must exist.
enum { SYMBOL1; SYMBOL; ... } can be used to specify a semicolon-separated (;) list of enumeration symbols SYMBOL1, SYMBOL2, ... in uppercase letters and in curly brackets. A semicolon must also be placed after the final entry in the list here. When an annotation is used, only one of the enumeration symbols prefixed with the # character can be used as an annotation value. If enumeration symbols are specified for the type String, the symbols become the enumeration values explicitly. In this case, the length specified for String must be at least as long as the longest enumeration symbol.
default can be used to specify a type-friendly default value applied when an annotation is used and no explicit annotation value is specified. The following applies here:
- Only true can be specified as a default value for the type Boolean.
- If enumeration symbols are defined, the default value of one of these symbols must be prefixed with the # character.
- No default value can be specified for reference types.
- No default values can be specified for the elements of an annotation array.
Notes
- The truth values for the type boolean can also be specified as 'true' and 'false' in quotation marks.
- The smallest feasible size is 1 for one character.
- The default value defined using default describes the default value applied when the annotation is used in its framework. If an annotation is not used, there can be another default value (described in the documentation of the annotation). The default value of the annotation definition is ignored when the annotation is saved and evaluated internally.
Example
The following annotation definition dictates truth values as possible annotation values of the annotation:
define annotation DemoAnnoBoolean : Boolean;
The annotation can be used as followed in CDS source code:
- @DemoAnnoBoolean: true
- @DemoAnnoBoolean: false
- @DemoAnnoBoolean: 'true'
- @DemoAnnoBoolean: 'false'
Example
The following annotation definition dictates enumeration values as possible annotation values of the annotation. In the case of the type String, the enumeration symbols are also the enumeration values and a length of at least 10 must be specified for the type, since the longest enumeration symbol as 10 characters.
define annotation DemoAnnoEnum : String(10)
enum{SHORT_TEXT;TEXT;LONG_TEXT;};
The annotation can be used as followed in CDS source code:
- @DemoAnnoEnum: #SHORT_TEXT
- @DemoAnnoEnum: #TEXT
- @DemoAnnoEnum: #LONG_TEXT
Example
The following annotation definition dictates numeric literals as possible annotation values of the annotation (a default value is defined here).
define annotation DemoAnnoDefault : Integer default 0;
The annotation can be used as follows in CDS source code, with and without a value being specified:
- @DemoAnnoDefault
- @DemoAnnoDefault: 100
Example
The following annotation definition has incorrect syntax. The length of the specified default value must be at least 3.