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





  [VARIANT variant]
  { [element_list] }[;]


... VARIANT variant


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

Before the ANNOTATE VIEW statement, the @Metadata.layer annotation must be specified with one of the displayed enumeration values, in order 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, which is not linked or is linked to the same CDS variant. The enumerated values 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.

Currently it is only possible to specify the following annotations:

All other annotations lead to 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 defined 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.



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 takes into account the definitions in the metadata extension and the translations into the current logon 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 for view with parameters'

annotate view demo_cds_parameters with
    @EndUserText.label: 'Lower distance boundary'
    @EndUserText.label: 'Upper distance boundary'
    @EndUserText.label: 'Unit of distance'
  @EndUserText.label: 'Carrier'
  @EndUserText.label: 'Connection'
  @EndUserText.label: 'Depart from city'
  @EndUserText.label: 'Arrive in city'
  @EndUserText.label: 'Flight distance'
  @EndUserText.label: 'Unit of flight distance'


... VARIANT variant


Links the metadata extension to 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.

For the evaluation of annotations with class CL_DD_DDL_ANNOTATION_SERVICE, you can specify the CDS variant, in order 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.



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

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