参考blog:
1,Trick with parameter derivation for using analytical report variants in ABAP CDS views
https://blogs.sap.com/2017/09/29/trick-with-parameter-derivation-for-using-analytical-report-variants-in-abap-cds-views/
2,Providing Value Help
https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.5.9/en-US/ce9deec2b91746f7b2f1ca4421256754.html
我们可以使用cds view的注解为分析模型创建参数,并且可以为该参数设置value help。
1, 创建一个basis view,作为数据的来源
@AbapCatalog.sqlViewName: 'ZV_I_BASIS' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'ZFI_I_BASIS' define view ZFI_I_BASIS as select from rsadmina as t1 { @ObjectModel.text.element: ['accstdname'] '1' as accstdid, @Semantics.text: true 'IFRS' as accstdname, '0L' as p_r_la, 'P0' as p_r_la_wo_pd, 'TL' as p_r_ta, 1 as sumcount } union all select from rsadmina as t2 { @ObjectModel.text.element: ['accstdname'] '2' as accstdid, @Semantics.text: true 'RAS' as accstdname, 'LL' as p_r_la, 'P1' as p_r_la_wo_pd, 'TL' as p_r_ta, 2 as sumcount }
这里涉及到的一些注解在之前的blog中,有过介绍。另外的一些注解可以看这个说明。
2,创建search help view
@AbapCatalog.sqlViewName: 'ZV_VALUEHELP' @ObjectModel.representativeKey: 'accstdid_vh' @Search.searchable: true @EndUserText.label: 'ZFI_VALUEHELP' define view ZFI_VALUEHELP as select from ZFI_I_BASIS { @Search.defaultSearchElement: true key accstdid as accstdid_vh }
这个view的数据从之前的basis view中查找,
@Search.searchable: true 如果将该view作为search help的话,需要使用该注解。
@Search.defaultSearchElement: true 至少设置一个默认检索项目,在search help的dialog中,可以使用该字段作为检索项目。
@ObjectModel.representativeKey: 'accstdid_vh' 因为search help是作为association与其他view进行关联的,所以要指定一个字段作为key,与其他view进行关联。
3,创建cube
@AbapCatalog.sqlViewName: 'ZV_I_ACCSTANDAND' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Dictionary of IFRS/RAS standard' @Analytics.dataCategory: #CUBE define view ZFI_I_ACCSTANDAND as select from ZFI_I_BASIS association [0..1] to ZFI_VALUEHELP as _zvaluehelp on $projection.accstdid = _zvaluehelp.accstdid_vh { @ObjectModel.text.element: ['accstdname'] @ObjectModel.foreignKey.association: '_zvaluehelp' accstdid, @Semantics.text: true accstdname, p_r_la, p_r_la_wo_pd, p_r_ta, @DefaultAggregation: #SUM sumcount, _zvaluehelp }
association [0..1] to ZFI_VALUEHELP as _zvaluehelp on $projection.accstdid = _zvaluehelp.accstdid_vh 这个关联不能写在analysis view中,因为analysis view中association无效。key就是我们在之前通过注解 @ObjectModel.representativeKey来定义的。
@ObjectModel.foreignKey.association: '_zvaluehelp' 使用这个注解可以将该字段与search help的view进行关联,同时需要在view中暴露 '_zvaluehelp'。
4,创建analysis view
@AbapCatalog.sqlViewName: 'ZV_C_LEDGER3_Q' @AbapCatalog.compiler.compareFilter: true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'ZFI_C_LEDGER3_Q' @Analytics.query: true @VDM.viewType: #CONSUMPTION define view ZFI_C_LEDGER3_Q as select from ZFI_I_ACCSTANDAND { @Consumption.filter: {selectionType: #SINGLE, multipleSelections: true, mandatory: true} //@Consumption.derivation: { lookupEntity: 'ZFI_I_ACCSTANDAND', // resultElement: 'accstdid' // } accstdid, accstdname, p_r_la, sumcount }
@Consumption.filter: {selectionType: #SINGLE, multipleSelections: true, mandatory: true} 消费字段作为检索项出现,可以设置该检索项的各种属性,比如是否必输,是否为单选等。
5,生成tile与target,运行。