What does it do? Functions for converting between units and between currencies in an ABAP SQL statement. The functions have keyword parameters> p1>, p2>, ... (some of which are optional), to which actual parameters a1>, a2>, ... must be assigned using => when a function is called.
What does it do? The function UNIT_CONVERSION> performs a unit conversion for the value passed to the formal parameter quantity>. The result has the same data type as the formal parameter passed to quantity >. The unit conversion is performed on the basis of the client-dependent rules saved in the DDIC database tables T006...> of package SZME>>. BEGIN_SECTION VERSION 5 OUT These rules can be edited using transaction CUNI> >. END_SECTION VERSION 5 OUT The table below shows the actual parameters p1>, p2>, ... and their meaning. Formal Parameter>Optional>Meaning> Data Type >Actual Parameter> quantity> -> Inbound value DEC>>, CURR>>, QUAN>>; DECFLOAT34>> SQL expression> source_unit> -> Source unit from column MSEHI> of the DDIC database table T006>> UNIT>> SQL expression> except for the null expression> target_unit> -> Target unit from column MSEHI> of the DDIC database table T006>> UNIT>> SQL expression> except for the null expression> client> X> Client whose rules are used to perform the unit conversion. Default: Content of the client column of the current row CLNT>> SQL expression> except for the null expression> on_error> X> Error handling. If fail> (default value), an error raises an exception; if set_to_null>, the result is reset to the null value>; if keep_unconverted>, the result is reset to the input value Enumerated type> ON_ERROR> of class SQL_CURRENCY_CONVERSION>> Allowed enumerated value>
ABAP_EXAMPLE_VX5 The SELECT> statement calls a unit conversion in its SELECT> list for the column DEC3> of the DDIC database table DEMO_EXPRESSIONS>>. In the event of an error, for example when a unit is not available, the result is reset to the null value. ABEXA 01721 ABAP_EXAMPLE_END
What does it do? The function CURRENCY_CONVERSION> performs a currency conversion for the value passed to the formal parameter amount>. The result has the same data type as the formal 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 the actual parameters p1>, p2>, ... and their meaning. Formal Parameter>Optional>Meaning> Data Type >Actual Parameter> amount> -> Inbound value DEC>>, CURR>>, QUAN>> with two decimal places; DECFLOAT34>> SQL expression> source_currency> -> Source currency from column WAERS> of the DDIC database table TCURC>> CUKY>> SQL expression> except for the null expression> target_currency> -> Target currency from column WAERS> of the DDIC database table TCURC>> CUKY>> SQL expression> except for the null expression> exchange_rate_date> ->Exchange rate date for column GDATU> of the DDIC database table TCURR>> DATS>> SQL expression> except for the null expression> exchange_rate_type> X> Exchange rate type from column KURST> of the DDIC database table TCURR>>, default value: M> CHAR>> SQL expression> client> X> Client whose rules are used to perform the currency conversion. Default: Content of the client column of the current row CLNT>> SQL expression> except for the null expression> round> X> Not possible for amount type D34N>; if X> (default value), the intermediate result of the conversion is rounded to the end result using commercial rounding; otherwise it is truncated ABAP type c> of length 1 Literal> or host constant> decimal_shift> X> Not possible for amount type D34N>; 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). ABAP type c> of length 1 Literal> or host constant> decimal_shift_back> X> Not possible for amount type D34N>; if X> (default value), the decimal places of the result are moved as specified by the decimal places of the target currency (see below). ABAP type c> of length 1 Literal> or host constant> on_error> X> Error handling. If fail> (default value), an error raises an exception; if set_to_null>, the result is reset to the null value> Enumerated type> ON_ERROR> of class SQL_CURRENCY_CONVERSION>> Allowed enumerated value> Handling the Decimal Places>
The value passed is rounded to two decimal places before it is converted.
Before the conversion, the value is multiplied by 10 to the power of the number of decimal places of the source currency.
If the value X> is passed to the parameter decimal_shift>, the value passed is multiplied by 10 to the power of two minus the number of decimal places of the source currency before it is converted.
If the value X> is passed to the parameter decimal_shift_back >, the result is divided by 10 to the power of two minus the number of decimal places of the target currency before it is converted.
After the conversion, the result is divided by 10 to the power of the number of decimal places of the target currency.
Latest notes:
The conversion is performed on the database, which means that part of the calculation takes place using different rounding rules from ABAP. No matter how the conversion is made, the same results cannot be expected as when using standard function modules for currency conversion, since these modules are generally less precise and round the intermediate results accordingly.
The parameter decimal_shift> is intended to set the source value to the number of decimal places of the source currency before the conversion. Because of that, its technical type, CURR>> must have two decimal places. The parameter decimal_shift_back> is intended to perform the reverse operation. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 The following is an excerpt of the class CL_DEMO_ASQL_CURRENCY_CNVRSN>>. The SELECT> statement calls a currency conversion in its SELECT> list for the column AMOUNT> of the DDIC database table DEMO_PRICES>>. The target currency is passed as a host variable. In the event of an error, for example when a currency is not available, an exception is raised. As a comparison, the same conversion is also performed using the function module CONVERT_TO_LOCAL_CURRENCY>>. As a prerequisite for the example, the currencies and conversion rules must be available in the corresponding DDIC database tables. ABEXA 01463 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 In the class CL_DEMO_ASQL_FUNC_CURR_CONV >>, the SQL function CURRENCY_CONVERSION> is used in a subquery of a MODIFY> statement. ABEXA 01464 ABAP_EXAMPLE_END