CAP | FE v4 | 분석 테이블 합계

SAP CAP(Node.js)와 HANA로 Fiori Elements v4 분석 테이블에 합계와 그룹별 소계를 켜는 방법을 단계별로.

이 글은 SAP CAP(Node.js)와 HANA를 사용해 Fiori Elements v4 분석 테이블(Analytical Table)에 합계를 켜는 방법을 단계별로 설명합니다. 여러분의 프로젝트에서 빠르게 재현할 수 있도록 하는 것이 목표입니다.

참고 저장소 (전체 코드): https://github.com/GonzaloMB/Totals_CAP_v4

합계는 어디에서 오는가ABC123db/ Bookstitle · stock01srv/ projectionservice.Books02annotations.cdsMeasure · #SUM03HANAgroupby · aggregateCAP Node.jsodata_new_parser05AnalyticalTableFE v4 · UI5 1.112+06footer total+ group sumsUI.Total$apply
그림 1합계는 어디에서 오는가

요구사항

  • Node.js 기반 CAP + HANA
  • AnalyticalTable을 쓰는 FE v4 앱 (List Report)
  • UI5 1.112.1 이상
  • 환경: SAP BAS (권장) 또는 @sap/cds가 설치된 로컬

데이터 모델 (db/)

엔티티를 정의하고 합계를 낼 숫자 필드를 표시합니다 (여기서는 stock).

spec · abap
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로 노출합니다.

spec · abap
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 버전을 정확히 지정합니다.

테이블 유형 변경:

spec · json
"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):

spec · json
"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)

그룹화, 기본 합계, 집계 방식이 있는 측정값을 정의합니다. 이렇게 하면 테이블 하단의 합계와 그룹별 합계가 켜집니다.

spec · abap
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에서 새(실험적) 파서를 켜세요.

spec · json
{
  "cds": {
    "requires": {
      "db": "hana"
    },
    "features": {
      "odata_new_parser": true
    }
  }
}

이 옵션이 없으면 아래와 같은 요청이 CAP Java에서는 동작해도 Node.js에서는 실패할 수 있습니다.

spec · http
GET /BooksAggregate?$apply=concat(groupby((ID,category,title))/aggregate($count%20as%20UI5__leaves),groupby((category))/concat(aggregate($count%20as%20UI5__count),%20top(72)))

실행하고 확인하기

  1. 프로젝트 실행: cds watch.
  2. FE 앱(Books List Report)을 엽니다.
  3. 확인:
    • 테이블 하단에 stock 합계가 보이는지.
    • title/bookshop으로 그룹화하면 그룹 합계가 보이는지.
    • $apply 오류가 없는지 (있다면 새 파서와 어노테이션 대상을 다시 확인하세요).

자주 겪는 문제

  • 합계 행이 보이지 않음: UI.PresentationVariant.Total과 stock이 #SUM을 가진 @Analytics.Measure인지 확인하세요.
  • 그룹화해도 합산되지 않음: 필드를 GroupableProperties에 추가하고 CustomAggregate를 확인하세요.
  • concat(...)에서 $apply 실패: package.json에 "odata_new_parser": true를 켜세요.
  • 어노테이션 대상이 틀림: annotate는 네임스페이스 엔티티가 아니라 service.Books를 가리켜야 합니다.

링크