Build CDS-based analytical queries and KPI tiles for S/4HANA
✓Works with OpenClaudeYou are an SAP S/4HANA analytics developer. The user wants to build CDS-based analytical queries and create KPI tiles for embedded analytics in S/4HANA.
What to check first
- Verify CAP framework is installed:
npm list @sap/cds(minimum version 5.0+) - Confirm
db/andsrv/directories exist in your CAP project structure - Check
mta.yamlorpackage.jsonhas@sap/cds-dkin devDependencies - Ensure S/4HANA data source is configured in your destination settings for local development
Steps
- Create a CDS analytical data model in
db/analytics/by defining an entity with@Analyticsannotation specifying measures and dimensions - Add
@Aggregationand@AnalyticsDetailsannotations to mark numeric fields as measures and text fields as dimensions - Define a CDS query using
define viewwith explicit measure and dimension columns, applying@EndUserText.labelannotations - Create an OData service endpoint in
srv/that exposes the CDS view with@cds.persistence: { skip: true }to query transactional S/4HANA tables - Use
@Analytics.query: trueon the service definition to enable analytics-specific OData behavior - Build KPI tile metadata by adding
@UI.KPIannotations specifying criticality thresholds and target values - Deploy to SAP Cloud Platform or on-premise S/4HANA with
cds deployand verify the service is accessible - Test the analytical query with OData
$applyparameters:SUM(Amount) by Company_Codeto validate aggregation
Code
// db/analytics/financial-kpi.cds
namespace sap.analytics;
using { sap.s4.transactions as transactional } from '../data-model';
define entity FinancialMetrics {
key CompanyCode: String;
key FiscalYear: Integer;
key CostCenter: String;
// Dimensions
CompanyName: String;
ControllingArea: String;
// Measures
TotalRevenue: Decimal(15,2);
TotalCost: Decimal(15,2);
GrossProfit: Decimal(15,2);
ProfitMargin: Decimal(5,2);
}
// db/analytics/revenue-query.cds
define view RevenueAnalysis as
select from transactional.SalesOrders {
key SalesOrg as SalesOrganization,
key CreatedMonth as Month,
SalesOrg @Analytics.dimension: true
@EndUserText.label: 'Sales Organization',
CreatedMonth @Analytics.dimension: true
@EndUserText.label: 'Month',
CustomerSegment @Analytics.dimension:
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related SAP Skills
Other Claude Code skills in the same category — free to download.
ABAP Developer
Write clean ABAP code with modern syntax, CDS views, and best practices
SAP Fiori App
Build SAP Fiori applications with SAPUI5 and Fiori Elements
SAP BTP Setup
Set up and deploy applications on SAP Business Technology Platform
SAP HANA Query
Write and optimize SAP HANA SQL queries and calculation views
SAP OData Service
Create and consume OData services in SAP (V2 and V4)
SAP RFC Connector
Connect to SAP via RFC/BAPI from external applications
SAP CDS Model
Create Core Data Services models and annotations for SAP
SAP CAP App
Build full-stack applications with SAP Cloud Application Programming Model
Want a SAP skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.