What does it do? Defines a CDS metadata extension > (MDE for short) in dedicated DDLX> source code>.
ANNOTATE ENTITY> Defines an MDE for any CDS entity> except CDS table functions>.
ANNOTATE VIEW> Defines an MDE specifically for a CDS view>. The CDS metadata extension adds metadata to a CDS entity as CDS annotations>. The entity in question must exist, be specified using the name of its CDS entity> cds_entity> or cds_view>, and contain the annotation Metadata.allowExtensions> with the default value true> in its source code. A CDS entity can have more than one CDS metadata extension. The annotation @Metadata.layer>> must be specified with one of the enumeration symbols shown in the example in front of the statement ANNOTATE> to define the layer of the metadata extension. In the analysis of metadata extensions> , the layer determines the priority of the metadata if there are multiple metadata extensions for the same CDS entity. The enumeration symbols are listed with the lowest priority ones on the left and the highest priority on the right. #CORE> therefore has the lowest, and #CUSTOMER> the highest priority. A syntax check warning is issued for annotations specified more than once, and the system uses the annotation of the first metadata extension found. The annotations added to the extended entity are defined as follows. A metadata extension must contain at least one of these.
Annotations in front of the statement ANNOTATE>
Only entity annotations @entity_annot> can be specified in front of the statement ANNOTATE ENTITY>. Valid SAP annotations> must be in the scope> of the entity annotations>. They are added to the entity annotations of the extended entity.
Entity annotations and view annotations @view_annot> can be specified in front of the statement ANNOTATE VIEW>. Valid SAP annotations> must be in the scope> of the view annotations>. They are added to the view annotations of the extended view.
parameter_list>> is used to specify annotations for the parameters of the extended entity.
element_list>> is used specify annotations for the elements of SELECT> list of the extended entity. In metadata extensions, only those annotations can be specified for which this is allowed in their annotation definition> using the annotation @MetadataExtension.usageAllowed:true>>. In the CDS metadata extension, an annotation can be used in the same scope defined using @Scope>> as in a data definition. All other annotations produce syntax errors. These annotations of a metadata extension are respected in the evaluation of annotations> with the methods of the class CL_DD_DDL_ANNOTATION_SERVICE>> except for GET_DIRECT_ANNOS_ >, in accordance with the layers defined by the annotation @Metadata.layer>. Here the annotations of a metadata extension always have a higher priority than the annotations specified in the source code of the CDS entity. These are only respected if they are not overridden by a corresponding annotation of a metadata extension. For the exact description of the evaluation, see section evaluation of metadata extensions >.
Latest notes:
Unlike the specification of annotations in the source code of the extended CDS entity, it is not possible to have any arbitrary annotations in metadata extensions; it is only possible to have SAP annotations>. The syntax check for a metadata extension checks the validity of its specification with respect to the annotation definition>:
the name of an annotation
the validity of the annotation values >, the type, and (for enumerations) the enumeration symbol
the scope>
whether any annotation arrays> are specified correctly (they must only be specified using square brackets). The format @annot: value> is not possible. @annot: [value]> must be used instead. The array can contain only similar elements (in accordance with its definition).
The annotations (of a CDS entity) specified in metadata extensions does not have any effect on the activation or the behavior at runtime. They are only respected by the class CL_DD_DDL_ANNOTATION_SERVICE>>.
The program ABAP_DOCU_MDE_ANNOS>> shows all annotations that can be specified in metadata extensions. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 The following metadata extension named DEMO_CDS_METADATA_EXTENSION>> adds annotations with original language German> to the CDS view entity DEMO_CDS_PARAMETERS>> from the executable example for CDS view entities with parameters>. The class CL_DEMO_CDS_META_DATA_EXT>> reads the annotations of the view with the methods of the classes CL_DD_DDL_ANNOTATION_SERVICE>> and CL_DD_DDL_ANALYZE>>. The method GET_ANNOS> of the class CL_DD_DDL_ANNOTATION_SERVICE> covers both the annotations specified in the metadata extension and the translations into the current text environment language. The method GET_ANNOTATIONS> of the class CL_DD_DDL_ANALYZE> only evaluates the specifications in the view DEMO_CDS_PARAMETERS>>. DDLX DEMO_CDS_METADATA_EXTENSION ABAP_EXAMPLE_END