SAP S/4HANA 嵌入式分析与 CDS View 开发实战

作者:郑德鼎 约 5 分钟阅读 更新日期:2025-07-07 1 年前更新 标签:SAP, S/4HANA, CDS, Embedded Analytics
目录

一、嵌入式分析概述

SAP S/4HANA Embedded Analytics(嵌入式分析)是基于 SAP HANA 内存计算能力构建的实时分析方案。它允许企业在不脱离 S/4HANA 的情况下,直接对业务交易数据进行多维分析、报表展示和 KPI 监控,实现 OLTP 与 OLAP 的融合。

嵌入式分析的核心技术栈包括 ABAP CDS Views、OData 服务、SAP Fiori Elements、Analytical List Page 和 Smart Business KPI Tiles。

二、CDS View 类型与作用

在嵌入式分析中,CDS View 扮演数据模型层的角色。根据用途不同,可分为以下几类:

类型说明典型用途
Basic View基础视图,直接映射底层表封装原始数据,提供统一语义
Composite View组合视图,关联多个 Basic View构建业务对象视图
Consumption View消费视图,暴露给 UI 或服务Fiori 应用、OData 服务
Cube View分析立方体视图,带维度和度量多维分析、KPI 计算
Query View查询视图,最终面向用户Analytical List Page、报表

三、Cube View 开发示例

@AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Sales Cube' @Analytics.dataCategory: #CUBE @VDM.viewType: #COMPOSITE define view entity ZC_SalesCube as select from zsales_item association [0..1] to zproduct as _Product on $projection.product_id = _Product.product_id association [0..1] to zcustomer as _Customer on $projection.customer_id = _Customer.customer_id { @ObjectModel.foreignKey.association: '_Product' key product_id, @ObjectModel.foreignKey.association: '_Customer' key customer_id, @Semantics.calendarYear: true calendar_year, @Semantics.currencyCode: true currency_code, @DefaultAggregation: #SUM @Semantics.amount.currencyCode: 'currency_code' net_amount, @DefaultAggregation: #SUM @Semantics.quantity.unitOfMeasure: 'unit_of_measure' quantity, unit_of_measure, _Product, _Customer }

四、Query View 与注释

@EndUserText.label: 'Sales Query' @Analytics.query: true @VDM.viewType: #CONSUMPTION define view entity ZC_SalesQuery as select from ZC_SalesCube { @AnalyticsDetails.query.axis: #ROWS @Consumption.filter: { selectionType: #INTERVAL, multipleSelections: true } key calendar_year, @AnalyticsDetails.query.axis: #ROWS product_id, @AnalyticsDetails.query.axis: #COLUMNS @AnalyticsDetails.query.totals: #SHOW @DefaultAggregation: #SUM net_amount, currency_code }

五、暴露 OData 服务

将 CDS Query View 通过 Service Definition 暴露为 OData V2/V4 服务后,即可被 Fiori 应用消费:

define service ZUI_SALES_ANALYTICS { expose ZC_SalesQuery as SalesQuery; expose ZC_SalesCube as SalesCube; }

六、Analytical List Page (ALP)

Analytical List Page 是 Fiori Elements 提供的分析型页面模板,支持:

ALP 通常基于一个带分析注释的 CDS Query View 自动生成,开发工作量远小于传统 SAPUI5 freestyle 应用。

七、Smart Business KPI Tiles

Smart Business KPI Tiles 允许将 CDS View 暴露的关键指标以磁贴形式展示在 Fiori Launchpad 上。其开发流程包括:

  1. 创建带有聚合和过滤条件的 CDS Query View。
  2. 使用 KPI Design Application(Fiori app)定义 KPI、阈值和计算逻辑。
  3. 创建 Evaluation,指定时间维度、过滤器和目标值。
  4. 创建 Tile 和 Target Mapping,将其分配到 Fiori Catalog 和 Group。
  5. 用户从 Launchpad 查看实时 KPI 并实现下钻分析。
性能建议:对于高频刷新的 KPI Tiles,应避免在 CDS View 中进行复杂计算。可通过 HANA Calculation Views、CDS Table Functions 或预聚合表(如 SAP 提供的预计算框架)提升响应速度。

八、性能优化要点

优化方向具体措施
减少数据传输仅暴露必要字段,使用参数化视图
利用 HANA 计算下推避免在 ABAP 层进行大量聚合
合理使用索引为高频过滤字段创建 HANA 索引
权限控制使用 DCL 进行行级权限控制,避免全表扫描
缓存策略对变化不频繁的 KPI 使用缓存或预计算

九、嵌入式分析 vs 外部 BI

嵌入式分析适合 operational reporting 和实时 KPI 场景,而对于复杂的企业级数据仓库、跨系统整合和高级预测分析,仍建议结合 SAP Analytics Cloud (SAC)、SAP Datasphere 或 SAP BW/4HANA 使用。

注意事项:嵌入式分析直接查询生产交易数据,设计不当可能对系统性能产生显著影响。务必在 QAS 环境进行真实数据量和并发测试。

十、总结

SAP S/4HANA 嵌入式分析通过 CDS Views、OData 和 Fiori 技术栈,为企业提供了一种轻量、实时、原生的分析能力。掌握 Cube View、Query View、ALP 和 KPI Tiles 的开发方法,能够帮助企业在 S/4HANA 平台上快速构建可视化分析应用,支撑业务决策。

ABAP Cheat Sheet 补充内容

以下内容整理自 SAP 官方 ABAP 速查表(主题:CDS View Entities),作为本文的扩展补充资料。

CDS View Entities

Core data services (CDS) are an infrastructure for defining and consuming semantically rich data models on the standard database of an AS ABAP.

[!NOTE] - The executable example focuses on CDS view entities and covers a selection of features. - The sample CDS view entities are designed to demonstrate a selection of features with a limited number of artifacts. They are not intended to be role models for proper CDS view design. They focus on syntax options only. They are not intended to solve concrete programming tasks. You should always work out your own solution for each individual case. For more detailed information, refer to the links in the More Information section. - The ABAP Dictionary cheat sheet highlights that several CDS entities - apart from CDS view entities - represent structured types that are usable in ABAP.

A Glimpse on the CDS Syntax

The following links take you to the source code of the cheat sheet artifacts to get a glimpse on the syntax used. To explore the syntax in action, import the ABAP cheat sheet repository into your system.

More Information

Executable Example

zcl_demo_abap_cds_ve

[!NOTE] - The executable example covers the following topics: - Operands, expressions, built-in functions, and input parameters in CDS view entities - Selecting data from CDS view entities using ABAP SQL SELECT statements - Joins - Note: A sample CDS view entity contains multiple joins. You can comment in/out code sections to see the effect. See the notes in the view. - Excursion: Joins in ABAP SQL - Associations - Defining views with associations - Exposing associations - Using exposed associations in ABAP statements - The example CDS view entities (zdemo_abap_cds_ve...) and the class contains comments in the code for more information. - The steps to import and run the code are outlined here. - Disclaimer
来源说明:本节内容来源:SAP-samples/abap-cheat-sheets (GitHub),原作者 SAP。原 Markdown 文件:15_CDS_View_Entities.md。版权归原作者所有。