CAP | FE v4 | 분석 테이블 합계
SAP CAP(Node.js)와 HANA로 Fiori Elements v4 분석 테이블에 합계와 그룹별 소계를 켜는 방법을 단계별로.
7분 분량sap · cap · fiori-elements · ui5 · odata
이 글은 SAP CAP(Node.js)와 HANA를 사용해 Fiori Elements v4 분석 테이블(Analytical Table)에 합계를 켜는 방법을 단계별로 설명합니다. 여러분의 프로젝트에서 빠르게 재현할 수 있도록 하는 것이 목표입니다.
참고 저장소 (전체 코드): https://github.com/GonzaloMB/Totals_CAP_v4
요구사항
- Node.js 기반 CAP + HANA
AnalyticalTable을 쓰는 FE v4 앱 (List Report)- UI5 1.112.1 이상
- 환경: SAP BAS (권장) 또는
@sap/cds가 설치된 로컬
데이터 모델 (db/)
엔티티를 정의하고 합계를 낼 숫자 필드를 표시합니다 (여기서는 stock).
namespace my.bookshop;
entity Books {
key ID : Integer;
title : String @Common.Label: 'Title';
bookshop : String @Common.Label: 'BookShop';
stock : Integer @Common.Label: 'Stock';
}서비스 (srv/)
서비스에서 엔티티를 프로젝션해 OData로 노출합니다.
using my.bookshop as my from '../db/data-model';
service CatalogService {
entity Books as projection on my.Books;
}UI: manifest.json (APP/)
List Report가 AnalyticalTable을 쓰도록 설정하고 UI5 버전을 정확히 지정합니다.
테이블 유형 변경:
"targets": {
"BooksList": {
"type": "Component",
"id": "BooksList",
"name": "sap.fe.templates.ListReport",
"options": {
"settings": {
"initialLoad": "Enabled",
"entitySet": "Books",
"controlConfiguration": {
"@com.sap.vocabularies.UI.v1.LineItem": {
"tableSettings": {
"type": "AnalyticalTable"
}
}
}
}
}
}
}UI5 버전 고정 (예: 1.112.1):
"sap.platform.cf": {
"ui5VersionNumber": "1.112.1"
},
"sap.ui5": {
"flexEnabled": true,
"dependencies": {
"minUI5Version": "1.112.1",
"libs": {
"sap.m": {},
"sap.ui.core": {},
"sap.ushell": {},
"sap.fe.templates": {}
}
}
}어노테이션 (APP/annotations.cds)
그룹화, 기본 합계, 집계 방식이 있는 측정값을 정의합니다. 이렇게 하면 테이블 하단의 합계와 그룹별 합계가 켜집니다.
using CatalogService as service from '../../srv/cat-service';
annotate service.Books with @(
Aggregation.ApplySupported : { GroupableProperties: [
title,
bookshop
]},
Aggregation.CustomAggregate #stock: 'Edm.Int32',
UI.PresentationVariant : {
Total : [stock],
Visualizations: ['@UI.LineItem']
},
UI.SelectionFields : [
title,
bookshop,
stock
],
UI.HeaderInfo : {
$Type : 'UI.HeaderInfoType',
TypeName : 'Book Stock Totals',
TypeNamePlural: 'Book Stock Totals',
Title : { Value: 'Book Stock Totals' }
},
UI.LineItem : [
{ $Type: 'UI.DataField', Value: title },
{ $Type: 'UI.DataField', Value: bookshop },
{ $Type: 'UI.DataField', Value: stock }
]
);
annotate service.Books with @(
UI.FieldGroup #GeneratedGroup1: {
$Type: 'UI.FieldGroupType',
Data : [
{ $Type: 'UI.DataField', Value: title },
{ $Type: 'UI.DataField', Value: bookshop },
{ $Type: 'UI.DataField', Value: stock }
]
},
UI.Facets: [{
$Type : 'UI.ReferenceFacet',
ID : 'GeneratedFacet1',
Label : 'General Information',
Target: '@UI.FieldGroup#GeneratedGroup1'
}]
) {
stock @Analytics.Measure @Aggregation.default: #SUM;
ID @UI.Hidden: true;
};핵심 포인트:
UI.PresentationVariant.Total:stock의 합계 행을 테이블 하단에 표시합니다.Aggregation.ApplySupported.GroupableProperties: 그룹화할 수 있는 필드.Aggregation.CustomAggregate:stock의 집계 유형 (정수).@Analytics.Measure+@Aggregation.default: #SUM:stock을 합산 가능한 측정값으로 표시합니다.
CAP Node.js: $apply용 OData 파서
CAP(Node.js)에서는 일부 $apply 조합(예: concat(...))이 기본 파서에서 실패할 수 있습니다. 그룹화가 있는 FE v4 AnalyticalTable 쿼리를 지원하려면 package.json에서 새(실험적) 파서를 켜세요.
{
"cds": {
"requires": {
"db": "hana"
},
"features": {
"odata_new_parser": true
}
}
}이 옵션이 없으면 아래와 같은 요청이 CAP Java에서는 동작해도 Node.js에서는 실패할 수 있습니다.
GET /BooksAggregate?$apply=concat(groupby((ID,category,title))/aggregate($count%20as%20UI5__leaves),groupby((category))/concat(aggregate($count%20as%20UI5__count),%20top(72)))실행하고 확인하기
- 프로젝트 실행:
cds watch. - FE 앱(
BooksList Report)을 엽니다. - 확인:
- 테이블 하단에
stock합계가 보이는지. title/bookshop으로 그룹화하면 그룹 합계가 보이는지.$apply오류가 없는지 (있다면 새 파서와 어노테이션 대상을 다시 확인하세요).
- 테이블 하단에
자주 겪는 문제
- 합계 행이 보이지 않음:
UI.PresentationVariant.Total과stock이#SUM을 가진@Analytics.Measure인지 확인하세요. - 그룹화해도 합산되지 않음: 필드를
GroupableProperties에 추가하고CustomAggregate를 확인하세요. concat(...)에서$apply실패:package.json에"odata_new_parser": true를 켜세요.- 어노테이션 대상이 틀림:
annotate는 네임스페이스 엔티티가 아니라service.Books를 가리켜야 합니다.
링크
- 참고 코드: https://github.com/GonzaloMB/Totals_CAP_v4
- CAP 문서 (Get Started): https://cap.cloud.sap/docs/get-started/