`
JerryWang_SAP
  • 浏览: 1042204 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

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

阅读更多

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_DETAIL
  with parameters @Environment.systemField: #CLIENT
                  clnt:abap.clnt
  returns { 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 method
    zcl_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 DEFINITION
  PUBLIC
  FINAL
  CREATE 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_but000
        BY DATABASE FUNCTION FOR HDB
        LANGUAGE SQLSCRIPT
        OPTIONS READ-ONLY
        USING 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 name
                  FROM crmd_partner AS sc
                    INNER JOIN but000 AS sp ON sc.client = sp.client AND
                                              sc.partner_no = sp.partner_guid
                    WHERE sc.client = :clnt AND
                          sc.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.title
    when '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的原创文章,请关注公众号"汪子熙":

0
0
分享到:
评论

相关推荐

    HANA-CDS view 教程

    在这个“S4D430 Building Views in Core Data Services ABAP (CDS ABAP)”的教程中,你将深入学习如何使用ABAP(Advanced Business Application Programming)来构建CDS视图。这个为期三天的课程旨在帮助参与者掌握...

    SAP-CDSView-Eclipse安装及创建步骤.doc

    SAP CDS (Core Data Services) 视图是SAP HANA数据库中的一种高级数据建模工具,它允许开发者创建高性能的数据模型,尤其在处理多表关联查询时能显著提升性能。CDS 视图使用声明式语言定义,并且可以直接在数据库...

    在SAP中查询TABLE的18种方法

    ### SAP中查询Table的18种方法 #### 概述 在SAP系统中,查询Table数据是一项常见的任务,尤其对于开发人员和技术支持人员来说更是如此。本文将介绍18种查询Table的方法,并重点讲解其中较为常用的部分。通过这些...

    完整版自学sap初级教程

    在"完整版的sap初级技能自学教程.pdf"中,你将详细学习以上内容,并逐步建立起对SAP系统的基本理解和操作能力。通过深入学习,你可以为进入SAP领域打下坚实的基础,为未来的职业生涯开启新的可能。

    史上最强大的Sap2000自学教程

    ### SAP2000自学教程知识点详解 #### 一、SAP2000简介 - **背景**:SAP2000是一款强大的结构分析软件,它利用有限元法进行结构分析,广泛应用于土木工程领域。 - **特点**: - **集成环境**:在单一的图形用户...

    完整版的sap初级技能自学教程

    完整版的sap初级技能自学教程。学习SAP的入门教程。

    SAP table control使用介绍

    在 SAP 的 ABAP 开发环境中,Table Control 是一种非常强大的工具,用于在屏幕上显示表格数据。它提供了丰富的功能来展示复杂的数据,并且允许用户进行灵活的交互操作。Table Control 可以被看作是一种特殊的屏幕...

    SAP初级技能自学教程

    ### SAP初级技能自学教程知识点概览 #### 一、引言 - **SAP简介**:SAP(System Applications and Products)是指一套在线财务及行政软件系统,同时也是开发这套系统的公司的名称。它由多个模块组成,每个模块负责...

    SAP PO/PI教程 Process Orchestration The Comprehensive Guide

    SAP Process Orchestration The Comprehensive Guide, 2nd Edition SAP流程编制综合指南 1 Introduction to SAP Process Orchestration 1.1 Historical Overview and Evolution 1.1.1 SAP Process Integration ...

    SAP SMARTFORMS 报错弹框 CSapEditorCtrl::GetObject: Object 13(16)does not exist的解决方法

    安装sap gui 750后,打开smartforms或scriptforms提示:CSapEditorCtrl::GetObject: Object 13 does not exist的解决方法:安装此安装包后即可解决问题

    SAP PI/SAP PO 详细教程(手把手教学)

    《SAP PI/SAP PO 详细教程:从基础到实践》 SAP PI(Process Integration)和SAP PO(Process Orchestration)是SAP提供的集成解决方案,用于连接不同的业务系统,实现数据交换和流程自动化。本教程将带你深入了解...

    SAP各模块常用TABLE

    SAP各模块常用TABLE

    cds-scp-api:用于SAP Cloud Platform API消费的CDS扩展

    节点模块CDS-SCP-API在SAP Cloud Platform上的Cloud Application Programming(CAP)模型中简化了来自SAP OnPremise和Cloud API,Microsoft Office 365 API,Google Cloud Platform API和其他REST API的消耗性外部...

    sap初级技能自学教程

    四、SAP自学路径 1. 学习SAP基础知识:了解SAP系统架构、模块功能以及其在企业中的应用。 2. 选择学习模块:根据个人职业兴趣或企业需求,选择特定的SAP模块进行深入学习。 3. ABAP编程入门:学习ABAP基础语法、...

    SAP Partner function

    SAP Partner Function 的两重值之迷 在 SAP 系统中,Partner Function 是一个非常重要的概念,它在业务流程中的应用非常广泛。今天,我们来讨论一个关于 Partner Function 的两重值的问题。这个问题来自于一个报表...

    SAP ABAP开发学习——第3课:数据字典2(视频教程)

    在SAP ABAP开发的学习过程中,数据字典是至关重要的组成部分,它为系统中的所有数据库对象提供了元数据的定义和管理。本课程“SAP ABAP开发学习——第3课:数据字典2”深入讲解了这个核心概念,旨在帮助初学者掌握...

    SAP Table Relations [zt]

    标题"SAP Table Relations [zt]"指的是关于SAP系统中的表关系知识,这通常涉及到数据库设计、数据模型以及SAP ABAP编程。SAP是企业级的业务应用软件,其核心部分是R/3系统,使用ABAP(Advanced Business Application...

    SAP ABAP开发学习——第14课:动态SQL(视频教程)

    在本课程中,我们将深入探讨SAP ABAP中的一个重要概念——动态SQL,这对于任何希望成为专业ABAP开发人员的人来说都是必不可少的知识。SAP ABAP(Advanced Business Application Programming)是SAP系统中用于开发...

Global site tag (gtag.js) - Google Analytics