前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP技术 - How to create a CDS redirect view for a given database table

SAP技术 - How to create a CDS redirect view for a given database table

原创
作者头像
Jerry Wang
修改2019-12-18 10:21:00
7530
修改2019-12-18 10:21:00
举报

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.

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.

  1. 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:

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.

Redirect is also automatically done when you browse the content of ZCOMM_PRODUCT from tcode SE16:

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.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Scenario
  • Prerequisite
  • How to
  • How does redirect work under the hood
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档