ABAP - Keyword Documentation →  ABAP - Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Annotations →  ABAP CDS - Specifying Annotations →  ABAP CDS Metadata Extensions →  ABAP CDS - DDL for Metadata Extensions → 

ABAP CDS - ANNOTATE VIEW

Syntax

@Metadata.layer: #CORE|#LOCALIZATION|#INDUSTRY|#PARTNER|#CUSTOMER

[@view_annot1]
[@view_annot2]
...

ANNOTATE VIEW cds_entity WITH
  [VARIANT variant]
  [parameter_list]
  { [element_list] }[;]


Addition:

... VARIANT variant

Effect

Defines a CDS metadata extension in (MDE for short) for a CDS view in separate DDLX short code. The CDS metadata extension add metadata to the CDS view in the form of CDS annotations. The view in question must exist, be specified using the name of its CDS entity cds_entity, and contain the annotation Metadata.allowExtensions with the default value true in its source code. There can be multiple CDS metadata extensions for one CDS entity.

The annotation @Metadata.layer must be specified with one of the displayed enumeration symbols in front of the statement ANNOTATE VIEW 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 that is associated with the same CDS variant or not associated with any variants. The enumeration symbols are displayed 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. If multiple CDS metadata extensions with none or the same CDS variant are assigned to the same layer, a syntax check warning is issued for annotations specified more than one, and the system uses the annotation of the first metadata extension found.

The annotations added to the extended view are defined as follows. A metadata extension must contain at least one of these.

In metadata extensions, only those annotations can be specified for which this is permitted 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 annotation of a metadata extensions are taken into account during 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 and in accordance with the used CDS variants. 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 taken into account 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.

Notes

Example

The following metadata extension named DEMO_CDS_METADATA_EXTENSION adds annotations with original language "German" to the CDS view DEMO_CDS_PARAMETERS from the executable example for CDS views with parameters. The program DEMO_CDS_META_DATA_EXTENSIONS 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.

@Metadata.layer:#INDUSTRY
              
@EndUserText.label: 'Demo für View mit Parametern'

annotate view demo_cds_parameters with
  parameters
    @EndUserText.label: 'Untere Entfernungsgrenze'
    p_distance_l,
    @EndUserText.label: 'Obere Entfernungsgrenze'
    p_distance_u,
    @EndUserText.label: 'Einheit der Entfernung'
    p_unit
{
  @EndUserText.label: 'Fluggesellschaft'
  carrid;
  @EndUserText.label: 'Flugverbindung'
  connid;
  @EndUserText.label: 'Abflug in Stadt'
  cityfrom;
  @EndUserText.label: 'Ankunft in Stadt'
  cityto;
  @EndUserText.label: 'Flugstrecke'
  distance;
  @EndUserText.label: 'Einheit der Flugstrecke'
  distid;
};


Addition

... VARIANT variant

Effect

Joints 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 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.

Notes

Caution

CDS variants are not currently released for general use. It is not possible to define standalone CDS variants and the use of CDS variants in metadata extensions produces a syntax check warning.

Executable Example

CDS Metadata Extensions with CDS Variants



Continue
ABAP CDS - ANNOTATE VIEW, metadata_extension_annot
ABAP CDS - ANNOTATE VIEW, parameter_list
ABAP CDS - ANNOTATE VIEW, element_list