SAP CDS view自学教程之五:如何开发支持Odata navigation的CDS view

标签: Jerry Wang的原创SAP技术文章  CRM  ABAP

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的原创文章,请关注公众号"汪子熙":

版权声明:本文为i042416原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/i042416/article/details/108024804

智能推荐

Valine-1.4.4新版本尝鲜+个性制定(表情包、qq头像、UI样式)

文章目录 一、前言 二、尝鲜 三、个性定制 1. 大佬版 2.“傻瓜”版 3.平民版 (1)自定义背景 (2)增添个性表情 (3) 根据邮箱拉取qq头像 (4)diy魔改样式 一、前言 大晚上又魔改评论系统了, 2020年4月16日01:56:39把新版本的自定义图片改出来了,2333,valine的新版本变化蛮大的。 二、尝鲜 1.4.4 强势来袭,尝鲜加体验。 文末给出...

RxJava源码分析(2) 变换原理

RxJava源码分析基于RxJava1.3.8。 在上一章节中,主要介绍了RxJava的基本使用并对该部分的源码做了详细分析。在这一章节中,将主要介绍RxJava的另一大核心功能:变换。 变换,就是将事件序列中的对象或整个序列进行加工处理,转换成不同的事件或事件序列。 在RxJava中,提供了许多针对不同场景实现变换功能的操作符,如下: map() flatMap(), concatMap(), ...

CVE-2017-11176: A step-by-step Linux Kernel exploitation (part 4/4)

CVE-2017-11176: A step-by-step Linux Kernel exploitation (part 3/4) 本文的原文地址:https://blog.lexfo.fr/cve-2017-11176-linux-kernel-exploitation-part4.html 介绍 在最后的这个部分中,我们将会把任意调用转换成在ring0权限下的任意代码执行,修复内核拿到ro...

一道简单的Docker题

docker是什么? 我觉得大致可以理解为linux环境下的虚拟机(容器) 就跟windows环境下的vmware一样 在打中科大hackergame2020的时候发现有一道docker题 先复习下docker的相关命令: 这里! 然后开始做题 首先先配置好本地的docker环境,apt-get换成浙大源(经过测试这个源下载安装docker速度超快,吊打阿里清华源) 然后安装 docker 首先需...

企业权限管理系统---产品管理

查询所有产品 添加产品 具体实现: jsp页面内容: Cntroller层代码 service层 dao层...

猜你喜欢

拒绝无用功,封装一个通用的PopupWindow

作者: 夏至,欢迎转载,但请保留这段申明,谢谢 https://juejin.im/post/5961e03e51882568b13c3308 为了避免重复造轮子,我们一般都会封装一个通用的控件,比如这次,项目中需要用到比较多的 popupwindow ,如果需要一个个写,那么依旧会累死人,而且还是无用功,无意义,所以,封装一个通用的,除了让同事看了直刷666之外,自己还省了很多事情。 先上效果图...

【数据库】关系数据库(Relational Databases)

关系数据库(Relational Databases) 关系数据库,是建立在关系数据库模型基础上的数据库,借助于集合代数等概念和方法来处理数据库中的数据 Relational Query Languages Tuple Relational Calculus (TRC) Relational Algebra (RA) SQL 举例说明: 零、名词概念 1. 基数 和 参数数 cardinality...

zabbix多台监控-proxy分布式监控

zabbix:proxy分布式监控 server3:zabbix-proxy 1、安装 2、开启mysql 3、编写配置文件 4、网页配置添加代理 server1:zabbix-server server2:zabbix-agent...

Collection

Collection 中的方法,全部来自API,读者无需硬性记忆,只需牢记:集合类就像容器,显示生活中容器的功能,也就是添加对象、删除对象、清空容器、判断容器是否为空等,集合类就为这些功能提供了对应的方法。 Collection基本方法: 输出结果: 转自:https://blog.csdn.net/wxc880924/article/details/52639701...

hive on spark部署

1. 环境 Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. tez, spark) or using Hive 1.X releases. hive默认使用mr作为计算引擎,当进入...