Get Example source ABAP code based on a different SAP table
ABAP_CDS - Calculated Quantity with Calculated Unit A CDS calculated quantity> is a component of a CDS view entity> or of a CDS projection view> in ABAP CDS> used to store a quantity in a specific unit. A calculated quantity is always the result type of a calculation using ABAP CDS amount fields> and/or ABAP CDS quantity fields >. The DDIC data type of a calculated quantity is DECFLOAT34 >>. A calculated quantity must be linked with a ABAP CDS calculated unit> using the annotation @Semantics.quantity.unitOfMeasure: 'calculatedUnit' >>. A calculated unit is a component of the same CDS view entity of data type CHAR> that specifies a user-defined unit which is not contained in any list of pre-defined values. The DDIC data element DD_CDS_CALCULATED_UNIT >> and DDIC domain DD_CDS_CALCULATED_UNIT >> can be used to type a calculated unit, but this is not mandatory. In CDS view entities, the following functions are available for amount and quantity fields:
GET_NUMERIC_VALUE>> removes reference information from an amount or quantity field.
CURR_TO_DECFLOAT_AMOUNT>> converts an amount field of data type CURR > to data type DECFLOAT34>, including shifting. The result remains an amount. Calculated quantities can be the result type of the following expressions in CDS view entities:
Arithmetic expressions>
Aggregate functions>
Simple> and complex case expressions>
ABAP_NOTE Cast expressions> do not handle calculated quantities. Moreover, special rules apply in the following operand positions in CDS view entities:
UNION> views>
INTERSECT> views >
Comparisons >
Latest notes:
Reference annotations to currency or unit of measurement keys are propagated in CDS entities selecting from DDIC database tables or other CDS entities. It is possible, but not mandatory, to redefine them.
Currently, CDS calculated quantities are only available in CDS view entities and in CDS projection views. They are not supported in any other CDS entity>.
If a field is a calculated quantity, this characteristic is inherited when a view entity selects from another view entity.
A calculated unit can be used as reference only once in a view. If a view contains several calculated quantity fields, each field needs a different calculated unit. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 In the following CDS view entity, the field rent_per_size> divides the amount of the rent for an apartment by the apartment size. The result is the cost per square meter. The calculated unit is EUR/MTK >, MTK> being the unit ID for square meter. DDLS DEMO_CDS_CALCULATED_QUANTITY The class CL_DEMO_CDS_CALCULATED_QUNTTY >> accesses the view, inserts values into the underlying database table, and displays the result. ABAP_EXAMPLE_END