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的原创文章,请关注公众号"汪子熙":

SAP CDS view自学教程之八:SAP Fiori Elements里不同类型的annotation相关推荐

  1. SAP CDS view自学教程之六:如何在CDS view里消费table function

    Let's try to resolve one real issue now. What we want to achieve is: in CRM we need a CDS view which ...

  2. 一步步学习 SAP CDS view Text Association 在 SAP Fiori Elements 中的应用

    在前一篇文章如何给 SAP Fiori Elements 应用的字段添加 value help,我们已经通过注解的方式,给 Fiori Elements 应用的 selection field,加上了 ...

  3. SAP CDS view自学教程之九:cube view和query view的实现原理

    In previous eight steps all we focus on is transactional stuff. This time let's touch some analytics ...

  4. SAP CDS view自学教程之十:SAP CDS view扩展性(Extensibility)实现原理

    目录 Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically ge ...

  5. SAP CDS view(Core Data Service)自学的一些材料和方法

    Self study和incident handling的不同之处 (1) incident handling有时间压力,遇到自己思路卡住求助同事无可厚非.而Self study没有太大的时间压力,要 ...

  6. 如何基于 SAP CDS view 生成 object page

    通过之前的文章如何在 SAP BTP 上通过 CDS view 快速创建 Fiori Elements 应用,我们已经创建了一个 CDS view,并基于该 CDS view,创建了一个 Fiori ...

  7. 使用 SAP CDS view SQL Function 将视图某些字段进行合并

    SAP 用于学习目的设计了很多 demo 开发包,里面包含了很多用于演示目的的 CDS view,类似经典的 Flight 模型,比如视图 /DMO/I_Travel_U. 这个视图和客户相关的信息只 ...

  8. SAP UI5 应用开发教程之八十五 - 如何用 OPA5 编写测试用例来测试用户输入文本的功能试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 作者简介 Jerry Wang,2007 年从电子科技大学计算机专业硕士毕业后加入 SAP 成都研究院工作至今.Jerry 是 SAP 社区导师,S ...

  9. SAP UI5 应用开发教程之八十二 - 采用 OPA5 开发支持页面跳转的 SAP UI5 集成测试用例试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

最新文章

  1. Nginx反向绑定域名方法和详细操作应用实例:Google和Gravatar
  2. 关于Servlet的原理以及常用类
  3. 计算机从加电到系统(Linux)启动完成
  4. jquery 筛选元素 (3)
  5. 拟合方程是什么matlab,matlab离散型数据拟合方程,求系数,哪个大神能说说方法...
  6. dw显示云服务器的数据库,dw如何读取服务器数据库
  7. android 发送显示广播,如何查看Android系统当前发送了什么广播
  8. jira-enterprise-3.6.4-standalone + confluence-2.2.8 + MySQL5.0 安装破解全过程
  9. java原始套接字打开_原始套接字-IP头包含选项
  10. DirectShow源码下载
  11. 如何用linux做共线性分析,「生信」共线性分析——MCScanX
  12. php 加减法,php加减法
  13. 前后端分离框架Vue+Element UI(上集)
  14. 疯狂的Google之各种传说
  15. 淫欲的真相是什么呢?可能很多英雄豪杰都没有想到过
  16. MySQL 数据库 day-03
  17. 程序员去大公司面试,阿里P8面试官都说太详细了,社招面试心得
  18. 【编程语言】Lua完全自学手册
  19. Nginx设置访问Web页面时用户名密码验证
  20. 高端HTML个性家具定制企业网站建设案例

热门文章

  1. linux boot procedure
  2. 获取服务器信息info
  3. 《PHP综合开发环境》(NuSphere PhpED v5.6.5615 Win32)[压缩包]
  4. centos who命令 查看当前登录系统用户信息
  5. python, 用filter实现素数
  6. 新建/克隆虚拟机(配置)
  7. 关闭Mycelipse的拼写检查
  8. 笔记本能连上WIFI网络,但是无法上网怎么办
  9. 科研经费管理新规定——劳务费从15%变为上不封顶
  10. TextBox只读时不能通过后台赋值取值解决办法