如何使用 SAP CDS view 中的 currency conversion 功能

例如,我开发了一个 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: truedefine 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.AgencyIDassociation [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 转换之后的新值:

(0)

相关推荐