SAP CDS F1 ANNOTATE VIEW



Get Example source ABAP code based on a different SAP table
  


• ANNOTATE VIEW ABAP_CDS_DDL_STATEMENT
• ANNOTATE ENTITY ABAP_CDS_DDL_STATEMENT
• WITH ABAP_CDS_ANNOTATE_VIEW
• WITH ABAP_CDS_ANNOTATE_ENTI

ABAP_CDS_DDL - ANNOTATE ENTITY, VIEW

ABAP_SYNTAX_FORMS

<(>ANNOTATE ENTITY<)>
1 @Metadata.layer: #CORE$|#LOCALIZATION$|#INDUSTRY$|#PARTNER$|#CUSTOMER
$[@entity_annot1$]
$[@entity_annot2$]
...
ANNOTATE ENTITY cds_entity WITH
BEGIN_SECTION SAP_ONLY
$[VARIANT variant$]
END_SECTION SAP_ONLY
$[parameter_list$]
{ $[element_list$] }$[;$]

<(>ANNOTATE VIEW<)>
2 @Metadata.layer: #CORE$|#LOCALIZATION$|#INDUSTRY$|#PARTNER$|#CUSTOMER
$[@entity_annot1$]
$[@entity_annot2$]
...
$[@view_entity_annot1 | @proj_view_annot1 | @_view_annot1$]
$[@view_entity_annot2 | @proj_view_annot2 | @_view_annot2$]
...
ANNOTATE VIEW cds_view WITH
BEGIN_SECTION SAP_ONLY
$[VARIANT variant$]
END_SECTION SAP_ONLY
$[parameter_list$]
{ $[element_list$] }$[;$]
BEGIN_SECTION SAP_ONLY

ABAP Addition
... VARIANT variant
END_SECTION SAP_ONLY

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

ABAP_EXAMPLE_VX5
The following metadata extension DEMO_CDS_MDE_FOR_ABSTR_ENT adds entity annotations and element annotations to the CDS abstract entity DEMO_CDS_ABSTRACT_ENTITY_ELEM from the example for its element annotations.
DDLX DEMO_CDS_MDE_FOR_ABSTR_ENT
ABAP_EXAMPLE_END
• VARIANT ABAP_CDS_ANNOTATE_VIEW
BEGIN_SECTION SAP_ONLY

ABAP Addition

What does it do?
Links the metadata extension with a CDS variant. An existing CDS variant must be specified for variant . This entry is not case sensitive. If there are multiple metadata extensions for the same CDS entity contained in the layer defined with annotation @Metadata.layer, these extensions should be assigned to CDS variants, because otherwise a warning is raised by the syntax check for duplicate annotations.
In evaluations of annotations using the class CL_DD_DDL_ANNOTATION_SERVICE, the CDS variant can be specified to select the metadata extension. The class collects the annotations that it returned, in accordance with the layers and variants in line with the hierarchy described under the evaluation of metadata extensions .



Latest notes:

CDS variants are created in the ADT and this creation process is documented there too.