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:
- Windows Server 2008 R2 搭建微信小程序
- insert事务产生duplicate key error引发的死锁分析
- 零基础入门深度学习 | 第六章:长短时记忆网络(LSTM)
- 第6章 I/O复用:select和poll函数
- 第7章 套接字选项
- 第8章 基本UDP套接字编程
- 第11章 名字与地址转换
- explicit_defaults_for_timestamp参数导致复制中断
- 剑指offer代码解析——面试题15求链表中倒数第K个结点
- 第15章 Unix域协议
- 第13章 守护进程和inetd超级服务器
- 第14章 高级I/O函数
- Python测试应用与工具
- 第16章 Sun RPC
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Python知识点
- 上盘硬菜,@Transaction源码深度解析 | Spring系列第48篇
- Python--网络编程和并发
- HashMap常见问题(更新中)
- 使用SNVSniffer软件找somatic mutation
- 腾讯云cvm 内存使用率监控指标解读
- Redis常见面试题
- 使用MuSE软件找somatic mutation
- vivo 基于原生 RabbitMQ 的高可用架构实践
- 数据库锁
- 现在单细胞还想“水”CNS恐怕得多组学了
- 7个处理JavaScript值为undefined的技巧
- Python高级知识点
- 三阴性乳腺癌表达矩阵探索之数据下载及理解
- 6种展示代码的工具,你学会了吗?