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
- 细数那些在2017年被黑客滥用的系统管理工具和协议
- Compass: 在你的应用中集成搜索功能
- 列表选择Spinner
- 巧用CSS3 :target 伪类制作Dropdown下拉菜单(无JS)
- 开源的虚拟机软件 VirtualBox v1.5.2
- Farseer:一个用于Silverlight和XNA的开源物理引擎
- Visual Studio 2008 debug的时候发生郁闷的错误ContextSwitchDeadlock was detected
- LINQ TO XML
- 不被未来折叠掉:AI时代下的思考
- Google 分析的基准化测试
- WebFont 三宗罪之一:WebFont 与 FOUT
- 探究基于声明的身份标识
- 深化“互联网+先进制造业”发展工业互联网的系列解读二:打造平台体系
- WebFont 三宗罪之二:吹毛求疵的WebFont 渲染差异
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法