SAP CDS PROJ VIEW VIRTUAL ELEMENT



Get Example source ABAP code based on a different SAP table
  


• VIRTUAL ABAP_CDS_PROJ_VIEW

ABAP_CDS_DDL - VIRTUAL

ABAP_SYNTAX
... VIRTUAL elem_name : typing

What does it do?
Defines a virtual element in the projection list of a CDS projection view. Virtual elements are read-only elements of a CDS projection view which are not part of the projected entity. Reading the virtual elements of a projection view with ABAP SQL delivers initial values. In order to fill and analyze the virtual elements of projection views, special frameworks like the RAP query engine have to be involved.
In RAP, for example, a virtual element can be connected to an ABAP class that implements a special virtual element interface by using the framework-specific annotation ObjectModel.virtualElementCalculatedBy. In that case the value of the virtual element is calculated during runtime by the RAP query engine. For more information, see the development guide for the ABAP RESTful Application Programming Model, section Using Virtual Elements in CDS Projection Views.



Latest notes:

Virtual elements are also supported in CDS projection views that implement data retrieval via an ABAP class using the annotation ObjectModel.query.implementedBy . This can be useful, for example, in extensibility scenarios. In this case, the ABAP query is evaluated first and the virtual element can use the returned values.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The projection view DEMO_SALES_PV_SO_EXP is based on the CDS view DEMO_SALES_CDS_SO. It contains a virtual element expiry_date that is bound to ABAP class CL_DEMO_SALES_VIRT_ELEM_EXIT that calculates the expiry date of an item during runtime if the view is accessed by the RAP query engine.
DDLS DEMO_SALES_PV_SO_EXP
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
The executable example Calculating a virtual element accesses the CDS projection view shown above and returns the result of the virtual element.
ABAP_EXAMPLE_END