zoukankan      html  css  js  c++  java
  • SAP技术

    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.

    clipboard1

    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.

    clipboard2

    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:

    clipboard3
    clipboard4

    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.

    clipboard5

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

    clipboard6

    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.

    clipboard8

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":
    公众号截图

  • 相关阅读:
    CopyOnWriteArrayList 写时复制思想
    CAS中ABA问题的解决
    彻底解决Chrome“请停用以开发者模式运行的扩展程序”提示(亲测整合)
    解决软件安装无法自定义文件夹,自动安装在C盘 (Windows系统)
    IDEA降低注解检测级别
    大白话带你认识JVM(转)
    Windows 与 Linux (CentOS7) 之间的文件共享
    Dubbo、Zookeeper 以及 Tomcat 启动的相关问题
    创建 maven 项目的时候遇到的问题
    MyBatis 项目的 jar 包导入与源码导入
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/12054487.html
Copyright © 2011-2022 走看看