What does it do? Functions for converting between units and between currencies in a CDS view entity>. The functions UNIT_CONVERSION> and CURRENCY_CONVERSION> have keyword parameters > quantity>, source_unit>, ... (some of which are optional), to which actual parameters arg1 >, arg2>, ... can or must be assigned when called using => >. The functions GET_NUMERIC_VALUE> and CURR_TO_DECFLOAT_AMOUNT > each have one mandatory positional parameter> arg>.
Latest notes: The function DECIMAL_SHIFT> is currently not supported in CDS view entities>. NON_V5_HINTS ABAP_HINT_END
ABAP_VARIANT_1 ... UNIT_CONVERSION( ... )>
What does it do? The function UNIT_CONVERSION> performs a unit conversion for the value passed to the keyword parameter quantity>. The unit conversion is performed on the basis of the client-dependent rules saved in BEGIN_SECTION VERSION 5 OUT transaction CUNI>> and in END_SECTION VERSION 5 OUT the DDIC database tables T006...> of the package SZME>>. The table below shows all available keyword parameters and their meaning. Formal Parameter>Optional>Meaning> Data Type >Actual Parameter arg>> quantity>->Inbound valueQUAN>>, DEC>>, INT1>>, INT2>>, INT4>>, DECFLOAT16>>, DECFLOAT34>>, FLTP>> Literal>, field of a data source>, parameter>, expression>, SQL-based scalar function>, path expression> source_unit>->Source currency from column MSEHI> of DDIC database table T006>> UNIT>>Field of a data source>, parameter>, case distinction>, cast expression>, path expression>, SQL-based scalar function> target_unit>->Target unit from column MSEHI> of DDIC database table T006>> UNIT>>Field of a data source>, parameter>, case distinction>, cast expression>, path expression>, SQL-based scalar function> client>X>, ->Client whose rules are used to perform the unit conversion. Since client handling takes place implicitly for CDS view entities, it is not possible to explicitly specify any client column as actual parameter. For client-dependent sources, there are two options: lbr - either, the parameter can be left out and the client column is implicitly added, or lbr - the actual parameter can be specified as expression, literal, or session variable (but not as field of a data source). CLNT >> Expression>, SQL-based scalar function>, literal>, session variable> error_handling>X>Error handling. lbr 'FAIL_ON_ERROR'>: an error raises an exception (default) lbr 'SET_TO_NULL'>: the result is set to the null value> lbr 'KEEP_UNCONVERTED'>: the source value is not changed. CHAR>> with length 20 Literal> The data type of the result depends on the data type of the formal parameter quantity>:
If quantity> has data type QUAN>, DEC>, INT1>, INT2>, INT4>, or FLTP>, the result has data type QUAN> with the length 31 and 14 decimal places.
If quantity> has data type DECFLOAT16>, the result has data type DECFLOAT16>.
If quantity> has data type DECFLOAT34>, the result has data type DECFLOAT34>.
Latest notes: The precision of the result of the unit conversion depends on the database platform. The highest precision is achieved on databases that support decimal floating point numbers>. Due to rounding, the result can be different from a unit conversion performed using ABAP methods, such as a standard function module. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 The following CDS view entity calls a unit conversion in the SELECT > list for the column DEC3> of the DDIC database table DEMO_EXPRESSIONS>>. The source unit is specified using a typed literal. The target unit must be passed as a parameter. In the event of an error, for example if a conversion between the entered units is impossible, the result is set to null. DDLS DEMO_CDS_UNIT_CONVERSION_VE The class CL_DEMO_CDS_UNIT_CONVERSION_VE >> accesses the view in a SELECT> statement. The target unit is passed to the respective formal parameter. As a comparison, the same conversion is also performed using the function module UNIT_CONVERSION_SIMPLE>>. As prerequisite for the example, the units and their conversion rules must be available in the corresponding DDIC database tables. ABAP_EXAMPLE_END
ABAP_VARIANT_2 ... CURRENCY_CONVERSION( ... ) >
What does it do? The function CURRENCY_CONVERSION> performs a currency conversion for the value passed to the keyword parameter amount>. The result has the data type CURR>> or DECFLOAT34>> with the same technical properties as the actual parameter passed to amount >. The currency conversion is performed on the basis of the client-dependent rules saved in the DDIC database tables TCUR...> of package SFIB>>. BEGIN_SECTION VERSION 5 OUT These rules can be edited using transaction OB08> >. END_SECTION VERSION 5 OUT The table below shows all available keyword parameters and their meaning. Formal Parameter>Optional>Meaning> Data Type >Actual Parameter arg>> amount>->Inbound value CURR>>, DECFLOAT34>>Field of a data source>, parameter>, SQL-based scalar function>, expression>, path expression> source_currency> ->Source currency from column WAERS > of DDIC database table TCURC>> CUKY>>Field of a data source>, SQL-based scalar function>, cast expression>, path expression>, parameter> target_currency>->Target currency from column WAERS > of DDIC database table TCURC>> CUKY>>Field of a data source>, SQL-based scalar function>, cast expression>, path expression>, parameter> exchange_rate_date>->Exchange rate date for column GDATU> of DDIC database table TCURR> > DATS>>Field of a data source>, literal>, parameter>, SQL-based scalar function>, path expression>. exchange_rate_type>X>Exchange rate type from column KURST> of DDIC database table TCURR> >, default value: 'M'>CHAR> > with length 4Literal>, parameter> client>X>, -> Client whose rules are used to perform the currency conversion. Since client handling takes place implicitly for CDS view entities, it is not possible to explicitly specify any client column as actual parameter. For client-dependent sources, there are two options: lbr - either, the parameter can be left out and the client column is implicitly added, or lbr - the actual parameter can be specified as expression, literal, or session variable (but not as field of a data source). CLNT>> Expression>, SQL-based scalar function>, literal>, session variable> round>X>If X> (default value), the intermediate result of the conversion is rounded to the end result using commercial rounding; else it is truncatedCHAR> >Literal> decimal_shift>X>This formal parameter can only be used with data type CURR> for amount>. lbr lbr If X> (default value), the decimal places of the source value are moved as specified by the decimal places of the source currency (see below). CHAR>> Literal> decimal_shift_back>X>This formal parameter can only be used with data type CURR> for amount>. lbr lbr If 'X' > (default value), the decimal places of the result are moved as specified by the decimal places of the target currency (see below). CHAR>>Literal> error_handling>X>Error handling. If 'FAIL_ON_ERROR' > (default value), an error raises an exception; if 'SET_TO_NULL' >, the result is set to the null value> ; if 'KEEP_UNCONVERTED'>, the source value is not changed. CHAR>> with length 20 Literal> The input parameters round>, decimal_shift>, and decimal_shift_back> accept the literals 'true'>, 'false'>, 'X'>, or ' '>. #cdsboolean.true> and #cdsboolean.false > with the domain prefix