SAP CDS View 开发「实例」

前言

  • CDS 基础概念
  • CDS 意义 & 使用场景
  • 开发环境 ADT 部署
  • CDS 实例 & 语法
  • ABAP 视图查询

CDS 概念

参见文章:CDS View-Part 1 & Part 2 介绍


开发环境

To install the front-end component of ADT, proceed as follows: 「消息源

  1. Get an installation of Eclipse 2022-09 (x86_64) (e.g. Eclipse IDE for Java Developers)

  2. Get the right version for your own Eclipse.

  3. In Eclipse, choose in the menu bar Help > Install New Software…在这里插入图片描述

  4. Enter the URL https://tools.hana.ondemand.com/latest

  5. Press Enter to display the available features.

  6. Select ABAP Development Tools and choose Next.

  7. On the next wizard page, you get an overview of the features to be installed. Choose Next.

  8. Confirm the license agreements and choose Finish to start the installation.

  9. Toggle the Panel View.[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-93ObCGuw-1669792079296)(./assets/SAP-CDS-View-02.png)]


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.

查询结果:

在这里插入图片描述

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wriprin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值