当前位置:网站首页>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

边栏推荐
- Recommended system - indicators: CTR, CVR
- 晶方科技:光刻机厂商ASML为公司参与并购的Anteryon公司的最主要客户之一
- 110. In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe
- 文件系统挂载
- The most detailed summary of common English terms in the chip industry (quick grasp of graphics and text)
- 比亚迪半导体完成8亿元A+轮融资:30家知名投资机构入局,估值已达102亿元!
- Branch and loop sentence exercises
- BigDecimal常用API
- 网络安全漏洞分析与漏洞复现
- C language programming | single dog topic explanation
猜你喜欢

C语言程序设计 | 单身狗题目讲解

iperf安装与使用

Redis cache penetration breakdown and avalanche

Redis-哨兵模式

Unknown database ‘xxxxx‘

C语言程序设计 | offsetof宏的讲解及其模拟实现

EWM收货ECC交货单校验逻辑问题

The cooperation between starfish OS and metabell is just the beginning

Node red interacts with tdengine

Introduction to the browser video frame operation method requestvideoframecallback()
随机推荐
Swoole collaboration
杂谈:一份最初就非常完善的FS跟第一版程序就要求没bug一样不切实际
If asynchronous processing is implemented according to the framework
URDF 集成 Gazebo
实现ABCD字母递增
The cooperation between starfish OS and metabell is just the beginning
Node red interacts with tdengine
吴雄昂发内部信:Arm的指控是莫须有的,现有成果不允许有任何损害!
Oracle error: ora-01722 invalid number
Recommended system model (III): fine scheduling model [LR, gbdt, wide & deep, DCN, DIN, Dien, MMOE, ple]
Canvas analog input box input
Array related knowledge
[300 opencv routines] 241. Scale invariant feature transformation (SIFT)
工具函数:把一个工作区中非空字段值付给另一个工作区相同字段
What is the reason for Chinese garbled code when dataworks transmits data to MySQL
Uni app advanced style framework / production environment
Storage of deep planing data in memory
Focus loss explanation
C语言main函数传递参数
Ford SUV "Mustang" officially went offline, safe and comfortable