Conversion Functions for Currencies and Units in CDS view
Function CURRENCY_CONVERSION performs a currency conversion for the value passed to formal parameter amount.The currency conversion is performed on the basis of the rules stored in the database tables TCURR.
Function UNIT_CONVERSION performs a unit conversion for the value passed to formal parameter quantity.The unit conversion is performed on the basis of the rules stored in transaction CUNI and in the database tables T006.
Function DECIMAL_SHIFT sets the decimal separator of the value that is passed to formal parameter amount according to a currency.
Below post shows to perform a currency conversion. We have SFLIGHT entries with respect to carrid ‘AA’ where price is available in USD but our CDS view should show a price in a different currency.
The CDS view with currency_conversion function, pass the amount to be converted, source currency, target currency and the exchange rate date.
@AbapCatalog.sqlViewName: ‘ZFLIGHT_VW’
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: ‘Flight View with Aggregation Operation’
define view Zflight_View
with parameters p_curr: abap.cuky(5),
p_dat:abap.dats
as select from sflight as s
{
key s.carrid,
key s.connid,
key s.fldate,
currency_conversion( amount => s.price,
source_currency => s.currency,
target_currency => :p_curr,
exchange_rate_date => :p_dat ) as local_amount,
:p_curr as local_currency
} where carrid = ‘AA’
Data Preview: provide the target currency and the date.
Here is the amount in the target currency.
Syntax for Unit_Conversion Function.
unit_conversion( quantity => ”,
source_unit => ”,
target_unit => ” ,
error_handling => ” )
Syntax for Decimal Shift Function.
decimal_shift( amount => ”,
currency => ”,
error_handling => ‘ ‘ )