定义扩展节点的数据模型
ABAP RESTful 应用程序编程模型 › 扩展 › RAP 扩展 › 开发 RAP 扩展 › 开发节点扩展 › 定义扩展节点的数据模型
在本章中,定义扩展节点的数据库表和 CDS 数据模型。
创建数据库表
使用保留审核数据所需的字段创建活动数据库表:
@EndUserText.label : 'Agency Review: Review. Active Instances'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table /dmo/zz_agn_reva {
key client : abap.clnt not null;
key agency_id : /dmo/agency_id not null;
key review_id : /dmo/zz_review_id not null;
rating : /dmo/zz_rating;
free_text_comment : /dmo/zz_free_text_comment;
helpful_count : /dmo/zz_helpful_count;
helpful_total : /dmo/zz_helpful_total;
@AbapCatalog.anonymizedWhenDelivered : true
reviewer : abp_creation_user;
local_created_at : abp_creation_tstmpl;
local_last_changed_at : abp_locinst_lastchange_tstmpl;
}
定义节点的 BDEF 扩展后,可以生成草稿数据库表。
定义 CDS 数据模型
创建名为
/DMO/ZZ_I_Agency_Review的 CDS 视图,该视图从数据库表/dmo/zz_agn_reva中选择。@AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Agency Review' define view entity /DMO/ZZ_I_Agency_Review as select from /dmo/zz_agn_reva as Review { key Review.agency_id as AgencyId, key Review.review_id as ReviewId, Review.rating as Rating, Review.free_text_comment as FreeTextComment, Review.helpful_count as HelpfulCount, Review.helpful_total as HelpfulTotal, @Semantics.user.createdBy: true Review.reviewer as Reviewer, @Semantics.systemDateTime.createdAt: true Review.local_created_at as LocalCreatedAt, @Semantics.systemDateTime.localInstanceLastChangedAt: true Review.local_last_changed_at as LocalLastChangedAt }
创建名为
/DMO/ZZ_R_Agency_ReviewTP的 CDS 视图,该视图从创建的 CDS 视图/DMO/ZZ_I_Agency_Review中选择。将关联添加到父实体/DMO/R_AgencyTP并在字段列表中公开此关联。您将在 将扩展节点添加到数据模型 章节中将相应构成添加到Ageny节点。@AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Agency Review' define view entity /DMO/ZZ_R_Agency_ReviewTP as select from /DMO/ZZ_I_Agency_Review association to parent /DMO/R_AgencyTP as _Agency on $projection.AgencyId = _Agency.AgencyID { key AgencyId, key ReviewId, Rating, FreeTextComment, HelpfulCount, HelpfulTotal, Reviewer, LocalCreatedAt, LocalLastChangedAt, _Agency }
创建名为
/DMO/ZZ_I_Agency_ReviewTP的接口投影 CDS 视图,该视图预计为 CDS 视图/DMO/ZZ_R_Agency_ReviewTP。将关联_Agency重定向到/DMO/Agency节点的接口层。@Metadata.ignorePropagatedAnnotations: true @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Agency Review' define view entity /DMO/ZZ_I_Agency_ReviewTP as projection on /DMO/ZZ_R_Agency_ReviewTP { key AgencyId, key ReviewId, Rating, FreeTextComment, HelpfulCount, HelpfulTotal, @Semantics.user.createdBy: true Reviewer, @Semantics.systemDateTime.createdAt: true LocalCreatedAt, @Semantics.systemDateTime.localInstanceLastChangedAt: true LocalLastChangedAt, /* Associations */ _Agency : redirected to parent /DMO/I_AgencyTP }
创建名为
/DMO/ZZ_C_Agency_ReviewTP的 CDS 映射视图,该视图预计为 CDS 视图/DMO/ZZ_R_Agency_ReviewTP。将关联_Agency重定向到/DMO/Agency节点的投影层。@EndUserText.label: 'Agency Review' @AccessControl.authorizationCheck: #NOT_REQUIRED @Metadata.allowExtensions: true @ObjectModel.semanticKey: ['Reviewer'] define view entity /DMO/ZZ_C_Agency_ReviewTP as projection on /DMO/ZZ_R_Agency_ReviewTP { key AgencyId, key ReviewId, Rating, FreeTextComment, HelpfulCount, HelpfulTotal, Reviewer, LocalCreatedAt, LocalLastChangedAt, /* Associations */ _Agency : redirected to parent /DMO/C_AgencyTP }
为 UI 上显示的 CDS 映射视图
/DMO/ZZ_C_Agency_ReviewTP创建元数据扩展。展开以下代码示例以查看元数据扩展的源代码
/DMO/ZZ_C_Agency_ReviewTP。示例代码
@Metadata.layer: #CUSTOMER @UI: { headerInfo: { typeName: 'Review', typeNamePlural: 'Reviews', title: { type: #STANDARD, value: 'ReviewId' } }, presentationVariant: [{ sortOrder: [{ by: 'LocalCreatedAt', direction: #DESC }], visualizations: [{type: #AS_LINEITEM}] }] } annotate view /DMO/ZZ_C_Agency_ReviewTP with { @UI.facet: [ { id: 'Review', purpose: #STANDARD, type: #IDENTIFICATION_REFERENCE, label: 'Review', position: 10 }, { id: 'HelpfulID', purpose: #HEADER, type: #DATAPOINT_REFERENCE, label: 'Helpful', position: 10, targetQualifier: 'HelpfulCount' } ] @UI.hidden: true AgencyId; @UI.hidden: true ReviewId; @UI:{ dataPoint: { title: 'Rating' ,visualization: #RATING ,targetValue: 5 }, lineItem: [ { position: 10, label: 'Rating', importance: #HIGH ,valueQualifier: 'Rating' ,type: #AS_DATAPOINT } ], identification: [ { position: 10, label: 'Rating', importance: #HIGH ,type: #AS_DATAPOINT } ] } Rating; @UI.lineItem: [{ position: 20 }] @UI.identification: [{ position: 20 }] @UI.multiLineText: true FreeTextComment; @UI:{ dataPoint: { title: 'Helpful', targetValueElement: 'HelpfulTotal' ,visualization: #PROGRESS }, lineItem: [ { position: 50, label: 'Helpful', importance: #HIGH ,type: #AS_DATAPOINT ,valueQualifier: 'Progress' } ] } HelpfulCount; @UI.hidden: true HelpfulTotal; @UI.lineItem: [ { type: #FOR_ACTION, dataAction: '/DMO/reviewWasHelpful', label: 'Helpful' }, { type: #FOR_ACTION, dataAction: '/DMO/reviewWasNotHelpful', label: 'Not Helpful' }, { position: 3 } ] @UI.identification: [ { type: #FOR_ACTION, dataAction: '/DMO/reviewWasHelpful', label: 'Helpful' }, { type: #FOR_ACTION, dataAction: '/DMO/reviewWasNotHelpful', label: 'Not Helpful' }, { position: 3 } ] Reviewer; @UI.hidden: true LocalCreatedAt; @UI.hidden: true LocalLastChangedAt; }
结果
您已定义扩展节点的数据模型。现在,您可以将其添加到原始业务对象的数据模型,请参阅将扩展节点添加到数据模型。
来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译
← 开发节点扩展 · 将扩展节点添加到数据模型 →