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 ).


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


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 ).


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



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.

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

(1) Create a new table function

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

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:


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

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”.SAP CDS view自学教程之六:如何在CDS view里消费table function

(3) Consume the created table function in CDS view

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

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.SAP CDS view自学教程之六:如何在CDS view里消费table function

(4) Test the whole solution

Click F8 on the view z_c_partner, check whether data previews as expected.


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


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


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


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


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


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

上一篇:SQL优化一例:查询条件内移,减少HASH JOIN代价


下一篇:《iOS和tvOS 2D游戏开发教程》——第2章,第2.1节Sprite Kit游戏循环