Ansicht
Dokumentation

ABENSQL_CURR_UNIT_CONV_FUNC - SQL CURR UNIT CONV FUNC

ABENSQL_CURR_UNIT_CONV_FUNC - SQL CURR UNIT CONV FUNC

rdisp/max_wprun_time - Maximum work process run time   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- Unit and Currency Conversion Functions

... CURRENCY_CONVERSION( p1 = a1, p2 = a2, ... ) ...

Variants:

1. ... CURRENCY_CONVERSION( p1 = a1, p2 = a2, ... )

Effect

Functions for converting between units 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.

Note

Currently, only currency conversions are possible in ABAP SQL. But it is planned to implement unit conversions as in ABAP CDS.

Variant 1

... CURRENCY_CONVERSION( p1 = a1, p2 = a2, ... )


Effect

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. These rules can be edited using transaction OB08.

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
target_currency - Target currency from column WAERS of the DDIC database table TCURC CUKY SQL expression
exchange_rate_date - Exchange rate date for column GDATU of the DDIC database table TCURR DATS SQL 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
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.

Note

  • 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.

Example

The following is an excerpt of the program DEMO_ASQL_CURRENCY_CONVERSION. 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.

Example

In the program DEMO_ASQL_FUNC_CURR_CONV, the SQL function CURRENCY_CONVERSION is used in a subquery of a MODIFY statement.






RFUMSV00 - Advance Return for Tax on Sales/Purchases   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 11348 Date: 20240328 Time: 142630     sap01-206 ( 129 ms )