当前位置: 首页 > ds >正文

SAP学习笔记 - 开发45 - RAP开发 Managed App New Service Definition,Metadata Extension

上一章讲了在 Data Model View ( CDS View for BO Structure )基础上创建 Projection View ( CDS View for BO Projection )。

SAP学习笔记 - 开发44 - RAP开发 Managed App 建 Projection View,Provider Contract,用 redirected to 设定父子关系-CSDN博客

本章继续学习RAP相关的知识 - New Service Definition,Metadata Extension。

- New Service Definition,Metadata Extension 里面的内容

- 基本上之前讲的,lineItem,selectionField,Search,ObjectModel,Value Help,headerInfo 等等,这些内容都重新复习了一遍。

- 代码的写法上也有更为灵活的方案

目录

1,New Service Definition

1-1,Z04_PV_Travel_M 修改

a),追加字段

b),@Metadata.allowExtensions: true - 允许Metadata放到单独文件

1-2,New Metadata Extension - Z04_PV_Travel_M_MD

1-3,New Service Definition - Z04_SD_Travel_M

1-4,New Service Binding - Z04_UI_Travel_M_V4

1-5,实验一下

2,Metadata Extension - Z04_PV_Travel_M_MD

2-1,加 lineItem,selectionField - 列对象,检索条件对象

2-2,加 @Search.searchable: true - 搜索框

2-3,@ObjectModel.text - 显示Code对应的Name/Text值

2-4,@Consumption.valueHelpDefinition - Value Help

2-5,@UI.hidden: true

2-6,@UI.identification / @UI.facet - 显示详细页面(Object Page)

2-7,@UI.headerInfo - Header


下面是详细内容。

1,New Service Definition

Projection View建好了,下面该做 Service Definition了。

1-1,Z04_PV_Travel_M 修改

a),追加字段

-  _Agency.Name as AgencyName,  =》显示代理店名称
- _Customer.LastName as CustomerName,  =》显示客户名称
- _Status._Text.Text as OverallStatusText :localized,  =》显示总体状态名称,localized:本地化

b),@Metadata.allowExtensions: true - 允许Metadata放到单独文件

因为咱们想要将Metadata单独到一个文件当中,需要设置该annotation 为True

1-2,New Metadata Extension - Z04_PV_Travel_M_MD

输入Name,Description,Extended Entity,点Next

选模板,annotateView,然后点Finish

 

Ctrl + Space,然后选 Insert All,这样就不用挨个输入了哈👍

 

本来想先不加,然后再慢慢挨个加,结果直接报个错,说至少得有一个😓,好吧

>No annotations defined. At least one annotation must be defined for 'Z04_PV_Travel_M'

 

先搞成这样,Ctrl+F3,激活

1-3,New Service Definition - Z04_SD_Travel_M

输入Name,Description,点Next

选模板,只有一个:),点Finish

 

咱们把 Z04_PV_Booking_M,Z04_PV_BookSuppl_M 都给加上,然后激活

 

1-4,New Service Binding - Z04_UI_Travel_M_V4

输入Name,Description,Binding Type,点 Next

点Finish

Ctrl + F3,激活,然后点 Publish

 

1-5,实验一下

就是这样的哈

其实也可以查询,点Settings,然后把想看的字段给调出来,就可以看啦,参照如下文章

SAP学习笔记 - 开发40 - RAP开发 Annotation的作用 @UI.headerInfo /@UI.lineItem/ @UI.selectionField/ @UI.facet等-CSDN博客

 

就像这样,数据是可以检索出来的。

但是这样毕竟不方便嘛,下面咱们就让画面默认显示这些字段

2,Metadata Extension - Z04_PV_Travel_M_MD

2-1,加 lineItem,selectionField - 列对象,检索条件对象

都是以前讲过的,其中UI 有多个annotation的话,写法上可以合并成下面这样:

- @UI:{ lineItem:[{ position: 70 }],
            selectionField: [{ position: 70 }]
      }

刷新页面,默认就显示成这样了

2-2,加 @Search.searchable: true - 搜索框

- @Search.searchable: true

- @Search.defaultSearchElement: true

TODO:好像没好用,之前还是好用的啊,不知道差哪儿,以后再说

SAP学习笔记 - 开发42 - RAP开发 Annotation的作用3: @Search.searchable - 检索功能,@Search.fuzzinessThreshold - 模糊查询-CSDN博客

2-3,@ObjectModel.text - 显示Code对应的Name/Text值

这里面需要注意几点:

- @ObjectModel.text 属于 ABAP Level 的association,所以不能写在 Metadata 文件中

- 下面的写法是OK的,如果也可以简写成:@ObjectModel.text.element: [ 'AgencyName' ]

@ObjectModel.text: {
    element: [ 'AgencyName' ]
}

完整的代码如下:AgencyName,CustomerName,OverallStatusText 都写上

 

Agency ID,Customer ID 都好用

TODO:但是 Overall Status 好像不好用哈

好像不是不好用,而是没有语言 JA 的文本吧

 

只有 E (English)的文本😓,好吧,代码应该没问题

 

把JA 的数据给加上

这样就能显示出来了

2-4,@Consumption.valueHelpDefinition - Value Help

对以下几个字段添加 Value Help:

- AgencyId - Table:/DMO/I_Agency Field:AgencyID

- CustomerId - Table:/DMO/I_Customer Field:CustomerID

- CurrencyCode - Table:I_Currency Field:Currency

- OverallStatus - Table:/DMO/I_Overall_Status_VH Field:OverallStatus

到目前这一步的 Metadata 文件的内容:

@Metadata.layer: #CORE
@Search.searchable: true
annotate view Z04_PV_Travel_M with
{@UI.lineItem: [{ position: 10 }]@Search.defaultSearchElement: trueTravelId;@UI:{ lineItem:[{ position: 20 }],selectionField: [{ position: 20 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{ entity: {name: '/DMO/I_Agency',element: 'AgencyID'},label: 'Agency'}]AgencyId;//      AgencyName;@UI:{ lineItem:[{ position: 30 }],selectionField: [{ position: 30 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Customer',element: 'CustomerID'},label: 'Customer'}]CustomerId;//      CustomerName;@UI.lineItem: [{ position: 40 }]BeginDate;@UI.lineItem: [{ position: 50 }]EndDate;//      BookingFee;@UI.lineItem: [{ position: 60 }]TotalPrice;@Consumption.valueHelpDefinition: [{entity: {name: 'I_Currency',element: 'Currency'},label: 'Currency'}]CurrencyCode;//      Description;@UI:{ lineItem:[{ position: 70 }],selectionField: [{ position: 70 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Overall_Status_VH',element: 'OverallStatus'},label: 'Overall Status'}]OverallStatus;//      OverallStatusText;//      CreatedBy;//      CreatedAt;//      LastChangedBy;//      LastChangedAt;//      /* Associations *///      _Agency;//      _Booking;//      _Currency;//      _Customer;//      _Status;}

刷新看效果:

- Agency ID:

 

- Customer ID:

- Overall Status:

2-5,@UI.hidden: true

虽然在画面端存在,但是不显示,设为 hidden:true

2-6,@UI.identification / @UI.facet - 显示详细页面(Object Page)

- @UI.facet:在 Metadata里面添加,这个是详细页面的块(字段显示在其中)

- @UI.identification:这是详细页面的字段

@Metadata.layer: #CORE
@Search.searchable: true
annotate view Z04_PV_Travel_M with
{@UI.facet: [{id: 'TravelDetail',purpose: #STANDARD,parentId: '',position: 10,label: 'Travel Detail',type: #IDENTIFICATION_REFERENCE}]@UI:{ lineItem:[{ position: 10 }],identification: [{ position: 10 }]}@Search.defaultSearchElement: trueTravelId;@UI:{ lineItem:[{ position: 20 }],selectionField: [{ position: 20 }],identification: [{ position: 20 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{ entity: {name: '/DMO/I_Agency',element: 'AgencyID'},label: 'Agency'}]AgencyId;//      AgencyName;@UI:{ lineItem:[{ position: 30 }],selectionField: [{ position: 30 }],identification: [{ position: 30 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Customer',element: 'CustomerID'},label: 'Customer'}]CustomerId;//      CustomerName;@UI:{ lineItem:[{ position: 40 }],identification: [{ position: 40 }]}BeginDate;@UI:{ lineItem:[{ position: 50 }],identification: [{ position: 50 }]}EndDate;@UI:{identification: [{ position: 55 }]}BookingFee;@UI:{ lineItem:[{ position: 60 }],identification: [{ position: 60 }]}TotalPrice;@Consumption.valueHelpDefinition: [{entity: {name: 'I_Currency',element: 'Currency'},label: 'Currency'}]CurrencyCode;@UI:{identification: [{ position: 65 }]}Description;@UI:{ lineItem:[{ position: 70 }],selectionField: [{ position: 70 }],identification: [{ position: 70 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Overall_Status_VH',element: 'OverallStatus'},label: 'Overall Status'}]OverallStatus;//      OverallStatusText;//      CreatedBy;//      CreatedAt;//      LastChangedBy;@UI.hidden: trueLastChangedAt;//      /* Associations *///      _Agency;//      _Booking;//      _Currency;//      _Customer;//      _Status;}

看一下效果:

List Report 页面,任意点一条

Object Page 显示的没啥问题,title 好像默认显示了 Travel ID了哈

2-7,@UI.headerInfo - Header

到目前为止的代码: 

@Metadata.layer: #CORE
@Search.searchable: true
@UI.headerInfo: {typeName: 'Travel',typeNamePlural: 'Travels',title: {type: #STANDARD,label: 'Travel',value: 'TravelId'}
}
annotate view Z04_PV_Travel_M with
{@UI.facet: [{id: 'TravelDetail',purpose: #STANDARD,parentId: '',position: 10,label: 'Travel Detail',type: #IDENTIFICATION_REFERENCE}]@UI:{ lineItem:[{ position: 10 }],identification: [{ position: 10 }]}@Search.defaultSearchElement: trueTravelId;@UI:{ lineItem:[{ position: 20 }],selectionField: [{ position: 20 }],identification: [{ position: 20 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{ entity: {name: '/DMO/I_Agency',element: 'AgencyID'},label: 'Agency'}]AgencyId;//      AgencyName;@UI:{ lineItem:[{ position: 30 }],selectionField: [{ position: 30 }],identification: [{ position: 30 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Customer',element: 'CustomerID'},label: 'Customer'}]CustomerId;//      CustomerName;@UI:{ lineItem:[{ position: 40 }],identification: [{ position: 40 }]}BeginDate;@UI:{ lineItem:[{ position: 50 }],identification: [{ position: 50 }]}EndDate;@UI:{identification: [{ position: 55 }]}BookingFee;@UI:{ lineItem:[{ position: 60 }],identification: [{ position: 60 }]}TotalPrice;@Consumption.valueHelpDefinition: [{entity: {name: 'I_Currency',element: 'Currency'},label: 'Currency'}]CurrencyCode;@UI:{identification: [{ position: 65 }]}Description;@UI:{ lineItem:[{ position: 70 }],selectionField: [{ position: 70 }],identification: [{ position: 70 }]}@Search.defaultSearchElement: true@Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Overall_Status_VH',element: 'OverallStatus'},label: 'Overall Status'}]OverallStatus;//      OverallStatusText;//      CreatedBy;//      CreatedAt;//      LastChangedBy;@UI.hidden: trueLastChangedAt;//      /* Associations *///      _Agency;//      _Booking;//      _Currency;//      _Customer;//      _Status;}

这样就显示了 Header

 

以上就是本篇的全部内容。

更多SAP顾问业务知识请点击下面目录链接或东京老树根的博客主页

https://blog.csdn.net/shi_ly/category_12216766.html

东京老树根-CSDN博客

http://www.xdnf.cn/news/15616.html

相关文章:

  • C++中list各种基本接口的模拟实现
  • 25、企业能源管理(Energy):锚定双碳目标,从分类管控到智能优化的数字化转型之路
  • npu-smi info命令参数解释
  • C++-linux系统编程 8.进程(三)孤儿进程、僵尸进程与进程回收
  • 数据结构之单链表
  • Java :List,LinkedList,ArrayList
  • sqli-labs靶场通关笔记:第17关 POST请求的密码重置
  • 连接new服务器注意事项
  • kiro, 新款 AI 编辑器, 简单了解一下
  • Java基础(八):封装、继承、多态与关键字this、super详解
  • 笔试——Day8
  • Scrapy扩展深度解析:构建可定制化爬虫生态系统的核心技术
  • 直播数据统计:如何让数据为我们所用?
  • CommunityToolkit.Mvvm IOC 示例
  • C++回顾 Day8
  • 一文深入:AI 智能体系统架构设计
  • 简单工厂设计模式
  • QT 中各种坑
  • 算法学习day16----Python数据结构--模拟队列
  • haproxy负载均衡
  • 【雅思播客016】New Year Resolution 新年决心
  • vue实现el-table-column中自定义label
  • 深入理解C++11 std::iota:从原理到实践
  • Oracle日期时间函数说明及与MySql区别说明
  • 028_分布式部署架构
  • lanch4j将jar转成exe
  • Mac IDEA启动报错:Error occurred during initialization of VM
  • WPF中的ListBox详解
  • 国内第一梯队终端安全产品解析:技术与场景实践
  • 分布式存储之Ceph使用指南--部署篇(未完待续)