SAP CDS ANNOTATIONS - Syntax



Get Example source ABAP code based on a different SAP table
  


• : ABAP_CDS_ANNOT_SYNTAX
• [ ] ABAP_CDS_ANNOT_SYNTAX
• { } ABAP_CDS_ANNOT_SYNTAX
• /at ABAP_CDS_ANNOT_SYNTAX
• /at< ABAP_CDS_ANNOT_SYNTAX

ABAP_CDS_DDL - Annotation Syntax

ABAP_SYNTAX
@$[ < $]Anno$[: value $]
$|$[: { subannos } $]
$|$[: [ arrelem ] $]
$|$[.subAnno$[ ... $] $]

What does it do?
A CDS annotation is specified in CDS source code by using fixed annotation syntax. This syntax specifies the following:
The annotation is introduced using the character @ or the characters @ < . @ < can be used in the CDS DDL for CDS entities except for CDS view entities in order to specify the annotation after a list element in a comma-separated or semicolon-separated list.
A main annotation Anno consisting of letters, numbers, and underscores and starting with a letter. A main annotation that is not structured using subannotations can be specified exactly once in a scope.
One of the following optional alternatives specified after a colon ( :):
An annotation value value
Subannotations subannos specified in curly brackets { ... }.
Elements of an annotation array arrelem specified in square brackets [ ... ].
The main annotation Anno chained with a subannotation subAnno using a period ( .). The combination Anno.subAnno is a structured annotation name that can be extended using further subannotations.
An annotation name must be unique within a scope. Only those annotations should be specified for which a CDS annotation definition exists. Alongside the syntax rules above, the annotation definition also specifies the following:
The statement define annotation defines the name, the possible annotation values, the layout of the subannotations, and whether the annotation in question is an annotation array.
The annotations of an annotation definition specify the scope of the annotation, whether it can be moved to metadata extensions, and whether a particular annotation value is translatable text.
In the DCL source code for CDS roles, DDLX source code for metadata extensions, and the DDLA source code for annotation definitions, the syntax check allows only those annotations that follow the rules of an annotation definition. In the DDL source code for data definitions, annotation definitions modify the source code colors and code completion in ADT. Currently, however, they are not covered by the syntax check.



Latest notes:

The evaluation of the annotations of CDS source code is currently the responsibility of the framework in which the CDS object is used.
The annotations specified in the DDL source code of a CDS entity can be supplemented or overridden using the annotations of CDS metadata extensions. Here the annotations are specified with the same syntax as in the DDL source code of a CDS entity, with the following restrictions:
@ < cannot be used for introducing an annotation.
Only those annotations can be specified for which this is noted in their annotation definition.
There is a set of SAP annotations predefined by SAP, comprising ABAP annotations evaluated by the ABAP runtime framework and framework-specific annotations evaluated by other frameworks. All other annotations are not usually evaluated. It cannot be guaranteed, however, that a framework allows all annotations.
The program ABAP_DOCU_CDS_ANNOS_OVERVIEW shows all SAP annotations and their properties.
NON_V5_HINTS
The methods of the class CL_DD_DDL_ANNOTATION_SERVICE for evaluating annotations of CDS entities return derived and inherited annotations alongside the annotations specified directly in the associated DDL source code.
ABAP_HINT_END
BEGIN_SECTION VERSION 5 OUT

ABAP_EXAMPLE_VX
The following DDL source code for defining a CDS view entity contains ABAP annotations and other annotations at the allowed positions (in other words, for the entire view, for the elements of the SELECT list, and for an input parameter).
DDLS DEMO_CDS_VIEW_ANNOTATIONS
ABAP annotations are:
EndUserText.label, applies to the full view entity.
EndUserText.label and EndUserText.quickInfo for the element some_field of the SELECT list
EndUserText.label and Environment.systemField for the input parameter param.
The remaining annotations are used as examples for framework-specific annotations . An annotation definition that allows the specified annotations shown here could look like this:
DDLA DEMOANNO
The class CL_DEMO_CDS_DDL_ANNOTATIONS access the metadata created by the specified annotations in the DDIC database tables DDHEADANNO, DDFIELDANNO, and DDPARAMETERANNO directly and using the methods of the classes CL_DD_DDL_ANNOTATION_SERVICE and CL_DD_DDL_ANALYZE and displays it. Note the following in particular:
The annotation @DemoAnno.vAnnot3 is an annotation array consisting of three elements indicated by the indexes $1$, $2$, and $3$ .
The annotations @DemoAnno.vAnnot4 and @DemoAnno.vAnnot5 show the alternatives to specifying a structured annotation using a comma-separated list in curly brackets and by using structured names.
Unlike the table DDHEADANNO, the tables DDFIELDANNO and DDPARAMETERANNO for the elements and parameters also contain the name of the element or parameter for which an annotation was created.
ABAP_EXAMPLE_END
END_SECTION VERSION 5 OUT