SAP CDS view自学教程之五:如何开发支持Odata navigation的CDS view
So far we have a working CDS view ready for us to create a UI5 application on top of it via Smart Template in WebIDE within just a couple of minutes. Once done, the UI5 application will display the data from our CDS view like below. For step by step how to achieve this, please refer to this blog: Step by Step to create CDS view through SmartTemplate + WebIDE.
How is navigation implemented among CDS views
In this part, let’s create CDS view which supports node navigation in OData service. The previous CDS view we created has a flat structure which only have a root node. Now let’s create a series of CDS views:
(1) A CDS view which contains two fields: spfli.connid and spfli.carrid. This view acts as the root node of the corresponding OData service model from semantic point of view. This view can support navigation from itself to the defined children node.
(2) A CDS view which acts as the navigation target from previously defined “root” view. Besides the two fields from sflight.connid and sflight.carrid which correspond to the root view, it has additional new field sflight.fldate.
OData navigation means suppose currently I am in the context of spfli.connid = 0001 and spfli.carrid ( data record with yellow ), and through navigation I can get all its dependent data in red color. We will see how this navigation would be performed later.
(3) A CDS view which exposes the two fields connid and carrid from root view and the associated data from child view.
This view is called “consumption” view and used to published as OData service.
Source code of view #1:
@AbapCatalog.sqlViewName: 'zspfliroot'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'root view'
define view Zspfli_Root as select from spfli
association [0..*] to Zsflight_Child as _Item on $projection.carrid = _Item.carrid
and $projection.connid = _Item.connid
{
key spfli.connid,
key spfli.carrid,
@ObjectModel.association.type: #TO_COMPOSITION_CHILD
_Item
}
Source code of view #2:
@AbapCatalog.sqlViewName: 'zsflightchild'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'child_view'
define view Zsflight_Child as select from sflight
association [1..1] to zspfli_root as _root
on $projection.connid = _root.connid
and $projection.carrid = _root.carrid
{
key sflight.carrid,
key sflight.connid,
key sflight.fldate,
@ObjectModel.association.type: [#TO_COMPOSITION_ROOT, #TO_COMPOSITION_PARENT]
_root
}
Source code of view #3:
@AbapCatalog.sqlViewName: 'zflight_c'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'flight consumption view'
@OData.publish: true
@ObjectModel: {
type: #CONSUMPTION,
compositionRoot,
createEnabled,
deleteEnabled,
updateEnabled
}
define view Zflight_Com as select from Zspfli_Root {
key Zspfli_Root.carrid,
key Zspfli_Root.connid,
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
Zspfli_Root._Item
}
Activate all of these three CDS views. Since the third consumption view has annotation @OData.publish: true, once activated there will be an OData service automatically generated:
How to test navigation
First check the response from OData metadata request via url/sap/opu/odata/sap/ZFLIGHT_COM_CDS/$metadata in gateway client.
You should find two AssociationSets generated based on corresponding annotation in CDS views.
The entityset Zflight_Com has type Zflight_ComType, which has the navigation Property “to_Item”. Now we can test the navigation.
First we get the root node’s content via url:/sap/opu/odata/sap/ZFLIGHT_COM_CDS/Zflight_Com(connid=’0400′,carrid=’LH’) .
And in the response, we are told that the correct url for navigation from current node to its child node is just to append the navigation property defined in metadata, toItem, to the end of url, that is,/sap/opu/odata/sap/ZFLIGHT_COM_CDS/Zflight_Com(connid=’0400′,carrid=’LH’)/to_Item .
How the navigation is implemented in ABAP side
Set the breakpoint in the method below and re-trigger the navigation operation.
Check the generated SQL statement in variable statement in line 27.
SELECT "Zsflight_Child"."CARRID" AS "CARRID", "Zsflight_Child"."CONNID" AS "CONNID", "Zsflight_Child"."FLDATE" AS "FLDATE" FROM "ZSFLIGHTCHILD" AS "Zsflight_Child"
WHERE "Zsflight_Child"."CARRID" = ? AND "Zsflight_Child"."CONNID" = ? AND "Zsflight_Child"."MANDT" = '001' WITH PARAMETERS( 'LOCALE' = 'CASE_INSENSITIVE' )
The value for two placeholders ( ? ) are stored in me->parameters->param_tab:
And check response in et_flag_data:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- SAP UI5 sap.ui.layout.Grid 控件概述
- SAP UI5 sap.ui.layout.Grid 控件宽度百分比的设置原理
- SAP UI5 sap.ui.Device.media 的使用介绍
- SAP UI5 sap.ui.Device.media.initRangeSet 方法的单步调试
- SAP ABAP Netweaver 里的 ABAP 会话概念
- 通过一个实际例子,理解 SAP UI5 sap.ui.model.odata.v2.ODataModel API 中 BindingContext 绑定上下文的概念和用法试读版
- [ChatGPT 勘误] SAP UI5 的 sap.ui.base.Object
- SAP ABAP CDS view 里 INNER JOIN 和 Association 的区别
- 我与 SAP 成都研究院吴院长的二三事
- SAPGUI 里运行的老程序,如何对新的 SAP Fiori Belize Theme 进行适配?
- SAP MIGO + 561初始化库存,系统报错 - Constant Z1900 for Ledger !* does not contain any val
- SAP UI5 sap.m.Table Manual Pop-In Mode 概述
- SAP UI5 响应式表格 sap.m.Table 根据不同宽度的屏幕动态决定显示或隐藏 Column 的实现源代码讲解试读版
- SAP Fiori Launchpad url 参数 sap-app-origin-hint 的含义
- 安装SAP,Linux获台前瞻未来(linux安装sap)
- SAP MM TCODE详解编程语言
- SAP Smartform中table和template的区别详解编程语言
- SAP中使用FTP服务详解编程语言
- SAP中的密码输入框详解编程语言
- SAP MM物料管理系统功能详解编程语言
- sap abap 对字符串的操作详解编程语言
- 对比SAP VS Oracle: 哪个更适合你?(sap与oracle)
- Oracle与SAP在仓储领域的联姻(仓库oracle和sap)
- 对比:Oracle 与 SAP的优势(oracle 与 sap)
- Oracle和SAP技术比较优势和劣势(oracle与sap比照)
- 使用Oracle与SAP进行数据接口开发(oracle sap接口)
- 探索 Oracle 与 SAP 技术的开发可能性(oracle sap开发)
- Oracle 与 SAP深度对比分析(oracle sap对比)