CDS view里case – when – else关键字的用法

  • 2020 年 2 月 17 日
  • 筆記

Requirement

The following mapping logic needs to be implemented in CDS view layer: if MARA-MTART = “SERV”, then PRODUCT_TYPE = “02” if MARA-MTART <> “SERV” and PROD_TYPE_CODE = ‘2’, then PRODUCT_TYPE = “02” otherwise PRODUCT_TYPE = ''01". View source code:

@AbapCatalog.sqlViewName: 'ZMATTYPE'  @AbapCatalog.compiler.compareFilter: true  @AccessControl.authorizationCheck: #CHECK  @EndUserText.label: 'material type'  define view Zmaterial_Type as select from mara inner join t134 on mara.mtart  = t134.mtart {    key mara.scm_matid_guid16 as product_guid,     case      when ( mara.mtart = 'SERV') or t134.prod_type_code = '2'       then '02'      else '01'    end as product_type  }