ABAP CDS view redirect特性介绍
Scenario
Suppose we have a database table A, and then we create a CDS redirect view B for it, then every time the READ OPEN SQL is done on table A, ABAP kernel will direct this request to view B, and serve the request with content from B.
Prerequisite
In order to make view B qualified as redirect view for table A, both A and B must have the same fields with exactly the same order and tehcnical name.
How to
(1) In order to demonstrate the logic, I create a Z table in ER9/001 with four fields as below.
![](https://user-images.githubusercontent.com/5669954/62515003-9a2dcd00-b853-11e9-8e81-77bf55d05b95.png)
Write a simple report to test:
DATA: lt_table TYPE STANDARD TABLE OF zcomm_product.
SELECT * INTO TABLE lt_table FROM zcomm_product.
WRITE: / sy-dbcnt.
Since this table is just created, so there is no content inside it, 0 is expected for output.
![](https://user-images.githubusercontent.com/5669954/62515004-9a2dcd00-b853-11e9-8f8b-75151f7865e8.png)
(2) Create a new CDS view with following source code:
@AbapCatalog.sqlViewName: 'zmara_cds'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Redirect ZCOMM_PRODUCT to MARA'
define view Zp_Mara_Redirect as select from mara {
mara.matnr as PRODUCT_ID,
case
when (mara.mtart = 'HAWA' or mara.mtart = 'INTR')
then '01'
when (mara.mtart = 'DIEN' or mara.mtart = 'COUP')
then '02'
else ''
end as product_Type,
mara.mtart as object_family
}
Note: since this is just a example, the mapping between ZCOMM_PRODUCT.PRODUCT_TYPE to MARA.MTART does not make sense from business point of view, I just use it to illustrate how a field from database table could be mapped to a CDS view ( field name and technical type must be equal ).
Once CDS view is done, activate it and assign the view to database table via menu in SE11:
![](https://user-images.githubusercontent.com/5669954/62515006-9ac66380-b853-11e9-933e-7846b3b4aef7.png)
![](https://user-images.githubusercontent.com/5669954/62515007-9b5efa00-b853-11e9-8b36-ef30fc6f49c0.png)
Once done, execute the report once again. This time, you could see the SELECT OPEN SQL on empty table ZCOMM_PRODUCT is actually redirected to MARA table - lots of entries returned.
![](https://user-images.githubusercontent.com/5669954/62515008-9b5efa00-b853-11e9-83c2-20b0a6385b03.png)
Redirect is also automatically done when you browse the content of ZCOMM_PRODUCT from tcode SE16:
![](https://user-images.githubusercontent.com/5669954/62515009-9bf79080-b853-11e9-9b60-c98ce0d55d31.png)
How does redirect work under the hood
If you perform a ST05 trace, you can observe the redirect is automatically done by ABAP runtime, no action from application side is needed.
![](https://user-images.githubusercontent.com/5669954/62515010-9bf79080-b853-11e9-9e4b-adab09c5ff08.png)
![](https://user-images.githubusercontent.com/5669954/62515012-9c902700-b853-11e9-9784-ff0fbb6cfd42.png)
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
[外链图片转存失败(img-6pVhuluB-1565624778329)(https://user-images.githubusercontent.com/5669954/60097669-68224900-9786-11e9-9f1e-e8bee08db4fa.png)]要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- 【华为云技术分享】HBase与AI/用户画像/推荐系统的结合:CloudTable标签索引特性介绍
- SAS市场研究应用介绍:组合/联合分析
- sevice__属性介绍: android:exported
- MySQL · 引擎特性 · InnoDB 事务子系统介绍
- Linux常用命令介绍(二)——压缩与解压缩命令
- Spartacus 开源项目给 SAP Commerce Cloud Storefront 共享的一些有用的特性介绍
- 有用的Chrome扩展介绍 - Octotree - GitHub code tree
- Kyma Application Connectivity 特性介绍
- 云原生应用程序运行时 Kyma 的主要特性介绍
- SAP UI5 Smart Chart 功能介绍
- DL之U-Net:U-Net算法的简介(论文介绍)、架构详解、案例应用等配图集合之详细攻略
- 【项目实战】java8新特性 - Optional介绍
- 5G系统关键无线技术介绍
- Yii2版本号新特性简单介绍
- 卡片式电脑介绍
- Elasticsearch 6.x版本全文检索学习之分布式特性介绍
- ES doc_values介绍2——本质是field value的列存储,做聚合分析用,ES默认开启,会占用存储空间
- 【云原生 • Kubernetes】k8s功能特性、k8s集群架构介绍
- 【Nvidia】nvidia 高级特性MIG详细介绍(二)
- 【Nvidia】nvidia 高级特性MIG详细介绍(一)
- Spring Cloud Ribbon(负载均衡器)介绍及使用
- 机器学习入门(一)基本概念介绍
- Kubernetes PodSecurityPolicy 资源介绍
- Jenkins介绍