例如,我开发了一个 CDS view,并主动生成了一个 Fiori Elements 利用,外面显示的金额单位是欧元:
我冀望利用 CDS view 的货币转换性能,currency conversion,将这些金额的单位转换成美元。
能够应用这个文档里提到的转换函数。
应用如下高亮代码:
@AbapCatalog.sqlViewName: 'ZCTRAVELJERRY'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Consumption view from /DMO/I_TRAVEL_U'
@Metadata.allowExtensions: true
@Search.searchable: true
define view Z_C_TRAVEL_DATA_JERRY as select from /DMO/I_Travel_U
association [1..1] to /DMO/I_Agency as _Agency on $projection.AgencyID = _Agency.AgencyID
association [1..1] to /DMO/I_Customer as _Customer on $projection.CustomerID = _Customer.CustomerID
{
key TravelID,
@ObjectModel.text.association: '_Agency'
AgencyID,
CustomerID,
concat_with_space(_Customer.Title, _Customer.LastName, 1) as Addressee,
BeginDate,
EndDate,
BookingFee,
TotalPrice,
CurrencyCode,
currency_conversion(
amount => TotalPrice,
source_currency => CurrencyCode,
round => 'X',
target_currency => cast('USD' as abap.cuky( 5)),
exchange_rate_date => cast('20200429' as abap.dats),
error_handling => 'SET_TO_NULL' )
as PriceInUSD,
@Search.defaultSearchElement: true
@Search.fuzzinessThreshold: 0.90
Memo,
Status,
LastChangedAt,
/* Associations */
_Agency,
_Booking,
_Currency,
_Customer
}
最初的成果:
转换成果如下:蓝色是原始的欧元单位,红色的是通过 currency_conversion 转换之后的新值:
更多 Jerry 的原创文章,尽在:” 汪子熙 ”: