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, subannos
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [@annotation_annot1]
[@annotation_annot2]
...
subAnno1{:
type;}|{[:]{subannos}[;]}|{:array of
arrelem};
[@annotation_annot1]
[@annotation_annot2]
...
subAnno2{:
type;}|{[:]{subannos}[;]}|{:array of
arrelem};
...
Effect
Structures a CDS annotation using subannotations subAnno1, subAnno2, ... . The subannotations are defined in a semicolon-separated list in curly brackets { ... } in the statement define annotation (a semicolon must be placed after the final entry in the list too). The names of the subannotations of an annotation must be unique.
Each subannotation is specified using the same syntax as when the main annotation is specified after define annotation. This means the following:
- The name of the subannotation can contain letters, numbers, and underscores only and must start with a letter.
- type can be used to define the possible annotation value for a subannotation
- A subannotation can itself be structured using further subannotations subannos
- A subannotation can be defined as an annotation array of array elements arrelem using array of
Annotation definition annotations @annotation_annot1, @annotation_annot2, ... can be specified in front of each subannotation. These annotations override any identically named annotation definition annotations specified for the structured annotation itself. Any annotations not specified directly in front of a subannotation are inherited by the next higher annotation in the hierarchy.
Notes
- Colons (:) in front of the opening curly bracket and semicolons (;) after the closing curly structuring bracket { ... } are optional.
- In the annotation syntax, structured annotations are specified either using comma-separated lists in curly brackets or using structured names.
Example
Defines a structured main annotation DemoAnnoMain with three subannotations, two of which are themselves structured. The semicolons after the closing curly structuring brackets are omitted here.
define annotation DemoAnnoMain{ subAnno1: Boolean;
subAnno2{ subsubAnno1:String(3);
subsubAnno2:Integer;}
subAnno3{ subsubAnno1:String(3);
subsubAnno2:Integer;} }
The annotation can be used, for example, as followed in CDS source code:
subAnno2:{subsubAnno1:'X',
subsubAnno2:100},
subAnno3:{subsubAnno1:'Y',
subsubAnno2:200} }
The exact same result can be achieved as follows:
@DemoAnnoMain.subAnno2.subsubAnno1:'X'
@DemoAnnoMain.subAnno2.subsubAnno2:100
@DemoAnnoMain.subAnno3.subsubAnno1:'Y'
@DemoAnnoMain.subAnno3.subsubAnno2:200