Virtual Elements — ABAP-calculated fields
Virtual elements are read-only fields whose values are computed in ABAP. They are useful when a value cannot be derived directly from a database column and must be calculated at runtime.
In the CDS view
@ObjectModel.virtualElement: true
@ObjectModel.virtualElementCalculatedBy: 'ABAP:ZCL_BC_VIRTUAL_ELE'
'' as VirtualFieldName,
In the ABAP class
Implement a class such as ZCL_BC_VIRTUAL_ELE and the required SADL/exit interfaces, e.g. IF_SADL_EXIT_CALC_ELEMENT_READ.
Optional: GET_CALCULATION_INFO before select
If the calculation requires additional fields, implement GET_CALCULATION_INFO to return the list of fields that need to be selected from the DB. These fields are then provided to your calculation logic.