製品の標準原価と、その原価要素別内訳 (cost component split)。 個票のタブにドーナツグラフが載っています。ここでの学びどころは描画ではなく、 「グラフを載せたければデータモデルの方を直す」という順序です。 金額の項目を 3 つ並べただけではグラフは出ません。
番号を押すと対応する反対側が光ります。
このファイルは 2 つの annotate ブロックでできています。前半が原価見積 (親)、
後半が原価要素 (子) で、グラフは子の側に定義されています。理由は下で説明します。
1
2
3
6
4
5
@UI.Facets@UI.FieldGroup #CostTarget: 'components/@UI.Chart#CostSplit'Dimensions: [ componentName ]Target: 'components/@UI.LineItem'DynamicMeasures → @Analytics.AggregatedPropertysum で集計した値。ALP のグラフとまったく同じ仕組み@Aggregation.ApplySupported (子エンティティ側)$apply を投げる。個票の中のグラフでも要る
using ShowcaseService as srv from './showcase-service';
/**
* 原価: List Report + Object Page。Object Page 側に原価内訳のドーナツチャートを載せて
* 「一覧 → 個票 → 内訳の可視化」という CO でよくある導線を作る。
*/
annotate srv.CostEstimates with @(
UI: {
HeaderInfo: {
TypeName : '原価見積',
TypeNamePlural : '原価見積',
Title : { Value: material_ID },
Description : { Value: ID }
},
SelectionFields: [ plant, costingStatus, material_ID, costingDate ],
// CK13N の原価見積ヘッダに寄せた列構成。金額 4 本 (材料費/労務費/製造間接費/
// 合計原価) を全部並べると通貨サブ列のぶん横幅を食い過ぎるので、一覧は合計原価だけ、
// 内訳は Object Page の原価要素 facet に置く分担にしている。
LineItem: [
{ Value: ID, Label: '原価見積番号' },
{ Value: material_ID, Label: '品目' },
{ Value: material.description, Label: '品目テキスト' },
{ Value: plant, Label: 'プラント' },
{ Value: costingVariant, Label: '原価計算バリアント' },
{ Value: costingDate, Label: '原価計算日' },
{ Value: validFrom, Label: '有効開始日' },
{ Value: validTo, Label: '有効終了日' },
{ Value: lotSize, Label: 'ロットサイズ' },
{ Value: totalCost, Label: '合計原価' },
{ Value: costingStatusText, Label: 'ステータス', Criticality: costingCriticality }
],
Facets: [
{ $Type: 'UI.ReferenceFacet', ID: 'CostFacet', Label: '原価要素', Target: '@UI.FieldGroup#Cost' },
{ $Type: 'UI.ReferenceFacet', ID: 'ChartFacet', Label: '内訳グラフ', Target: 'components/@UI.Chart#CostSplit' },
{ $Type: 'UI.ReferenceFacet', ID: 'SplitFacet', Label: '内訳明細', Target: 'components/@UI.LineItem' },
{ $Type: 'UI.ReferenceFacet', ID: 'AdminFacet', Label: '原価計算情報', Target: '@UI.FieldGroup#Admin' }
],
FieldGroup #Cost: { Data: [
{ Value: materialCost },
{ Value: laborCost },
{ Value: overheadCost },
{ Value: totalCost }
]},
FieldGroup #Admin: { Data: [
{ Value: ID },
{ Value: material_ID },
{ Value: material.description, Label: '品目テキスト' },
{ Value: plant },
{ Value: costingVariant },
{ Value: costingDate },
{ Value: validFrom },
{ Value: validTo },
{ Value: lotSize },
{ Value: costingStatusText, Criticality: costingCriticality }
]}
}
);
/**
* 原価要素別内訳。Object Page のチャート facet はこちらを見る。
* 「3 つの金額項目を Measures に並べたドーナツ」は sap.fe のチャートが
* 扱えない形 (dimension が無い) なので、SAP の cost component split と
* 同じく「要素 = dimension / 金額 = measure」の明細にしてある。
* チャート building block は $apply を投げるので ApplySupported が要る。
*/
annotate srv.CostComponents with @(
Aggregation.ApplySupported: {
Transformations : ['aggregate', 'groupby', 'filter', 'orderby', 'top', 'skip', 'concat'],
GroupableProperties : [ componentNo, componentName, costEstimate_ID, currency_code ],
AggregatableProperties : [ { Property: amount } ]
},
Analytics.AggregatedProperty #totalAmount: {
Name : 'totalAmount',
AggregationMethod : 'sum',
AggregatableProperty : amount,
![@Common.Label] : '金額'
},
UI: {
Chart #CostSplit: {
$Type : 'UI.ChartDefinitionType',
ChartType : #Donut,
Title : '原価要素別の内訳',
Dimensions : [ componentName ],
DynamicMeasures : [ ![@Analytics.AggregatedProperty#totalAmount] ],
MeasureAttributes: [{
$Type : 'UI.ChartMeasureAttributeType',
DynamicMeasure : ![@Analytics.AggregatedProperty#totalAmount],
Role : #Axis1
}],
DimensionAttributes: [{
$Type : 'UI.ChartDimensionAttributeType',
Dimension : componentName,
Role : #Category
}]
},
LineItem: [
{ Value: componentNo, Label: '原価要素' },
{ Value: componentName, Label: '名称' },
{ Value: amount, Label: '金額' }
]
}
);
annotate srv.CostComponents with {
componentNo @title: '原価要素';
componentName @title: '名称';
amount @title: '金額' @Measures.ISOCurrency: currency_code;
}
annotate srv.CostEstimates with {
ID @title: '原価見積番号';
material @title: '品目';
plant @title: 'プラント';
costingVariant @title: '原価計算バリアント';
costingDate @title: '原価計算日';
validFrom @title: '有効開始日';
validTo @title: '有効終了日';
lotSize @title: 'ロットサイズ';
materialCost @title: '材料費' @Measures.ISOCurrency: currency_code;
laborCost @title: '労務費' @Measures.ISOCurrency: currency_code;
overheadCost @title: '製造間接費' @Measures.ISOCurrency: currency_code;
totalCost @title: '合計原価' @Measures.ISOCurrency: currency_code;
costingStatus @title: '原価計算ステータス (コード)';
costingStatusText @title: 'ステータス';
}
{
"_version": "1.60.0",
"sap.app": {
"id": "showcase.cost",
"type": "application",
"applicationVersion": { "version": "1.0.0" },
"title": "原価見積",
"description": "製品原価見積 — List Report + Object Page (原価内訳グラフつき)",
"dataSources": {
"mainService": {
"uri": "/odata/v4/showcase/",
"type": "OData",
"settings": { "odataVersion": "4.0" }
}
}
},
"sap.ui": {
"technology": "UI5",
"deviceTypes": { "desktop": true, "tablet": true, "phone": true }
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.120.0",
"libs": { "sap.m": {}, "sap.ui.core": {}, "sap.fe.templates": {}, "sap.ui.comp": {} }
},
"models": {
"": {
"dataSource": "mainService",
"preload": true,
"settings": { "operationMode": "Server", "autoExpandSelect": true, "earlyRequests": true }
}
},
"routing": {
"routes": [
{ "pattern": ":?query:", "name": "CostEstimatesList", "target": "CostEstimatesList" },
{ "pattern": "CostEstimates({key}):?query:", "name": "CostEstimatesObjectPage", "target": "CostEstimatesObjectPage" }
],
"targets": {
"CostEstimatesList": {
"type": "Component",
"id": "CostEstimatesList",
"name": "sap.fe.templates.ListReport",
"options": {
"settings": {
"contextPath": "/CostEstimates",
"variantManagement": "Page",
"initialLoad": "Enabled",
"navigation": {
"CostEstimates": { "detail": { "route": "CostEstimatesObjectPage" } }
}
}
}
},
"CostEstimatesObjectPage": {
"type": "Component",
"id": "CostEstimatesObjectPage",
"name": "sap.fe.templates.ObjectPage",
"options": { "settings": { "contextPath": "/CostEstimates" } }
}
}
}
}
}
contextPath と
libs の sap.ui.comp (グラフのため) だけです。
タブが 4 つあることも、そのうち 1 つがグラフであることも書いてありません。
最初にやりたくなるのはこれです —— 親エンティティに materialCost /
laborCost / overheadCost が並んでいるのだから、この 3 つを
Measures に入れれば円グラフになるはずだ、と。なりません。
| やりたいこと | なぜ通らないか |
|---|---|
Measures: [materialCost, laborCost, overheadCost] で 3 分割の円 |
ディメンション (分割の軸) が無い。グラフは「軸の値ごとに measure を集計する」道具なので、 「3 つの別々の列」は軸にならない |
生の金額項目を Measures に置く |
集計方法が決まっていないので [50017] Invalid data binding になる |
通し方は 1 つで、「原価要素」という軸を持った子エンティティにすることです。 そして、これはグラフのための都合ではありません。SAP のデータモデルが最初からその形です —— 原価見積ヘッダ (KEKO) に対して、原価要素別内訳は明細 (CKIS / KEPH) として持ちます。 要素は 3 つとは限らず、原価要素分割は 10 も 20 も持ちうるからです。
entity CostEstimates {
key ID : String(12);
material : Association to Materials;
plant : String(4);
costingVariant: String(4); // PPC1 = 標準原価計算 (KEKO-KALKA/TCK03 相当)
costingDate : Date;
validFrom : Date;
validTo : Date;
lotSize : Decimal(13,3);
materialCost : Decimal(15,2); // ← 合計としては持つ (一覧で速いので)
laborCost : Decimal(15,2);
overheadCost : Decimal(15,2);
totalCost : Decimal(15,2);
costingStatus : String(2); // KA 原価計算済 / VO 暫定 / FR リリース済
components : Composition of many CostComponents on components.costEstimate = $self;
}
/** 原価要素別内訳の 1 行。原価見積の明細として持つ。 */
entity CostComponents {
key ID : String(16);
costEstimate : Association to CostEstimates;
componentNo : String(3); // 010 材料費 / 020 労務費 / 030 製造間接費
componentName : String(40); // ← これがグラフの軸になる
amount : Decimal(15,2); // ← これが measure
currency : Currency;
}
親に合計 4 本、子に内訳という二重持ちは冗長に見えますが、SAP でも同じです。
一覧で 20 件表示するために毎回明細を集計するのは高いので、
ヘッダに集計済みの値を持ち、内訳は明細に持つのが定石です
(このサイトでは一覧に totalCost だけを出し、内訳は個票に置く分担にしています)。
UI: {
Chart #CostSplit: {
$Type : 'UI.ChartDefinitionType',
ChartType : #Donut,
Title : '原価要素別の内訳',
Dimensions : [ componentName ], // 軸
DynamicMeasures : [ ![@Analytics.AggregatedProperty#totalAmount] ], // 面積
MeasureAttributes: [{ … Role: #Axis1 }],
DimensionAttributes: [{ … Role: #Category }]
},
親からは Target: 'components/@UI.Chart#CostSplit' と関連名をパスにして参照します。
明細テーブルを items/@UI.LineItem で貼るのとまったく同じ書き方で、
貼る先が LineItem か Chart かが違うだけです。
facet は「子の見せ方を、親のどこに置くか」を決めるだけの層だと分かると、
Object Page の組み立てが一気に単純になります。
ApplySupported が要る$apply=groupby((componentName),aggregate(amount with sum …)) を投げます。
投げ先は子エンティティ (CostComponents) なので、
集計の許可も子の側に書かないと動きません。
ALP のときに親へ書いたのと同じ宣言を、ここでは子に書いています。
一覧に出しているのは 合計原価だけです。材料費・労務費・製造間接費は個票に置いています。 理由は幅で、金額項目は 1 本につき通貨のサブ列が付くためです (「10,750.00」と「JPY」で 2 列ぶん)。4 本並べると横幅を食い切り、 肝心の品目テキストや有効期間が折り返し (popin) に落ちます。
代わりに、CK13N の原価見積ヘッダで実際に見る項目——原価計算バリアント・原価計算日・ 有効期間・ロットサイズ——を入れています。原価は「いつ時点の、どの計算方式の値か」が 分からないと意味を持たないので、実務ではこちらのほうが優先度が高いためです。
| アノテーション | 何を決めるか | 画面のどこ | ABAP CDS なら |
|---|---|---|---|
@UI.Facets | タブ 4 つの構成と順番 | タブ (1) | @UI.facet |
@UI.FieldGroup | 金額 4 つ / 原価計算情報 | (2) | @UI.fieldGroup |
Target: 'components/@UI.Chart#…' | 子のグラフを親の facet に貼る | 内訳グラフ (3) | 同じ (関連名/@UI.chart) |
@UI.Chart (#Donut) | グラフ種別・軸・題名 | ドーナツ (4)(6) | @UI.chart |
@Analytics.AggregatedProperty | 金額の合計という項目 | 面積 (6) | @DefaultAggregation: #SUM |
@Aggregation.ApplySupported | 子エンティティの集計許可 | (見えない / 必須) | Analytics 系の宣言 |
Target: 'components/@UI.LineItem' | 同じ子を表として貼る | 内訳明細 (5) | 同じ |
Criticality | 原価計算ステータスの色 | 一覧のステータス列 | @UI.lineItem.criticality |
@Measures.ISOCurrency | 金額 5 項目すべてに通貨 | 「JPY」列 | 同じ |
| やること | 起きること | そこから分かること |
|---|---|---|
ChartType を #Column や #Pie に変える |
そのまま棒 / 円になる | グラフ種別は 1 語。データ側は変えなくてよい |
Dimensions を componentNo に変える |
凡例が 010 / 020 / 030 になる | 軸は「値の集合」であれば何でもよい |
Facets の並びを入れ替える |
タブの順番が変わる | 画面構成は配列順そのもの |
子側の ApplySupported を消す |
グラフのタブが空になる | 集計許可は「グラフを描く側のエンティティ」に要る |
/odata/v4/showcase/CostComponents?$apply=groupby((componentName),aggregate(amount with sum as total)) |
グラフと同じ 3 行が JSON で返る | グラフはこの結果を描いているだけ |