Skip to content

ABAP Keyword Documentation →  ABAP Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Syntax 

ABAP CDS - Annotations

Other versions: 7.31 | 7.40 | 7.54

Syntax

... annotation[.annotation1[.annotation2]][:value]  ...

Effect

Annotation that can be specified at predefined positions within a CDS source code, to enhance a definition of the ABAP CDS with meta data. An annotation consists of a single or multiple-part name and an optional specified value.

Names

An annotation has a single-part name

... annotation ...

or a multiple-part name

... annotation.annotation1.annotation2...,

in which single names are separated by a period . (full stop). The individual names annotation, annotation1, annotation2, ... can contain letters, digits, and underscores and must start with a letter. The name of an annotation must be unique in the context of the annotation.

  • A set of predefined annotations with predefined names is available; these can be specified for specific contexts of a definition, expect specific values, and can be analyzed by the runtime environment. These annotations are documented for the respective context.
  • All other names define self-defined annotations, to which any value can be assigned and which must be analyzed by the application itself.

Specified Value

A value value can be specified after a colon :. However, an annotation does not have to contain a value. The following can be specified for value:

  • Literals
Character literals or numeric literals embedded in inverted commas
  • Truth values true and false
These values can be embedded in inverted commas optionally.
  • Enumeration values #value
Specific predefined annotations expect preset values; these are specified directly and without inverted commas after the # character.
  • Value lists [ value1, value2, ...]
Comma-separated lists of values can be specified in square brackets; for such values, the same applies as for value. This is used for structuring an annotation, by assigning different values to it. Direct nesting of square brackets is syntactically possible; however, this is currently ignored during the analysis of the annotations.
  • Annotation lists { annotation1[:value1], annotation2[:value2], ...}
Curly brackets can be used to specify comma-separated lists of annotations. The internal annotations have the same syntax as the external annotation. Specifying an annotation list after an annotation produces a nested annotation and has the same effect as specifying individual names as follows:
annotation.annotation1[:value1]
annotation.annotation2[:value2]
...

Evaluation

The evaluation of annotations differs between predefined and self-defined annotations:

  • Predefined annotations with predefined names specify the technical and semantic properties of CDS objects that are analyzed by the runtime environment.
  • Self-defined annotations with self-defined names must be analyzed by the application itself using a suitable API. Currently, no global API for analyzing self-defined annotations is supplied. Instead, a direct access to the database tables containing the meta data is possible.

Contexts for Annotations

Annotations can be specified for the following contexts.

  • DDL:
  • DCL:

The predefined annotations that are possible for a context are documented here.


Example

The following CDS source code for defining a CDS view contains predefined and self-defined annotations at the allowed positions, that is for the entire view and for an element of the SELECT list. The predefined annotations include AbapCatalog.sqlViewName and ClientDependent for the entire view, and EndUserText.label and EndUserText.quickInfo for the element of the SELECT list. The remaining annotations are self-defined.

@AbapCatalog.sqlViewName: 'DEMO_VIEW_ANNOT'
@ClientDependent: false

@v_annot0
@v_annot1:'abc'
@v_annot2:123
@v_annot3:[ 'abc', 123 ]
@v_annot4:{ annot0, annot1:'abc', annot2:123 }
@v_annot5.annot0
@v_annot5.annot1:'abc'
@v_annot5.annot2:123
@v_annot6:[ 'abc', 123,
            [ 'abc', 123 ],
            { annot0, annot1:'abc', annot2:123 } ]
@v_annot7:{ annot0,
            annot1:[ 'abc', 123 ],
            annot2:{ annot0, annot1:'abc', annot2:123 } }

define view demo_cds_view_annotations
  as select from demo_expressions
    { @f_annot0
      key id as key_field
      @<f_annot1:'abc'
      @<f_annot2:123,    
      @EndUserText:{ label:'Some field', quickInfo:'Some info' }
      @f_annot1:[ 'abc', 123 ]
      num1 as some_field
      @<f_annot2:{ annot0, annot1:'abc', annot2:123 }
    }

The program DEMO_CDS_DDL_ANNOTATIONS accesses the corresponding meta data in database tables DDHEADANNO and DDFIELDANNO and displays these. It should be noted that the notations for v_annot4 and v_annot5 are the same, and that the nested square bracket in the annotation v_annot6 is ignored. Compared with the table for the entire view, the table for the SELECT list additionally contains the name of the element for which an annotation was created.