当前位置:网站首页>ABAP CDs table function introduction and examples
ABAP CDs table function introduction and examples
2022-07-28 01:16:00 【51CTO】
Reference blog :
《ABAP CDS Table Function Introduction and examples 》
ABAP CDS Table Function
stay ABAP CDS Table Function In the development process , We will use the field structure 、 Parameters ( Optional )、association Equal pass class / Methods are defined as entities . adopt AMDP We can go straight to ABAP Layer write stored procedure , And encapsulate it in classes / In the method , For more information, see the previous article :ABAP Medium AMDP(ABAP-Managed Database Procedures .
scene
Each airline provides flight connections to different cities in the world , Users want to see all cities supported by a particular airline in a single field , The content is separated by commas . Because the number of cities of each airline is different , We need a logic to connect cities , No matter how many pieces of data there are in the query results .
In the regular ABAP CDS We can use CONCAT function , But when using it , We need to define a fixed number of fields , since CDS The view cannot implement the processing dynamic logic required here , How to deal with it ?
This is a use of ABAP CDS Table Function A great scene , Because we can use simple database functions STRING_AGG(String Aggregation). This function is SQL Script Available in the , But it is still not supported ABAP CDS View .
Development

Edit the generated entity , Contains the following :
- Field :
- Client
- Airline Code
- Airline Name
- Cities To
- class : ZCL_FLIGHTS_DEMO_CDS
- Method : FLIGHTS_CONNECTIONS
The result should be :
Of course , Now? ZCL_FLIGHTS_DEMO_CDS There is no such thing as . next step , Let's create it :

Let class contain IF_AMDP_MARKER_HDB Interface . This step will take you ABAP Class to AMDP class , And it allows you to write stored procedures inside the methods of classes .
In the method implementation, we need to introduce some configuration options :
- BY DATABASE FUNCTION: Will mark the method as table function, Another option is through BY DATABASE PROCEDURE Mark as stored procedure .
- FOR HDB: Set the database type to HDB (HANA database ).
- LANGUAGE SQLSCRIPT: HANA Language of database storage .
- OPTIONS READ-ONLY: Data modification is not allowed in stored procedures .
- USING: Definition table function Database tables consumed in 、 Views or stored procedures . In this case , Only visit SFLIGHTS View .
Let's prepare two of the query segmentation logic SELECT sentence .
first SLECT Need to get Client, Airline Code, Airline Name and City To Field , And pass DISTINCT Keyword de duplication , Because we will find the city records of the same airline on different connection dates ,
AMDP One of the advantages of is that you can SELECT The query results of are transmitted to “ Internal table ”, And can execute new SELECT To read its data . Let's apply the benefits of this feature , And will be the first SELECT The query result of the statement is named itab_cities.
In the second SELECT in , We need to itab_cities Read data in and implement database methods STRING_AGG To gather multiple cities and airlines . In order to achieve this function, we need to be based on Client,Airline Code and Name Field GROUP BY entry . It's written in :
Be careful :table function There should always be return parameters , So remember in the last SELECT Put a RETURN sentence . in addition , Notice that we convert the field name to the previous ABAP CDS Table Function Declared field name , If you don't provide a suitable alias , When activated, the compiler will give a prompt .
class ZCL_FLIGHTS_DEMO_CDS The final version of is like this :
Execution results

边栏推荐
- Tear the source code of gateway by hand, and tear the source code of workflow and load balancing today
- 0-1 knapsack problem
- Matlab drawing - points and vectors: method and source code of vector addition and subtraction
- I/O设备的基本概念及分类
- Redis-哨兵模式
- 诺基亚宣布与博通合作开发5G芯片
- Node red interacts with tdengine
- Iperf installation and use
- Demo: the test interface receives duplicate data and creates documents in a short time
- Learning note 12: Eratosthenes screening method to find prime numbers (within 100) and magic square matrix
猜你喜欢

Fabric2.4.4 version building process (complete process)

Maximize activation

代码随想录笔记_哈希_1002查找共用字符

Cross desktop web container evolution
![论文赏析[ICLR18]联合句法和词汇学习的神经语言模型](/img/1c/5b9726b16f67dfc2016a0c2035baae.png)
论文赏析[ICLR18]联合句法和词汇学习的神经语言模型

Use of postman

110. In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe

BAT大厂测试架构师如何解读测试平台的各种争议

The cooperation between starfish OS and metabell is just the beginning

共创文旅新篇章|新起典与国华文旅签订战略合作协议
随机推荐
国产NB-IoT芯片厂商芯翼信息科技获2亿元A+轮融资
计算属性的基本使用
Swoole collaboration
浏览器视频帧操作方法 requestVideoFrameCallback() 简介
What is the reason for Chinese garbled code when dataworks transmits data to MySQL
自用图床搭建教程
Deepening the concept of linear algebra [23] 01 - points coordinate points and vectors vectors
SAP各模块优缺点和发展简析
The cooperation between starfish OS and metabell is just the beginning
Use of swarm task task
Learning note 12: Eratosthenes screening method to find prime numbers (within 100) and magic square matrix
容器网络硬核技术内幕 (7) 大海航行靠舵手
闻泰科技收购安世半导体剩余股权获得无条件通过
推荐系统-模型:wide&deep 模型
Swoole协程
0-1 knapsack problem
华为旗下哈勃投资入股VCSEL芯片厂商纵慧芯光
Redis-哨兵模式
6月19日上会,中芯国际或创造国内最快上市记录!
One year anniversary of creation, Chongba young Lang