Get Example source ABAP code based on a different SAP table
ABAP_CDS - Quantity Fields An ABAP CDS quantity field> is a component of a CDS entity> in ABAP CDS> used to store a quantity in a specific unit. Possible built-in ABAP Dictionary data types > are QUAN>, DECFLOAT16>, DECFLOAT34 > , DEC>, FLTP>, INT1>, INT2>, or INT4>. In the case of data type QUAN>, the field is automatically interpreted as quantity field and a reference to a unit of measurement key> using the annotation @Semantics.quantity.unitOfMeasure>> is mandatory. In the case of the other data types, this reference is not mandatory but if used, it turns the field into a quantity field. A quantity field must be linked with a unit key that defines the unit and the number of decimal places. A unit key is a component of a structure, DDIC database table, DDIC view or of another CDS entity of type UNIT> and it can contain a unit ID> from the DDIC database table T006>>. For handling of CDS quantity fields in ABAP Dictionary, handling in dynpros, and handling in ABAP programs, the same rules apply as for currency fields in DDIC, see topic ABAP DDIC - Quantity Fields>.
Handling of CDS Quantity Fields in Expressions in CDS View Entities In CDS view entities, special handling for CDS quantity fields is implemented: When used in expressions>, UNION> views>, or INTERSECT>> views, the reference annotation of a CDS quantity field to a unit key is considered. Special rules apply concerning how amounts and quantities can be combined in calculations, compatibility of data types, and result types. A new result type is available: the CDS calculated quantity>. The rules are documented in the respective sections:
Amounts and quantities in arithmetic expressions>
Amounts and quantities in aggregate functions>
Amounts and quantities in simple > and complex case expressions>
Amounts and quantities in UNION> views>
Amounts and quantities in INTERSECT> views >
Amounts and quantities in comparisons >. ABAP_NOTE Cast expressions> do not handle quantities. Only the target type QUAN> requires a reference to a unit key. The following conversion function is available for quantities in CDS view entities:
GET_NUMERIC_VALUE>>: removes the reference to a unit key and returns the numeric value of a field.
Latest notes:
Reference annotations that assign a unit key to a field are propagated in CDS entities selecting from DDIC database tables or other CDS entities. It is possible, but not mandatory, to redefine them. This is true for all CDS entities except for ABAP_CDS_V1_VIEWS .
Currently, the handling of CDS quantity fields in expressions is only available in CDS view entities and not in any other CDS entity>.
Quantities and units are handled as specified by the data saved in the DDIC database tables T006...> in the package SZME>>. This data can be maintained using the transaction CUNI>>. NON_V5_HINTS ABAP_HINT_END