Complex CDS Modeling: Compositions, Projections & Managed vs. Unmanaged Entities

Core Data Services (CDS) are central to SAP CAP development. Beyond basic entity definitions, CAP developers benefit from advanced modeling techniques such as compositions, projections, and understanding managed vs. unmanaged entities. These concepts improve code reuse, data integrity, and maintainability.

This guide explores these advanced CDS modeling patterns and shows practical examples for enterprise CAP applications.

Compositions in CDS

Compositions define strong ownership between entities. The parent entity owns the lifecycle of the child entities. Deleting the parent also deletes the children automatically.

Example: Orders and OrderItems

entity Orders {
  key ID : UUID;
  customerName : String;
  items : Composition of many OrderItems on items.order = $self;
}

entity OrderItems {
  key ID : UUID;
  order : Association to Orders;
  productName : String;
  quantity : Integer;
}

Key Points:

  • Composition indicates strong ownership
  • Child entity cannot exist without the parent
  • Supports cascading deletes

Projections in CDS

Projections allow you to expose a subset or transformed view of an entity. They are read-only by default unless extended.

Example: Product Projection

entity Products {
  key ID : UUID;
  name : String;
  price : Decimal(10,2);
  cost : Decimal(10,2);
}

entity ProductPublic as projection on Products {
  ID,
  name,
  price
}

Benefits:

  • Control which fields are exposed in services
  • Simplify API contracts
  • Enhance security by hiding sensitive fields
  • Enable multiple views of the same entity

Managed vs. Unmanaged Entities

CAP distinguishes between managed and unmanaged entities:

Managed Entities

  • CAP automatically generates standard CRUD operations
  • CDS annotations like @cds.persistence.exists or @odata.draft.enabled apply
  • Suitable for service-based access

Example:

entity Customers {
  key ID : UUID;
  name : String;
}

CAP automatically creates:

  • READ, CREATE, UPDATE, DELETE handlers
  • Persistence in the underlying database

Unmanaged Entities

  • CAP does not automatically generate handlers or persistence
  • Used for projections, external services, or calculated data
  • Developers must implement handlers manually

Example:

entity CustomerSummary @(unmanaged) {
  ID : UUID;
  name : String;
  orderCount : Integer;
}

Use Cases:

  • Aggregated views
  • Joined or computed entities
  • External data sources

Combining Compositions and Projections

You can combine compositions and projections for flexible APIs.

Example: Exposing Order Summary

entity OrderSummary as projection on Orders {
  ID,
  customerName,
  items {
    productName,
    quantity
  }
}

Notes:

  • Nested compositions are preserved
  • Projections can hide fields or sensitive data
  • Supports OData $expand automatically

Best Practices for Complex CDS Modeling

  • Use compositions for strong parent-child relationships
  • Use associations for weak relationships
  • Use projections to expose only necessary fields
  • Keep unmanaged entities for derived data or analytics
  • Avoid circular compositions
  • Document entities for team clarity
  • Use CDS annotations for behavior (drafts, readonly, restrict)

Real-World Example

  1. Order Management System:
    • Orders (parent) composed of OrderItems (children)
    • Projections for public APIs expose only order summary
    • Managed entities for database persistence
    • Unmanaged entities for reporting and analytics
  2. E-Commerce App:
    • Products and Categories with associations
    • ProductPublic projection hides internal cost
    • Calculated discount views as unmanaged entities

Conclusion

Advanced CDS modeling in CAP through compositions, projections, and proper use of managed vs. unmanaged entities enables scalable, maintainable, and secure applications. Mastering these concepts ensures clean data modeling, optimized APIs, and flexibility for enterprise scenarios.

you may be interested in this blog here:-

Don’t Fear the Update: Navigating the Challenges of how to implement sap note

Five Top Technology Investment Drivers for 2024

How many dollars worth of RSU does Salesforce typically offer an MTS (experienced hire) on joining?

Integration cloud system to HANA Cloud Platform using Cloud Connector

₹25,000.00

SAP SD S4 HANA

SAP SD (Sales and Distribution) is a module in the SAP ERP (Enterprise Resource Planning) system that handles all aspects of sales and distribution processes. S4 HANA is the latest version of SAP’s ERP suite, built on the SAP HANA in-memory database platform. It provides real-time data processing capabilities, improved…
₹25,000.00

SAP HR HCM

SAP Human Capital Management (SAP HCM)  is an important module in SAP. It is also known as SAP Human Resource Management System (SAP HRMS) or SAP Human Resource (HR). SAP HR software allows you to automate record-keeping processes. It is an ideal framework for the HR department to take advantage…
₹25,000.00

Salesforce Administrator Training

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
₹25,000.00

Salesforce Developer Training

Salesforce Developer Training Overview Salesforce Developer training advances your skills and knowledge in building custom applications on the Salesforce platform using the programming capabilities of Apex code and the Visualforce UI framework. It covers all the fundamentals of application development through real-time projects and utilizes cases to help you clear…
₹25,000.00

SAP EWM

SAP EWM stands for Extended Warehouse Management. It is a best-of-breed WMS Warehouse Management System product offered by SAP. It was first released in 2007 as a part of SAP SCM meaning Supply Chain Management suite, but in subsequent releases, it was offered as a stand-alone product. The latest version…
₹25,000.00

Oracle PL-SQL Training Program

Oracle PL-SQL is actually the number one database. The demand in market is growing equally with the value of the database. It has become necessary for the Oracle PL-SQL certification to get the right job. eLearning Solutions is one of the renowned institutes for Oracle PL-SQL in Pune. We believe…
₹25,000.00

Pega Training Courses in Pune- Get Certified Now

Course details for Pega Training in Pune Elearning solution is the best PEGA training institute in Pune. PEGA is one of the Business Process Management tool (BPM), its development is based on Java and OOP concepts. The PAGA technology is mainly used to improve business purposes and cost reduction. PEGA…
₹27,000.00

SAP PP (Production Planning) Training Institute

SAP PP Training Institute in Pune SAP PP training (Production Planning) is one of the largest functional modules in SAP. This module mainly deals with the production process like capacity planning, Master production scheduling, Material requirement planning shop floor, etc. The PP module of SAP takes care of the Master…
X
WhatsApp WhatsApp us
Call Now Button