SAP CDS view自學教程之八:SAP Fiori Elements裡不同型別的annotation
Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically generate after you activate one CDS view Part3 – how is view source in Eclipse converted to ABAP view in the backend Part4 – how does annotation @OData.publish work Part5 – how to create CDS view which supports navigation in OData service Part6 – consume table function in CDS view Part7 – unveil the secret of @ObjectModel.readOnly Part8 – this blog Part9 – cube view and query view Part10 – How does CDS view key user extensibility work in S4/HANA Part11 – CDS view test double framework Part12 – CDS view source code count tool Part13 – CDS view authorization During my recent CDS view explore I have experienced several ways of CDS view annotation declaration or generation. I list them in this blog for study purpose.
Approach 1: developer does not declaration explicitly, but backend generates automatically
Take this field for example:
I do not declare any display format on this field. It has DATS data type in the backend.
When you publish this CDS view as OData service and check its metadata response, you can find the annotation “sap:display-format=Date” is automatically added. Who adds it?
Answer: it is added here. Backend framework will automatically add corresponding annotation according to the data type of exposed field.
Approach 2: developer adds one style of annotation, and backend framework detects such annotation, and do some conversion
One example of this kind of approach can already be found from tutorial 7 – unveil the secret of @ObjectModel.readOnly
In that tutorial I explained how the annotation defined by developer (@ObjectModel.readOnly: true ) is converted by backend framework into sap:updatable = false.
@ObjectModel.readOnly: true Z_i_Order_View.posting_date We can also look into another example. We have use the following annotation “@Consumption.valueHelp: ‘_statusfixedvalue’ ” to assign a value help to field txt04: @Consumption.valueHelp: ‘_statusfixedvalue’ Z_i_Order_View.txt04, When framework has scanned the annotation in line 47, it will set flag lv_consumption_vh as true.
Base on the fact whether the assigned value help is a consumption or foreign key value help, different element name are put to internal table lt_param_display and finally all the left annotation necessary for value help is generated by framework:
And this picture below explains where does each field in metadata response come from. The logic in method _add_value_help is very useful as it teaches us how to create necessary annotation via ABAP code, which we will use later.
Approach 3: developer adds necessary annotation via ABAP code
If you would like to build a drop down list based on a CDS view field like the status field below,
it is not just enough to use the annotation “Consumption.valueHelp” in CDS view source code – you would just get a drop down list with technical code of status value displayed. Instead, you must tell Smart template framework to display status description text in drop down list.
In order to archieve it, you must add the following ABAP code in DEFINE method of the MPC_EXT class of your OData service, to tell the framework that the text property for “status_code” is “status_text” by annotation. The usage of such coding to create annotation by ABAP code is learned from method _add_value_help mentioned in approach 2.
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').
For details please refer to this blog How to build a drop down list using Smart template + CDS view
Approach 4: developer adds UI related annotation in CDS view which are consumed by UI5 SmartTemplate
All UI related annotation which could be inserted into CDS view source code could be found from SAP help.
Those UI annotations will not be converted by ABAP backend:
@UI.identification: [ { position: 10 } ]Z_i_Order_View.posting_date
All UI related annotations could be retrieved via the url below:
And in the runtime, Smart-template also uses this very url to retrieve UI annotations so that it can know what styles of UI control the annotated CDS view field must be rendered as.
Conclusion
For approach 1 & 2, they sometimes look mysterious as everything happens under the hood. Fortunately we are in ABAP world and we can debug everything to clarify what confuses us by ourselves
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2722161/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP CDS view自學教程之十:SAP CDS view擴充套件性(Extensibility)實現原理View套件
- SAP CDS view自學教程之一:如何測試基於SAP CDS view自動生成的OData服務View
- SAP CDS view自學教程之二:當SAP CDS view被啟用時,背後發生了什麼View
- 如何在 SAP BTP 上通過 CDS view 快速建立 Fiori Elements 應用View
- 一步步學習 SAP CDS view Text Association 在 SAP Fiori Elements 中的應用View
- SAP ABAP CDS view 裡 INNER JOIN 和 Association 的區別View
- SAP Fiori Elements裡Drop down list的實現原理
- SAP Fiori Elements 應用裡和 Fiori 3 相關的外觀設定
- 使用SAP CDS view快速建立一個Fiori應用,管理Service OrderView
- SAP Fiori Elements List Report 裡的表格型別(tableType)是如何決定出來的型別
- SAP Fiori Elements 框架裡 Smart Table 控制元件的工作原理介紹框架控制元件
- SAP ABAP CDS view Association 引入的緣由View
- SAP Fiori Elements 應用裡的 Title 顯示的內容是從哪裡來的
- SAP Fiori Elements controller extension 的載入原理Controller
- Jerry的CDS view自學系列View
- SAP Fiori Elements 公開課第二單元學習筆記:Fiori Elements 架構筆記架構
- 如何基於 SAP CDS view 生成 object pageViewObject
- SAP Fiori Elements 本地專案的 annotations.xml 檔案XML
- SAP ABAP CDS view裡的註解在ABAP後臺是如何被解析的?View
- 如何使用 SAP CDS view 中的 currency conversion 功能View
- 在 Excel 裡使用 ODBC 讀取 SAP BTP 平臺上 CDS view 的資料ExcelView
- 如何分辨 SAP Fiori Launchpad 裡的真假 Fiori 應用
- 如何給 SAP Fiori Elements 應用的欄位新增 value help
- SAP Fiori裡的兩種鎖機制
- Open SAP 上 SAP Fiori Elements 公開課第一單元學習筆記筆記
- 如何使用 mock 資料在本地執行 SAP Fiori ElementsMock
- 如何給 SAP Fiori Elements 應用新增自定義按鈕
- 如何在 SAP Fiori Elements List Report 表格工具欄裡增添新的自定義按鈕
- SAP ABAP CDS view 檢視的 Replacement 技術介紹View
- 什麼是SAP CDS重定向檢視(Redirect View)?View
- 在 Excel 內使用 ODBC 消費 SAP ABAP CDS viewExcelView
- SAP Fiori Elements 應用的 i18n 語法使用方式
- 深入掌握 SAP Fiori Elements 工作原理的前提條件:理解 Smart Field
- 如何將自定義XML檢視注入SAP Fiori Elements應用XML
- SAP S/4HANA裡extension include view和extension view的區別View
- SAP Fiori + Vue = ?Vue
- SAP Fiori UXUX
- SAP CDS view單元測試框架Test Double介紹View框架