创建界面视图

ABAP RESTful 应用程序编程模型 › 开发 › 开发应用程序 › 使用分层数据结构开发应用 › 具有草稿功能的可编辑树视图 › 可编辑树视图:概览中的开发流程 › 创建界面视图

在我们的演示中,我们正在使用这两个界面视图 /DMO/I_Employee_HD 和 /DMO/I_Agency_HD。

界面视图 /DMO/I_Agency_HD

数据定义 /DMO/I_Agency_HD 是表 /dmo/agency_a_hd 的界面视图。

下面显示的关联具有精确一到多个的基数。这意味着在每个代理中,可以有许多员工。

示例代码

association of exact one to many /DMO/I_Employee_HD as _Employee on $projection.Agency = _Employee.Agency

展开以下代码示例以查看数据定义 /DMO/I_Agency_HD 的源代码。

示例代码

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Hierarchy: Draft: Agency'

@Search.searchable: true

define root view entity /DMO/I_Agency_HD
  as select from /dmo/agency_a_hd as Agency

  association of exact one to many /DMO/I_Employee_HD    as _Employee on $projection.Agency = _Employee.Agency

  association of one       to one I_Country              as _Country  on $projection.CountryCode = _Country.Country

{
      @ObjectModel.text.element: ['Name']
  key Agency.agency                as Agency,

      @Search.defaultSearchElement: true
      @Search.fuzzinessThreshold: 0.8
      @Semantics.text: true
      @Semantics.organization.name: true
      Agency.name                  as Name,

      @Semantics.address.street: true
      Agency.street                as Street,

      @Semantics.address.zipCode: true
      Agency.postal_code           as PostalCode,

      @Search.defaultSearchElement: true
      @Semantics.address.city: true
      Agency.city                  as City,

      @Consumption.valueHelpDefinition: [{entity: { name: 'I_CountryVH', element: 'Country' } }]
      @Semantics.address.country: true
      Agency.country_code          as CountryCode,

      @Semantics.telephone.type: [#WORK]
      Agency.phone_number          as PhoneNumber,

      @Semantics.eMail.address: true
      Agency.email_address         as EMailAddress,

      Agency.web_address           as WebAddress,

      @Semantics.user.createdBy: true
      Agency.local_created_by      as LocalCreatedBy,

      @Semantics.systemDateTime.createdAt: true
      Agency.local_created_at      as LocalCreatedAt,

      @Semantics.user.lastChangedBy: true
      Agency.local_last_changed_by as LocalLastChangedBy,

      @Semantics.systemDateTime.localInstanceLastChangedAt: true
      Agency.local_last_changed_at as LocalLastChangedAt,

      @Semantics.systemDateTime.lastChangedAt: true
      Agency.last_changed_at       as LastChangedAt,

      /* Associations */
      _Employee,
      _Country
}

界面视图 /DMO/I_Employee_HD

数据定义 /DMO/I_Employee_HD 是表/dmo/employ_a_hd 的界面视图。从现有数据库表 /dmo/employ_a_hd 中选择数据。

在此视图中,存在多个关联。第一个关联指定员工和代理之间的多对一关系。这表示许多员工可以与一个代理相关联。

示例代码

 association of many to one /DMO/I_Agency_HD   as _Agency  on  $projection.Agency = _Agency.Agency

第二个关联还指定多对一关系,但具有相同的实体视图 (/DMO/I_Employee_HD) 本身,表示员工可以拥有经理,也是员工。这会将层次结构逻辑添加到现有数据,表示员工号也可以用作其他员工的经理编号。由于许多员工与一个经理相关联,因此以下关联的基数定义为多对一。

示例代码

association of many to one /DMO/I_Employee_HD as _Manager on  $projection.Agency  = _Manager.Agency
                                                            and $projection.Manager = _Manager.Employee

_Employee 关联使您能够识别向当前经理报告的所有员工。

示例代码

association of many to many /DMO/I_Employee_HD as _Employee on  $projection.Agency   = _Employee.Agency
                                                              and $projection.Employee = _Employee.Manager

展开以下代码示例以查看数据定义的源代码 /DMO/I_Employee_HD。

示例代码

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Hierarchy: Draft: Employee'

define view entity /DMO/I_Employee_HD
  as select from /dmo/employ_a_hd

  association of many to one /DMO/I_Agency_HD    as _Agency   on  $projection.Agency = _Agency.Agency
  association of many to one /DMO/I_Employee_HD  as _Manager  on  $projection.Agency  = _Manager.Agency
                                                              and $projection.Manager = _Manager.Employee
  association of many to many /DMO/I_Employee_HD as _Employee on  $projection.Agency   = _Employee.Agency
                                                              and $projection.Employee = _Employee.Manager
  association         to one I_Currency          as _Currency on  $projection.SalaryCurrency = _Currency.Currency
{
  key agency                as Agency,
  key employee              as Employee,

      @Semantics.name.givenName: true
      first_name            as FirstName,
      @Semantics.name.familyName: true
      last_name             as LastName,

      @Semantics.amount.currencyCode: 'SalaryCurrency'
      salary                as Salary,
      salary_currency       as SalaryCurrency,

      @EndUserText.label: 'Manager'
      manager               as Manager,

      sibling_order_number  as SiblingOrderNumber,

      local_created_by      as LocalCreatedBy,
      local_created_at      as LocalCreatedAt,
      local_last_changed_by as LocalLastChangedBy,
      local_last_changed_at as LocalLastChangedAt,

      _Agency,
      _Manager,
      _Employee,
      _Currency
}

来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译

← 创建数据库表 · 为目录创建根视图实体 →