SAP CDS F1 DEFINE ANNOTATION TYPE



Get Example source ABAP code based on a different SAP table
  


• DEFAULT ABAP_CDS_DEFINE_ANNO
• ENUM ABAP_CDS_DEFINE_ANNO

ABAP_CDS_DDL - DEFINE ANNOTATION, type

ABAP_SYNTAX
... dtype $[enum { SYMBOL1; SYMBOL2; ... }$] $[default val$|#SYMBOL$]

What does it do?
Defines the annotation values to be specified when a CDS annotation defined using define annotation is used in a CDS entity.
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 dtypeAnnotation Value
BooleanTruth 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 dec decimal places. A number between 1 and 31 can be specified for len and a number between 0 and 14 can be specified for dec, but dec cannot be greater than len.
DecimalFloatNumeric literal without quotation marks. The same values can be specified as in the source field of an ABAP conversion from c to decfloat34
IntegerNumeric 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 dtypeAnnotation Value
AssociationRefName of a CDS association that is exposed in the SELECT list where the annotation is used. If the association is defined in the same CDS entity, the annotation value must be the association's name. If the association is defined in another entity, the annotation value must be a path expression.
ElementRefName of an element of the CDS entity where the annotation is used. For elements of association targets, the annotation value is a path expression.
EntityRefName of any CDS entity.
KeyElementName of a key field of the CDS entity where the annotation is used.
LocalDefinitionRefName of a data source of the current CDS entity. The data source can either be defined after FROM or as an association. If an alias name is specified for the data source, this alias name must be specified as annotation value.
ParameterRefName of a parameter of the CDS entity where the annotation is used.
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 enumerated 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-compliant 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.



Latest 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.
ABAP_HINT_END

ABAP_EXAMPLE_VX
The following annotation definition specifies truth values as possible annotation values of the annotation:
DDLA DEMOANNOBOOLEAN
The annotation can be used as followed in CDS source code:
@DemoAnnoBoolean: true
@DemoAnnoBoolean: false
@DemoAnnoBoolean: 'true'
@DemoAnnoBoolean: 'false'
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX
The following annotation definition specifies enumerated values as possible annotation values of the annotation. In the case of the type String, the enumeration symbols are also the enumerated values and a length of at least 10 must be specified for the type, since the longest enumeration symbol as 10 characters.
DDLA DEMOANNOENUM
The annotation can be used as followed in CDS source code:
@DemoAnnoEnum: #SHORT_TEXT
@DemoAnnoEnum: #TEXT
@DemoAnnoEnum: #LONG_TEXT
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX
The following annotation definition specifies numeric literals as possible annotation values of the annotation (a default value is defined here).
DDLA DEMOANNODEFAULT
The annotation can be used as follows in CDS source code, with and without a value being specified:
@DemoAnnoDefault
@DemoAnnoDefault: 100
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX
The following annotation definition has incorrect syntax. The specified length 1 is not sufficient for the specified default value of length 3. annotation DemoAnno : String(1) default 'XXX';
ABAP_EXAMPLE_END