SAP CDS View 开发「实例」
前言
- CDS 基础概念
- CDS 意义 & 使用场景
- 开发环境 ADT 部署
- CDS 实例 & 语法
- ABAP 视图查询
CDS 概念
开发环境
To install the front-end component of ADT, proceed as follows: 「消息源」
Get an installation of Eclipse 2022-09 (x86_64) (e.g. Eclipse IDE for Java Developers)
In Eclipse, choose in the menu bar Help > Install New Software…
Enter the URL https://tools.hana.ondemand.com/latest
Press Enter to display the available features.
Select ABAP Development Tools and choose Next.
On the next wizard page, you get an overview of the features to be installed. Choose Next.
Confirm the license agreements and choose Finish to start the installation.
Toggle the Panel View.
CDS 实例
创建 ABAP Project
,配置 Router
账户等相关信息 连接 服务器,按照提示一步步来即可
创建实例 Data Definition
Package
按需填写,我在这里不传输,$TMP
本地对象即可,填写 Name and Description
选择模板,Finish
即可
以模板为基底,写一个简单的 DEMO
实例具体代码如下:
/*指定了数据库 SQL View 的名字,在 CDS View 激活时,会在数据库层生成对应的 SQL View*/
@AbapCatalog.sqlViewName: 'ZV_DEMO01' /*(SE11 可查看,最长 16 位字符)*/
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true /*值为 TRUE 时,SQL view 中的 key 字段使用 CDS 中定义的 key; 值为 FALSE 时,使用 DB table 中 table 的 key field.*/
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS_BASIC_DEMO'
// First DEMO
define view ZCDS_DEMO01 /* CDS 视图(最长 30 个字符,与 SQL view 两者在开发应用基本相同,命名不可重名*/
as select from sbook
{
carrid,
connid
}
Ctrl + F3
激活后 F8
执行(快捷键与 GUI
端大体一致)
CDS 语法
参见文章:SAP CDS View 基础语法
ABAP 视图查询
注意与 SELECT
底表时查询条件的 差异
CDS
代码如下:
@AbapCatalog.sqlViewName: 'ZVDEMO03'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'between and'
define view ZCDS_DEMO03
with parameters
p_distance_l : s_distance,
p_distance_h : s_distance,
p_unit : s_distid,
p_mandt : mandt
as select from spfli
{
key mandt,
key carrid,
key connid,
cityfrom,
cityto,
distance,
distid
}
where distid = :p_unit
and distance between :p_distance_l and :p_distance_h
and mandt = :p_mandt
ABAP
代码如下:
*&--- 选择屏幕
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE TEXT-101.
PARAMETERS: p_unit LIKE spfli-distid,
p_mandt LIKE spfli-mandt,
p_dis_l LIKE spfli-distance,
p_dis_h LIKE spfli-distance.
SELECTION-SCREEN END OF BLOCK bk1.
START-OF-SELECTION.
PERFORM frm_get_data. " 获取航班数据
*&--- 获取航班数据
FORM frm_get_data.
SELECT *
INTO TABLE @DATA(lt_data)
FROM zvdemo03_yakub( p_unit = @p_unit, p_distance_l = @p_dis_l, p_distance_h = @p_dis_h, p_mandt = @p_mandt ).
cl_demo_output=>display( lt_data ).
ENDFORM.
查询结果:
文章来自于网络,如果侵犯了您的权益,请联系站长删除!