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

简介: 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:

image.png



I do not declare any display format on this field. It has DATS data type in the backend.

image.png



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?

image.png



Answer: it is added here. Backend framework will automatically add corresponding annotation according to the data type of exposed field.

image.png



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.

image.png



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:

image.png



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.



image.png

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,

image.png



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.

image.png



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.

image.png

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:image.png

All UI related annotations could be retrieved via the url below:image.png

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.

image.png

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



image.png


image.pngimage.png

相关文章
|
4月前
|
SQL Android开发
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
|
4月前
|
数据库 API
启用SAP Fiori之前的一些注意事项
启用SAP Fiori之前的一些注意事项
|
4月前
|
Web App开发 开发者 存储
介绍一个 webp 格式转 png 格式的软件:XNConvert
介绍一个 webp 格式转 png 格式的软件:XNConvert
介绍一个 webp 格式转 png 格式的软件:XNConvert
|
4月前
|
JavaScript 前端开发
试读版:如何找出 SAP 标准 Fiori 应用某个按钮点击后执行的 JavaScript 源代码
试读版:如何找出 SAP 标准 Fiori 应用某个按钮点击后执行的 JavaScript 源代码
|
4月前
|
数据库 存储 BI
SAP ABAP CDS View 源代码存储的数据库表揭秘和其他相关数据库表介绍试读版
SAP ABAP CDS View 源代码存储的数据库表揭秘和其他相关数据库表介绍试读版
SAP ABAP CDS View 源代码存储的数据库表揭秘和其他相关数据库表介绍试读版
|
4月前
|
前端开发 搜索推荐 开发者
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
|
4月前
|
JavaScript 前端开发 开发者
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
|
4月前
|
Web App开发 数据采集 前端开发
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
|
4月前
|
XML 存储 数据格式
SAP UI5 控件 customData 属性的应用介绍
SAP UI5 控件 customData 属性的应用介绍
|
4月前
|
前端开发 JavaScript API
SAP UI5 sap.ui.require.toUrl 的作用介绍
SAP UI5 sap.ui.require.toUrl 的作用介绍