天天看點

使用 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 将視圖某些字段進行合并