Quick CDS syntax reference for entities, services, annotations, and queries
Provides quick CDS syntax reference for entities, services, annotations, and queries.
/plugin marketplace add secondsky/sap-skills/plugin install sap-cap-capire@sap-skillsComprehensive CDS (Core Data Services) syntax reference for SAP Cloud Application Programming Model.
entity Books {
key ID : UUID;
title : String(100);
price : Decimal(10,2);
stock : Integer;
}
using { cuid, managed } from '@sap/cds/common';
entity Books : cuid, managed {
title : String(100);
price : Decimal(10,2);
}
// cuid adds: ID : UUID
// managed adds: createdAt, createdBy, modifiedAt, modifiedBy
entity Books {
key ID : UUID;
title : String(100);
author : Association to Authors; // to-one
reviews : Composition of many Reviews on reviews.book = $self; // to-many
}
service CatalogService {
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
}
service OrdersService {
entity Orders as projection on my.Orders actions {
action cancel() returns String;
};
}
entity Books {
title : String(100) @title: 'Book Title';
price : Decimal(10,2) @title: 'Price';
stock : Integer @assert.range: [0, 9999];
}
annotate CatalogService.Books with @(
UI.LineItem: [
{ Value: title, Label: 'Title' },
{ Value: author.name, Label: 'Author' }
]
);
const books = await SELECT.from(Books);
const book = await SELECT.one.from(Books).where({ ID: bookID });
await INSERT.into(Books).entries({ title: 'CAP Guide', price: 29.99 });
await UPDATE(Books).set({ stock: stock + 10 }).where({ ID: bookID });
await DELETE.from(Books).where({ ID: bookID });
For comprehensive documentation, see: