UI Annotations SAP官方文档

ObjectModel

@ObjectModel:{
  transactionalProcessingDelegated: true,
  writeActivePersistence:         'ZCA90T_001',
  semanticKey:                    'work_order',
  representativeKey:              'db_key',
  dataCategory:                   'work_type',
  createEnabled:                  true,
  updateEnabled:                  true,
  deleteEnabled:                  false,
  draftEnabled: false,
  usageType.dataClass: #TRANSACTIONAL,
  compositionRoot: true,
  transactionalProcessingDelegated: true,
  deleteEnabled:'EXTERNAL_CALCULATION',
  updateEnabled:'EXTERNAL_CALCULATION',
  draftEnabled: true
}

CDS自动创建BOBF对象

ZCA90_C_WORK_ORDERS

@AbapCatalog.sqlViewName: 'ZCA90_IV_WORDERS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '**工单'

@ObjectModel:{
  compositionRoot:                true,
  transactionalProcessingEnabled: true,
  writeActivePersistence:         'ZCA90T_001',
  semanticKey:                    'work_order',
  representativeKey:              'db_key',
  dataCategory:                   'work_type',
  createEnabled:                  true,
  updateEnabled:                  true,
  deleteEnabled:                  true
}

ZCA90_C_WORK_ORDERS

@AbapCatalog.sqlViewName: 'ZCA90_CV_WORDERS'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '**工单'
//@Search.searchable: true
@OData.publish: true

@ObjectModel:{
  transactionalProcessingDelegated: true,
  writeActivePersistence:         'ZCA90T_001',
  semanticKey:                    'work_order',
  representativeKey:              'db_key',
  dataCategory:                   'work_type',
  createEnabled:                  true,
  updateEnabled:                  true,
  deleteEnabled:                  true
}

带有子节点的bobf

@AbapCatalog.sqlViewName: 'ZRRE_V_I_DMHD'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '设计综合管理'
@Search.searchable: true

@ObjectModel:{

  compositionRoot:                true,
  transactionalProcessingEnabled: true,
  writeActivePersistence:         'ZRRE_D_DMCPH',
  semanticKey:                    [ 'dspid', 'itmnr' ],
  representativeKey:              'db_key',
  createEnabled:                  true,
  updateEnabled:                  true,
  deleteEnabled:                  true
}

define view ZRRE_I_DMHD as select from zrre_d_dmcph as root
association [0..*] to ZRRE_I_DMYT  as _yt on $projection.db_key = _yt.parent_key 
association [0..*] to ZRRE_I_DMBC  as _bc    on $projection.db_key = _bc.parent_key
association [0..*] to ZRRE_I_DMPS  as _ps    on $projection.db_key = _ps.parent_key
association [0..*] to zrre_i_dmcg  as _cg    on $projection.db_key = _cg.parent_key
association [0..*] to zrre_i_dmfa  as _fa    on $projection.db_key = _fa.parent_key
association [0..*] to zrre_i_dmpk  as _pk on $projection.db_key = _pk.parent_key 
association [0..*] to zrre_i_dmtz  as _tz    on $projection.db_key = _tz.parent_key
association [0..*] to zrre_i_dmfy  as _fy    on $projection.db_key = _fy.parent_key
association [0..*] to zrre_i_dmxe  as _xe    on $projection.db_key = _xe.parent_key
association [0..*] to zrre_i_dmpg  as _pg    on $projection.db_key = _pg.parent_key
association [0..*] to ZRRE_I_DMaw as _aw    on $projection.db_key = _aw.parent_key
association [0..*] to ZRRE_I_DMZBH as _zbh    on $projection.db_key = _zbh.parent_key
association [0..*] to ZRRE_I_DMDW as _dw    on $projection.db_key = _dw.parent_key
association [0..*] to zrre_i_dmcn as _cn    on $projection.db_key = _cn.parent_key
association [0..*] to ZRRE_I_SJRZ as _rz    on $projection.db_key = _rz.parent_key
{
    key root.db_key ,
	.....
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _pk , // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _fy,
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _tz,
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _xe,
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _pg, // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _yt , // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _ps,
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _cg,
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _fa,
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _bc, // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _aw, // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _rz, // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _dw, // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _zbh, // Make association public
    @ObjectModel.association.type: #TO_COMPOSITION_CHILD   _cn // Make association public

自定义按钮

dataAction即BOBF的anction

1692151091974.png

效果图

1692151217231.png

@UI: {lineItem: [
             { type: #FOR_ACTION, invocationGrouping: #CHANGE_SET, position: 1, dataAction: 'BOPF:SEND_BPM',  label: '发布' },
             { type: #FOR_ACTION, invocationGrouping: #CHANGE_SET, position: 3, dataAction: 'BOPF:DEL_ROOT'  ,  label: '删除' } ],
  fieldGroup: [{ qualifier: 'DocData', position: 10 }]
}
id;

默认排序

@UI.presentationVariant: [{
        sortOrder : [{ by: 'created_date', direction: #DESC },{ by: 'created_time', direction: #DESC }]}]
define view Z**CLBX{
...
}

虚拟节点

@ObjectModel.virtualElement: true
@ObjectModel.virtualElementCalculatedBy: 'zrre_cl_get_dmcp_progress'
cast( ''  as abap.char(6)) as sjps,

zrre_cl_get_dmcp_progress需要实现接口IF_SADL_EXITIF_SADL_EXIT_CALC_ELEMENT_READ
在Methodif_sadl_exit_calc_element_read~calculate中可以实现对虚拟节点的修改

注意: 虚拟节点只对前台页面有效,直接访问View是不会进入类执行的

输入框搜索帮助

GUI样式弹出式搜索帮助

1692148946841.png

ZCA90_C_WORK_TYPE

@AbapCatalog.sqlViewName: 'ZCA90_V_F4WTYPE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: '需求类型'
define view ZCA90_C_WORK_TYPE as select from dd07t
{
    key domvalue_l,
    ddtext
} where domname = 'ZCAD_WORK_TYPE'

ZCA90_C_WORK_ORDERS

define view ZCA90_C_WORK_ORDERS as select from ZCA90_I_WORK_ORDERS as _h
association [1] to ZCA90_C_WORK_TYPE           as _wtype  on  domvalue_l = $projection.work_type
{
....

	@Consumption.valueHelp: '_wtype'
	@ObjectModel: { foreignKey.association: '_wtype', mandatory: true }
	work_type,
	@ObjectModel.readOnly: true
	_wtype.ddtext as ddtext,
}

联动搜索帮助

成本中心根据公司代码进行联动搜索
1693194209096.png

1693194325490.png

实现方法:

ZERS_I_KOSTL

@AbapCatalog.sqlViewName: 'ZERS_IV_KOSTL'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '成本中心搜索帮助'
@VDM.viewType: #COMPOSITE

@ObjectModel.dataCategory: #VALUE_HELP
@ObjectModel.usageType.serviceQuality: #C
@ObjectModel.usageType.sizeCategory: #S
@ObjectModel.usageType.dataClass: #MIXED
@Search.searchable : true
define view ZERS_I_KOSTL
  as select distinct from csks  as _ks
    left outer join       cskt  as _Kt  on  _Kt.kokrs = _ks.kokrs
                                        and _Kt.kostl = _ks.kostl
                                        and _Kt.datbi = _ks.datbi
                                        and _Kt.spras = $session.system_language
    left outer join       cepct as _Pct on  _Pct.prctr = _ks.prctr
                                        and _Pct.datbi >= $session.system_date
                                        and _Pct.kokrs = _ks.kokrs
                                        and _Pct.spras = $session.system_language
{
           @Search.defaultSearchElement: true
           @ObjectModel.text.element: ['ltext']
           @UI.textArrangement: #TEXT_FIRST
           @EndUserText.label: '成本中心'
  key      _ks.kostl,

           @Consumption.filter.hidden: true
           @EndUserText.label: '公司代码'
           _ks.bukrs,

           @Search.defaultSearchElement: true
           @EndUserText.label: '成本中心描述'
           @Semantics.text: true
           _Kt.ktext  as ltext,

           @Search.defaultSearchElement: true
           @ObjectModel.text.element: ['ltext2']
           @UI.textArrangement: #TEXT_FIRST
           @EndUserText.label: '利润中心'
           _ks.prctr,

           @Search.defaultSearchElement: true
           @EndUserText.label: '利润中心描述'
           @Semantics.text: true
           _Pct.ltext as ltext2
}
where
      _ks.datab <= $session.system_date
  and _ks.datbi >= $session.system_date

ZERS_C_CLBX

@ObjectModel.mandatory: true
@ObjectModel.readOnly: 'EXTERNAL_CALCULATION'
@ObjectModel.foreignKey.association: '_Kostl'
@UI.textArrangement: #TEXT_FIRST
@Consumption.valueHelpDefinition:[{entity:{name:'ZERS_I_KOSTL',element:'kostl'},
additionalBinding: [{ element: 'bukrs',localElement: 'bukrs',usage:#FILTER}]}]
@EndUserText.label: '成本中心'
_Rot.kostl,

下拉列表

在弹出式搜索帮助的基础上增加新注解
1692149312860.png

ZCA90_C_WORK_TYPE

@AbapCatalog.sqlViewName: 'ZCA90_V_F4WTYPE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: '需求类型'
@ObjectModel.resultSet.sizeCategory:  #XS
define view ZCA90_C_WORK_TYPE as select from dd07t
{
    @EndUserText.label: '需求类型'
    @ObjectModel.text.element:['ddtext']
    @ObjectModel.text.reference.association: 'ddtext'
    key domvalue_l,
    @EndUserText.label: '需求类型'
    ddtext
} where domname = 'ZCAD_WORK_TYPE'

基础注解

@AbapCatalog.sqlViewName: 'ZCGCX_C4'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: '设计成果'
@Search.searchable: true
//使用Metadata Extensions
@Metadata.allowExtensions: true
//CDS View发布为Odata Service服务
@OData:{ publish: true }
@EndUserText.label: '需求类别'//字段描述
@ObjectModel.readOnly: true //只读
@UI: {
      lineItem: [ { position: 30, label: '需求类别', importance: #HIGH } ],//在行项目中显示
	  selectionField: [ { position: 30 } ],//设置为选择条件
      identification:[ { position: 30, label: '需求类别'} ],//在详情页中显示
	  fieldGroup: [{ qualifier: 'DocData', position: 30 }]}//在详情页中的页签设置

@UI.multiLineText:true //长文本

默认搜索

@Search.searchable: true //设置CDS带有默认搜索框

//设置默认搜索框的搜索字段,可以多个,可以用来做全文搜索
@Search.defaultSearchElement: true
work_type,

列表字段值编码显示为描述

@ObjectModel.text.element: ['ddtext']
@UI.textArrangement: #TEXT_ONLY //只显示文本:TEXT_ONLY、文本在前:TEXT_FIRST、文本在后:TEXT_LAST、TEXT_SEPARATE
work_type,
@ObjectModel.readOnly: true
_wtype.ddtext as ddtext,

抬头信息

@UI.headerInfo.title.value: 'work_order'

@UI: {
    headerInfo: {
    typeName: '**工单',
    typeNamePlural: '**工单',
    title: { type: #STANDARD, label: '**工单' }
    }
}

TAB页签

@UI.facet: [
        {
            label: '基本信息',
            id : 'ItemData',
            //parentId : 'Header',
            type : #FIELDGROUP_REFERENCE,
            targetQualifier : 'DocData'
        },
        {
            label: '需求描述',
            id : 'QuestionDesc',
            //parentId : 'Header',
            type : #FIELDGROUP_REFERENCE,
            targetQualifier : 'QuestionDesc'
        },
        {
            label: '附件信息',
            id : 'InternalInfo',
            //parentId : 'Header',
            type : #FIELDGROUP_REFERENCE,
            targetQualifier : 'InternalInfo'
        },
        {
            label: '办理记录',
            id : 'RecordInfo',
            //parentId : 'Header',
            type : #FIELDGROUP_REFERENCE,
            targetQualifier : 'RecordInfo'
        },
        {
            label: '解决方案详细描述',
            id : 'SolutionDesc',
            //parentId : 'Header',
            type : #FIELDGROUP_REFERENCE,
            targetQualifier : 'SolutionDesc'
        }
      ]

1692147926157.png

超链接

RevReason: CDS View中的字段,url地址

@UI: { lineItem : [{ position : 170 , label: '详情' } , {type: #WITH_URL,url: 'RevReason'} ],
       identification:[ { position: 170, label: '详情'  ,type: #WITH_URL,url: 'RevReason'} ] ,
       fieldGroup: [{ qualifier: 'DocData', position: 170 }]
       }
  xq;

草稿

@AbapCatalog.sqlViewName: 'ZERS_IV_SQ_ROT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #COMPOSITE
@ObjectModel:{
    modelCategory: #BUSINESS_OBJECT,
    semanticKey:['db_key'],
    compositionRoot:true,
    createEnabled:true,
    updateEnabled:'true',
    deleteEnabled:'true',
    draftEnabled: true,
    entityChangeStateId: 'changed_at',
    writeActivePersistence:'ZERST_SQ_ROT',
    writeDraftPersistence: 'ZERST_SQ_ROT_D',
    transactionalProcessingEnabled:true
}

CDS with Parameters

在查询语句中,参数必须紧接在对应的数据源后边,作为一个整体来使用,否则不能通过语法检查 测试用CDS
View如下图所示,该视图需要传入两个参数 ip_matnr 以及 ip_langu

SELECT *
  FROM zcds_demo( ip_matnr = 'DHA_DEMO_1',
                  ip_langu = @sy-langu ) AS a 
  INTO TABLE @DATA(lt_data).