SAP Fiori Elements裡Drop down list的實現原理
In the blog Step by Step to create CDS view through SmartTemplate + WebIDE and Create a CRM Service Order Fiori application within a couple of minutes we get an Fiori application generated which needs several fine-tuning on appearance. For example, the status field is by default rendered as a pure input field with technical status code like “OPEN”, “PROC” displayed. It is better to render it as a drop down list with human readable text like “Open”, “In process” displayed as drop down list item.
I searched in SCN and could not find a working solution for it, so I spent some time for research and would like to share with you here.
Step1 Create a simple CDS view to hold status code and status description
@AbapCatalog.sqlViewName: 'zstatusfixed'@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #CHECK@EndUserText.label: 'fixed value'define view Z_C_Status_Fixedvalue as select from zstatus_fixedval {
@EndUserText.label: 'status key for fixed value'
key zstatus_fixedval.status_code,
@EndUserText.label: 'status description for fixed value'
zstatus_fixedval.status_text}
Previewed as below:
Here below is the table definition on top of which the CDS view above is created.
For demonstration purpose I create a Z table and only inserted three status items:
Step2 link the status field to the CDS view created in previous step
I have defined the consumption view Z_C_Service_Order_View with below source code:
define view Z_C_Service_Order_View as select from Z_i_Order_View...@UI.identification: [ { position: 50 } ]@Consumption.valueHelp: '_statusfixedvalue'@ObjectModel: { foreignKey.association: '_statusfixedvalue', mandatory: true }Z_i_Order_View.txt04,
Where does the definition of “_statusfixedvalue” come from? It is defined in view Z_i_Over_View:
define view Z_i_Over_View as select from XXXXassociation [0..1] to Z_C_Status_Fixedvalue as _statusfixedvalue
on $projection.txt04 = _statusfixedvalue.status_code{
...
_status_text.txt04,
...
@ObjectModel.association.type: #TO_COMPOSITION_CHILD
_statusfixedvalue}
So far the work on CDS side is done.
Step3 create necessary annotation in ABAP code
Prerequisite: you should first create a project using tcode SEGW and then include your CDS consumption view via the context menu as below:
Redefine method DEFINE of your MPC_EXT class with following source code:
super->define( ).
DATA lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation.
DATA lo_property TYPE REF TO /iwbep/if_mgw_odata_property.
DATA lo_entity_set TYPE REF TO /iwbep/if_mgw_odata_entity_set.
lo_entity_set = model->get_entity_set( 'Z_C_Service_Order_View' ).
lo_annotation = lo_entity_set->create_annotation( 'sap' ).
lo_annotation->add( iv_key = 'semantics' iv_value = 'fixed-values').
DATA(lo_entitytype) = model->get_entity_type( 'Z_C_Service_Order_ViewType' ).
lo_entitytype->set_is_value_list( abap_true ).
data(lo_txt_property) = model->get_entity_type( 'Z_C_Service_Order_ViewType' )->get_property( 'txt04' ).
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 = 'to_statusfixedvalue/status_text').
lo_txt_property = model->get_entity_type( 'Z_C_Status_FixedvalueType' )->get_property( 'status_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 = 'status_text').
Note: those ABAP code is necessary, or else you will only get an ugly drop down list: only status code is displayed:
Final result
In display mode and in edit mode, the status description is displayed:
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2722159/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP Fiori Elements List Report Smart Table Toolbar 的 XML 檢視實現XML
- SAP Fiori Elements 框架裡 Smart Table 控制元件的工作原理介紹框架控制元件
- SAP Fiori Elements controller extension 的載入原理Controller
- SAP Fiori Elements List Report 裡的表格型別(tableType)是如何決定出來的型別
- 如何在 SAP Fiori Elements List Report 表格工具欄裡增添新的自定義按鈕
- SAP Fiori Elements 應用裡和 Fiori 3 相關的外觀設定
- SAP CDS view自學教程之八:SAP Fiori Elements裡不同型別的annotationView型別
- Fiori裡花瓣的動畫效果實現原理動畫
- 深入掌握 SAP Fiori Elements 工作原理的前提條件:理解 Smart Field
- SAP WebClient UI drop down list(下拉選單)的一個故障和解決方法WebclientUI
- 如何檢視 SAP Fiori Elements List Report Table 都支援哪些設定
- SAP Fiori Elements 應用裡的 Title 顯示的內容是從哪裡來的
- SAP Fiori Elements 在本地測試模式下如何修改 List Report 裡欄位標籤和圖示模式
- SAP Fiori裡兩種鎖機制(lock)的實現
- SAP Fiori Elements List Report 列表寬度決定邏輯的單步除錯除錯
- SAP Fiori Elements List Report Smart Table 列專案寬度計算的奧妙
- 使用 mock 資料在本地執行 SAP Fiori Elements 應用的工作原理Mock
- SAP Fiori Elements 公開課第二單元學習筆記:Fiori Elements 架構筆記架構
- SAP Fiori裡的List是如何做到懶載入Lazy load的
- Fiori Elements List Report table 裡的普通按鈕,Global 按鈕 和 Determining 按鈕
- SAP Fiori Elements 本地專案的 annotations.xml 檔案XML
- SAP Fiori image的顯示原理
- 如何給 SAP Fiori Elements 應用的欄位新增 value help
- SAP S/4HANA Material Fiori應用的搜尋實現原理
- 如何分辨 SAP Fiori Launchpad 裡的真假 Fiori 應用
- 如何使用 mock 資料在本地執行 SAP Fiori ElementsMock
- 如何給 SAP Fiori Elements 應用新增自定義按鈕
- SAP Fiori 應用裡圖示(Icon)的渲染原理和使用技巧
- SAP Fiori Elements 應用的 i18n 語法使用方式
- SAP Fiori裡的兩種鎖機制
- 如何將自定義XML檢視注入SAP Fiori Elements應用XML
- SAP Fiori應用裡出現http request錯誤的原因分析HTTP
- Open SAP 上 SAP Fiori Elements 公開課第一單元學習筆記筆記
- SAP Hybris裡搜尋顯示結果的實現原理
- 使用Fiori Elements建立的SAP UI5應用,如何支援編輯功能UI
- SAP Fiori Launchpad頁面在伺服器端的配置背後的實現原理伺服器
- SAP Fiori Elements 學習筆記 - 2021年4月19日筆記
- 如何在 SAP BTP 上通過 CDS view 快速建立 Fiori Elements 應用View