Get Example source ABAP code based on a different SAP table
SAP_ONLY
CDS Metadata Extensions with CDS Variants The example demonstrates the evaluation> of CDS annotations that are defined in CDS metadata extensions.
ABAP_SOURCE_CODE DEMO CL_DEMO_CDS_MDE_VARIANTS
ABAP_DESCRIPTION The example class uses the method GET_ANNOS> of class CL_DD_DDL_ANNOTATION_SERVICE>> to access the following CDS view entity: DDLS DEMO_CDS_MDE The annotations of the view are extended or overridden by the following CDS metadata extensions>:
DEMO_CDS_MDE_PARTNR_VARIANT_2> DDLX DEMO_CDS_MDE_PARTNR_VARIANT_2 The evaluation is done with different parameters for the method GET_ANNOS>:
If the value of abap_false> is passed to the parameter METADATA_EXTENSION>, the default evaluation of the metadata extensions is switched off for the view and the annotations that are specified in the source code are returned.
If the value of abap_true> is passed to the parameter METADATA_EXTENSION> (default behavior), all existing metadata extensions for the view are evaluated as follows.
If the name of a CDS variant is not passed, only annotations from metadata extensions that are not assigned to a variant are used. DEMO_CDS_MDE_PARTNR_NO_VARIANT> is evaluated first and the annotation @UI.dataPoint.title> is found there. This is ignored in the next metadata extension in the hierarchy, DEMO_CDS_MDE_INDSTR_NO_VARIANT>, from which only @UI.dataPoint.description> is used. Finally, UI.dataPoint.longDescription> is used from the view itself, which has no entry in a metadata extension.
If the name of the CDS variant DemoVariant1> is passed, annotations from the metadata extensions that are assigned to this variant are used first, and then annotations from metadata extensions that are not assigned to a variant. DEMO_CDS_MDE_PARTNR_VARIANT_1> is evaluated first and the annotation @UI.dataPoint.title> is found there. In the next metadata extension in the hierarchy, DEMO_CDS_MDE_INDSTR_VARIANT_1>, the annotation @UI.dataPoint.longDescription> is found. No annotation is found in DEMO_CDS_MDE_PARTNR_NO_VARIANT>. In DEMO_CDS_MDE_INDSTR_NO_VARIANT>, the annotation @UI.dataPoint.description> (not used until now) is found and used. The annotations of the source code of the view are all overridden.
If the name of the CDS variant DemoVariant2> is passed, DEMO_CDS_MDE_PARTNR_VARIANT_2> is evaluated first and the annotations UI.dataPoint.title> and @UI.dataPoint.description> are found there. In the next metadata extension in the hierarchy, DEMO_CDS_MDE_INDSTR_VARIANT_2>, there are no annotations that have not already been used. The same applies to DEMO_CDS_MDE_PARTNR_NO_VARIANT> and DEMO_CDS_MDE_INDSTR_NO_VARIANT>, which are evaluated next. Therefore, the annotation UI.dataPoint.longDescription> from the view itself is used.
If the name of an invalid CDS variant is passed, an empty internal table is returned. The column <(>SOURCEDDLX<)> in the output internal tables contains the metadata extension in which an annotation is specified.