What does it do? The statement define annotation> defines a CDS annotation> with the name Anno > in the CDS DDL> in the DDLA source code>. The annotation Anno> is the main annotation> of the current annotation definition> , which can be structured with optional subannotations>. The DDLA source code of an annotation definition can contain the definition of exactly one main annotation, whose name must match the name of the DDLA> source code. The names are case-sensitive. Annotations of the definition annotation, @annotation_annot1> >, @annotation_annot2>>, ..., can be specified before the statement define annotation>. These are inherited by subannotations or overwritten there. The statement define annotation> creates the annotation Anno > as a CDS object>, which is transported using the DDLA source code. The definition of the annotation Anno> describes how it is to be used in other CDS source code in annotation syntax>:
Anno> is the name of the annotation. It can contain letters, numbers, and underscores, and must start with a letter. Only annotations with names defined in this way should be used>.
One of the following must be specified after the name:
A colon (:>) followed by the definition of the type type>> of the annotation. Enumerations and a default value can be defined when the type is specified. The type specification must be closed using a (;>).
An optional colon (:>) followed by the structuring of the annotation using subannotations> subannos>> in curly brackets {...}>. This can be closed using an optional semicolon ( ;>).
A colon (:>) followed by the definition of the elements of an array using array of>. This makes the annotation Anno> into an annotation array> of the elements defined using arrelem>>. These elements can be a type specification or subannotations.
Latest notes:
Put simply, an annotation definition specifies how the annotation needs to be specified in CDS source code in annotation syntax>. When annotations are specified, the annotation definitions are used for the color of the source code and for code completion.
The type specification determines which annotation values> can be specified in the annotation syntax when the annotation is used.
In the annotation syntax, subannotations are specified either as comma-separated lists in curly brackets> or as structured names >.
The elements of an array are specified in annotation syntax as comma-separated lists in square brackets>.
The syntax check in CDS DDL> for data definitions currently ignores annotation definitions. It checks only the formal correctness of any names, annotation values>, subannotations>, and annotation arrays> specified.
When annotations are evaluated > in a CDS entity> using the class CL_DD_DDL_ANNOTATION_SERVICE>>, the annotations are respected as specified in the DDL source code> of the entity. The associated annotation definitions are ignored.
Alongside the rules defined by the statement define annotation>, an annotation definition also has annotation documentation that describes its meaning and how it is used by the framework in question. ABAP_HINT_END
ABAP_EXAMPLE_VX Defines a structured annotation. The main annotation> DEMOANNOSTRUCT>> has subannotations > subAnno1> to subAnno4>. The subannotations subAnno3 > and subAnno4> are annotation arrays>. (Here, subAnno4> is structured.) DDLA DEMOANNOSTRUCT The annotation defined in this way allows the following to be specified in annotation syntax> in a piece of DDL source code> that defines a CDS view> or a CDS table function> as a view annotation (CDS view entity>, CDS projection view>, ABAP_CDS_V1_VIEWS >) or as a function annotation>:
Specifies the subannotation subAnno1> once (the default value true> is used here implicitly): @DemoAnnoStruct.subAnno1>
Specifies the subannotations subAnno1> and subAnno2> together in curly brackets (the default values are overwritten by explicit annotation values> here. In subAnno2>, one of the fixed enumerated values is used: @DemoAnnoStruct:{subAnno1:false, subAnno2:#I2}>
Specifies annotation values for the annotation array subAnno3>. The values within the quotation marks can have a maximum of ten characters: @DemoAnnoStruct.subAnno3:['a','abc','abcdefghij']>