天天看点

使用 SAP CDS view SQL Function 将视图某些字段进行合并

SAP 用于学习目的设计了很多 demo 开发包,里面包含了很多用于演示目的的 CDS view,类似经典的 Flight 模型,比如视图 /DMO/I_Travel_U.

这个视图和客户相关的信息只有一个 customer ID,因此基于该视图生成的 Fiori Elements 应用里,只有一个 Customer ID 可供显示:

使用 SAP CDS view SQL Function 将视图某些字段进行合并
我们首先使用 association,通过主视图 /DMO/I_TRAVEL_U 的 CustomerID 字段,连接到 /DMO/I_CUSTOMER 视图,再使用 SQL Function 中的 concat_with_space, 将客户 association 中的 Title 和 LastName 连接在一起,将结果使用别名 Addressee 进行存储:
使用 SAP CDS view SQL Function 将视图某些字段进行合并

@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,
    @Search.defaultSearchElement: true
    @Search.fuzzinessThreshold: 0.90
    Memo,
    Status,
    LastChangedAt,
    /* Associations */
    _Agency,
    _Booking,
    _Currency,
    _Customer
}      

最后 Fiori Elements 里的显示效果:

使用 SAP CDS view SQL Function 将视图某些字段进行合并