Let’s try to resolve one real issue now. What we want to achieve is: in CRM we need a CDS view which returns the service order guid together with its Sold-to Party information, “Title” ( Mr. ) and “Name” ( blGMOUTH ).

The title and Name information are stored on table BUT000, while Service order transactional information is maintained in tableCRMD_PARTNER, which has a field PARTNER_NO ( CHAR32 ) linking to table BUT000’s PARTNER_GUID ( RAW16 ).


It is not allowed to do join on these two fields since their data type are not equal. This question is asked via this SCN thread: ABAP CDS View: join tables on columns of different type.

As suggested in the Correction Answer, this issue could be resolved by using CDS Table Function. Here below are the detail steps.

(1) Create a new table function

@ClientDependent: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
define table function ztf_BP_DETAILwith parameters @Environment.systemField: #CLIENTclnt:abap.clntreturns { client:s_mandt;partner_guid:BU_PARTNER_GUID;partset_guid:CRMT_OBJECT_GUID;partner_no: CRMT_PARTNER_NO;bp_guid: BU_PARTNER_GUID;title:AD_TITLE;name: BU_NAME1TX;}implemented by methodzcl_amdp_bp_detail=>crmd_partner_but000;

With keyword “with parameters”, the client parameters is defined which works as the importing parameters for the ABAP class method zcl_amdp_bp_detail=>crmd_partner_but000. The keywords “returns” defines available fields which could be consumed by other CDS entities.

For further information about AMDP ( ABAP Managed Database Procedure ), please refer to this document Implement and consume your first ABAP Managed Database Procedure on HANA or this blog An example of AMDP( ABAP Managed Database Procedure ) in 740.

(2) Create a new AMDP implementation

Create a new ABAP class zcl_amdp_bp_detail by copying the following source code:

CLASS zcl_amdp_bp_detail DEFINITIONPUBLICFINALCREATE PUBLIC .PUBLIC SECTION.INTERFACES if_amdp_marker_hdb.CLASS-METHODS crmd_partner_but000 FOR TABLE FUNCTION ztf_bp_Detail.PROTECTED SECTION.PRIVATE SECTION.
ENDCLASS.
CLASS zcl_amdp_bp_detail IMPLEMENTATION.
METHOD crmd_partner_but000BY DATABASE FUNCTION FOR HDBLANGUAGE SQLSCRIPTOPTIONS READ-ONLYUSING crmd_partner but000.RETURN SELECT sc.client as client,sc.partner_guid as partner_guid,sc.guid as partset_guid,sc.partner_no as partner_no,sp.partner_guid as bp_guid,sp.title as title,sp.name1_text as nameFROM crmd_partner AS scINNER JOIN but000 AS sp ON sc.client = sp.client ANDsc.partner_no = sp.partner_guidWHERE sc.client = :clnt ANDsc.partner_fct = '00000001'ORDER BY sc.client;ENDMETHOD.
ENDCLASS.

Here in line 30 the two columns of CRMD_PARTNER and BUT000 are joined. The importing parameter is used in SQLScript source code by adding a “:” before the variable name. The hard code “00000001” means the constant value for partner function “Sold-to Party”.

(3) Consume the created table function in CDS view


@AbapCatalog.sqlViewName: 'zcpartner'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'partner detail'
define view Z_c_partner as select from crmd_orderadm_h
inner join crmd_link as _link on crmd_orderadm_h.guid = _link.guid_hi and _link.objtype_hi = '05'and _link.objtype_set = '07'
inner join ztf_bp_detail( clnt: '001') as _bp on _link.guid_set = _bp.partset_guid
{key crmd_orderadm_h.guid,--_link.objtype_hi as header_type,--_link.objtype_set as item_type,_bp.bp_guid,_bp.partner_no,_bp.name,case _bp.titlewhen '0001' then 'Ms.'when '0002' then 'Mr.'when '0003' then 'Company'when '0004' then 'Mr and Mrs'else 'Unknown'end as title
}

Please note that the created table function in step1 could be directly consumed just as a normal CDS view, see example in line 8.
Since the table function declares client as parameter, so when consumed, I put the current client id 001 into it. The fields defined as the returning parameters in table function could be used in consuming view.

(4) Test the whole solution
Click F8 on the view z_c_partner, check whether data previews as expected.

or you can also check against single data record, by clicking “SQL Console”, maintain the SQL and click Run:

The same test could also easily be done on ABAP side:


要获取更多Jerry的原创文章,请关注公众号"汪子熙":

SAP CDS view自学教程之六:如何在CDS view里消费table function相关推荐

  1. SAP UI5 应用开发教程之六十七 - 基于 OData V4 的 SAP UI5 List-Detail(列表-明细)布局的实现方式试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  2. SAP UI5 应用开发教程之六十六 - 基于 OData V4 的 SAP UI5 表格控件如何实现删除功能试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  3. SAP UI5 应用开发教程之六十四 - 基于 OData V4 的 SAP UI5 表格控件如何实现 filter(过滤) 和 sort(排序)功能试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  4. SAP UI5 应用开发教程之六十三 - 基于 OData V4 的本地 Mock Server 实现的深入介绍试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  5. SAP UI5 应用开发教程之六十二 - 基于 OData V4 的 SAP UI5 表格控件使用方法介绍试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  6. SAP UI5 应用开发教程之六十 - SAP UI5 地图控件的一些高级用法试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  7. SAP UI5 应用开发教程之六十九 - 如何从 SAP UI5 Not Found 页面跳转回到正常的应用页面试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  8. SAP UI5 应用开发教程之六十九 - 如何从 SAP UI5 Not Found 页面跳转回到正常的应用页面

    本系列的前一篇文章,我们学习了 SAP UI5 自定义 Not Found 页面的实现方式: SAP UI5 应用开发教程之六十八 - 如何实现 SAP UI5 路由失败时显示自定义的 NOT Fou ...

  9. SAP UI5 应用开发教程之六十五 - 基于 OData V4 的 SAP UI5 表格控件如何实现创建,编辑和保存功能

    本教程前几个步骤,我们已经用 SAP UI5 table 控件开发了一个包含 User 列表的应用,并且支持了根据 LastName 字段进行查询,以及排序的操作. SAP UI5 应用开发教程之六十 ...

最新文章

  1. html怎么查看cad文件,如何直接查看CAD格式的图纸
  2. oracle10g提权,Oracle 10g提权测试
  3. 中国金控(00875.HK)获主席兼首席执行官林裕豪增持15.8万股
  4. MySQL视图、事务与存储过程
  5. 朴素Paxos(Basic Paxos)算法java简易实现
  6. SharePoint 2013 自定义扩展菜单(二)
  7. SQL Server表和字段说明的增加和更新
  8. 关于java集合的知识点_java中集合的知识点
  9. (6)matplotlib下水平竖直线绘制
  10. 测试象棋水平用哪个软件好,佳佳象棋软件作者李国来对象棋软件引擎的专业看法及测试指导...
  11. 布客·ApacheCN 翻译/校对/笔记整理活动进度公告 2020.1
  12. 通俗易懂的方式讲解最大流和最小割问题
  13. 使用 vue-waterfall2插件 vue 瀑布流
  14. 两台计算机如何共享文档,两台电脑如何共享文件
  15. 别把项目成功当目标!——项目经理的误区(1)(转)
  16. sdhc卡文件丢失常见原因和两种恢复方法
  17. matlab求平均聚集系数,复杂网络聚类系数和平均路径长度计算的MATLAB源代码
  18. 查询主机名对应的IP地址-C语言
  19. 蓝牙芯片NRF51822入门学习:时间管理
  20. 使用Cython提高python代码执行速度

热门文章

  1. 开源 java CMS - FreeCMS2.4 模型管理
  2. 解决SQL Server 2008安装时提示:重新启动计算机 失败
  3. WEB数据透视表Pivot Table
  4. 我的WCF之旅(1):创建一个简单的WCF程序
  5. 关于Vue中计算属性computed和methods属性的区别,你了解多少呢
  6. java读取写入文件
  7. 深入理解this和call、bind、apply对this的影响及用法
  8. ElasticSearch 索引模块——集成IK中文分词
  9. ArcGIS License启动无响应
  10. eclipse+webservice开发实例