SAP Fiori Elements如何基于domain fixed value创建下拉菜单
发布日期:2021-06-30 14:25:51 浏览次数:2 分类:技术文章

本文共 7037 字,大约阅读时间需要 23 分钟。

Several days ago I wrote a blog which introduces how to create a drop down list based on values from a backend table.

For example, the status list in above screenshot comes from the three entries in database table ZSTATUS_FIXEDVAL.

And now a new requirement is to use the fixed value defined in an ABAP domain instead.

Here below are steps to achieve it.

(1) Create an ABAP domain named ZORDER_STATUS_DOMAIN containing status list as displayed in previous screenshot.

Then create an ABAP data element based on this domain.
Create one header database table as root,

and another database table as item.

(2) create two CDS views based on the two database tables accordingly:

@AbapCatalog.sqlViewName: 'zorheader'@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: 'header view'define view Z_I_Order_Header as select from zorder_headerassociation [0..*] to Z_I_Order_Item as _Itemon $projection.object_id = _Item.parent_id{  key zorder_header.object_id,  zorder_header.description,  zorder_header.order_status,  zorder_header.order_status_text,  @ObjectModel.association.type: #TO_COMPOSITION_CHILD  _Item}@AbapCatalog.sqlViewName: 'zorITem'@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: 'order item detail'define view Z_I_Order_Item as select from zorder_item {  @UI.lineItem : [{position:10, label : 'Parent ID'}]  key zorder_item.parent_id,  @UI.lineItem : [{position:20, label : 'Item Number'}]  key zorder_item.item_id,  @UI.lineItem : [{position:30, label : 'Item Description'}]  zorder_item.item_text,  zorder_item.item_type}

Then the consumption CDS view:

@AbapCatalog.sqlViewName: 'zjorderview'@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: 'Jerry order consumption view'@Search.searchable: true@OData.publish: false@ObjectModel: {   compositionRoot: true,   type: #CONSUMPTION,   transactionalProcessingDelegated: true,   createEnabled,   deleteEnabled,   updateEnabled}@UI.headerInfo:{  typeName:       'Jerry Service Order',  typeNamePlural: 'Jerry Service Orders',  title: { value: 'object_id' },  description: { value: 'description' }}define view Z_C_Order as select from Z_I_Order_Header {  @UI.lineItem : [{position:10, label : 'Service Order ID'}]  @UI.identification: [ { position: 10,  label : 'Service Order ID' } ]  @Search:{ defaultSearchElement: true, ranking: #HIGH, fuzzinessThreshold: 0.8 }  @UI.selectionField: [ { position: 20, label : 'Service Order ID' } ]  key Z_I_Order_Header.object_id,  @UI.lineItem : [{position:20, label : 'Service Order Description'}]  @UI.identification: [ { position: 20,  label : 'Service Order Description' } ]  @Search:{ defaultSearchElement: true, ranking: #HIGH, fuzzinessThreshold: 0.8 }  @UI.selectionField: [ { position: 10, label : 'Description' } ]  Z_I_Order_Header.description,  @UI.identification: [ { position: 30,  label : 'Order Status' } ]  Z_I_Order_Header.order_status,  Z_I_Order_Header.order_status_text,  @ObjectModel.association.type: [#TO_COMPOSITION_CHILD]  Z_I_Order_Header._Item}

Now all are done except remaining work in ABAP side.

(3) Create a new project via tcode SEGW and include the activated consumption CDS view created in step2. If you don’t know how to do it, refer to this blog .

Generate runtime artifacts. Now both DPC and MPC classes are generated.

3.1 Redefine DEFINE method of your MPC_EXT class:

super->define( ).    zcl_fis_shlp_annotation=>create(      io_odata_model = model      io_vocan_model = vocab_anno_model      iv_namespace = 'sap'      iv_entitytype = 'Z_C_OrderType'      iv_property = 'order_status'      iv_search_help = space      iv_search_supported = abap_false      iv_search_help_field = space      iv_valuelist_entityset = 'OrderStatusEntitySet'      iv_valuelist_property = 'Code' ##NO_TEXT      )->add_display_parameter( iv_valuelist_property  = 'Text' ).    data(lo_txt_property) = model->get_entity_type( 'Z_C_OrderType' )->get_property( 'order_status' ).    lo_txt_property->set_value_list( /iwbep/if_mgw_odata_property=>gcs_value_list_type_property-fixed_values ).    data(lo_text_anno) = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).    lo_text_anno->add( iv_key = 'text' iv_value = 'order_status_text').    lo_txt_property = model->get_entity_type( 'OrderStatus' )->get_property( 'Code' ).    lo_txt_property->set_value_list( /iwbep/if_mgw_odata_property=>gcs_value_list_type_property-fixed_values ).    lo_text_anno = lo_txt_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).    lo_text_anno->add( iv_key = 'text' iv_value = 'Text').

The code above will generate the highlighted annotations which could be found in metadata:

3.2 Since in 3.1, the entity set OrderStatusEntitySet and entity type OrderStatus do not exist in SEGW project yet, so now we have to create them manually.

Just create them from context menu by clicking Entity Types and Entity Sets in SEGW:

Create properties for entity type:

And assign entity type to newly created entity set. After that regenerate runtime artifacts.

3.3 Since now framework knows it should display the value of order_status_text to render the drop down list, so we are responsible to provide framework with correct content.

Redefine method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET of your DPC_EXT:

METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset.    CASE iv_entity_name.      WHEN 'OrderStatus'.        get_Status_list( IMPORTING er_entityset = er_entityset ).      WHEN OTHERS.        TRY.            CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset              EXPORTING                iv_entity_name           = iv_entity_name                iv_entity_set_name       = iv_entity_set_name                iv_source_name           = iv_source_name                it_filter_select_options = it_filter_select_options                it_order                 = it_order                is_paging                = is_paging                it_navigation_path       = it_navigation_path                it_key_tab               = it_key_tab                iv_filter_string         = iv_filter_string                iv_search_string         = iv_search_string                io_tech_request_context  = io_tech_request_context              IMPORTING                er_entityset             = er_entityset                es_response_context      = es_response_context.          CATCH /iwbep/cx_mgw_busi_exception .          CATCH /iwbep/cx_mgw_tech_exception .        ENDTRY.        IF iv_entity_name = 'Z_C_OrderType'.          fill_status_text( CHANGING cr_entityset = er_entityset ).        ENDIF.    ENDCASE.  ENDMETHOD.

The method fill_status_text is responsible for filling the field order_status_text.

Note: if you comment out the line 40 and 46,

The annotation for order_status_text will become “standard”, instead of previous “fixed-values”.

In this case, this field will be rendered as F4 value help instead:

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

转载地址:https://jerry.blog.csdn.net/article/details/108024705 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:SAP CDS view自学教程之五:如何开发支持Odata navigation的CDS view
下一篇:如何处理新建的SAP CRM产品category没有出现在列表的问题

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月26日 10时20分41秒