Concept Map: SAP CAP to Atscript
This page maps what you write in the SAP Cloud Application Programming Model® (SAP CAP) to the Atscript way of doing the same thing, with links to where each Atscript side is documented. The two are separate tools with their own building blocks: each row pairs things that do the same job. The worked example shows them together in one model.
The table
| SAP CAP | Atscript |
|---|---|
entity Books { … } | interface Books with @db.table |
key ID | @meta.id |
cuid | @meta.id with @db.default.uuid on an ID: string.uuid |
managed (createdAt, modifiedAt) | number.timestamp.created, number.timestamp.updated |
managed (createdBy, modifiedBy) | set in the controller's onWrite hook |
String(111) | string with @expect.maxLength 111 |
Decimal(9,2) | decimal with @db.column.precision 9, 2 |
Integer | number.int |
status : String default 'new' | @db.default 'new' |
enum { … } | a union of literals: 'new' | 'done' |
Association to Authors | @db.rel.FK on the foreign key + @db.rel.to on the navigation |
Association to many Books on books.author = $self | @db.rel.from on the navigation |
Composition of many Items | @db.rel.from, with @db.rel.onDelete 'cascade' on the child's foreign key |
@title, @Common.Label | @meta.label |
@mandatory | @meta.required |
@assert.range | @expect.min / @expect.max |
@assert.format | @expect.pattern |
@readonly on an element | @meta.readonly |
@readonly on an entity | serve it with a @ReadableController |
@assert.unique | @db.index.unique |
@odata.etag | @db.column.version |
as projection on, as select from | @db.view, @db.view.for |
@Common.ValueList | @ui.valueHelp (or a foreign key: its target becomes the picker) |
@Common.Text, @UI.TextArrangement | @ui.valueLabel; on the text of a single key also @ui.dict.label |
@UI.LineItem, @UI.FieldGroup | @ui.table.*, @ui.form.* |
service CatalogService { … } | Moost controllers: @TableController, @ReadableController |
srv.before(…), srv.on(…) | controller hooks: onWrite, transformFilter, guardWrite |
@restrict, @requires | Aooth: @ArbacResource, @ArbacAction |
cds deploy | asc db sync |
SELECT.from(Books).where(…) (CQL) | table.findMany({ filter, controls }) |
Model
In Atscript, an entity is an exported interface with @db.table; its fields carry the database, validation and UI annotations together. What the SAP CAP aspects cuid and managed add is written as field types and annotations:
@db.table 'books'
export interface Book {
@meta.id
@db.default.uuid
ID: string.uuid
@meta.label 'Title'
@meta.required
@expect.maxLength 111
title: string
createdAt?: number.timestamp.created
modifiedAt?: number.timestamp.updated
}number.timestamp.created is filled on insert, number.timestamp.updated on every update. Reusable parts of a model are plain interfaces and types, combined with extends or & where SAP CAP uses aspects with :.
See Atscript interfaces and types, Atscript DB tables and defaults.
Associations and compositions
In Atscript, the counterpart of a managed association is a foreign key and a navigation, declared separately:
@db.rel.FK
author_ID?: Author.ID // the foreign key, typed as the target's key
@db.rel.to
author?: Author // the navigation to the principalThe other side lists the dependents with @db.rel.from (books?: Book[]). A composition maps to the same @db.rel.from with @db.rel.onDelete 'cascade' on the child's foreign key, so deleting the parent deletes its children. Related rows are loaded with $with, and written together with deep inserts and patches. See Atscript DB relations.
Validation
@meta.required, @expect.min / @expect.max, @expect.maxLength and @expect.pattern are checked by the same validator in the browser (Atscript UI forms, db-client's preflight) and on the server (every write of Atscript DB). A failure answers 400 with an entry per field, which Atscript UI shows on the field. See Atscript validation.
Views and projections
A projection that renames or picks columns, or a select from with joins, maps to an Atscript DB view: @db.view with @db.view.for (the entry table), @db.view.joins, @db.view.filter. A projection that only restricts what a service exposes is often simpler as a controller over the table itself, with transformFilter for the rows and hasField for the columns. See Atscript DB views.
UI annotations
The @UI vocabulary describes SAP Fiori® elements floorplans; Atscript UI reads annotations of its own from the .as model:
- labels and descriptions:
@meta.label,@meta.description; - table columns and their order:
@ui.table.*; form fields, order, groups and placeholders:@ui.form.*; - value helps:
@ui.valueHelpwith.filland.column, and every foreign key; texts next to codes:@ui.valueLabel; the text a picker lists a row by:@ui.dict.label; fixed values:@ui.type 'select'.
See Atscript UI form annotations and table annotations.
Services and handlers
An SAP CAP service exposes entities over OData. In Atscript each table gets a Moost controller, which serves the REST protocol of Atscript DB (/query, /pages, /one, /meta and the writes); Atscript UI and @atscript/db-client speak it. Handlers become overrides on the controller class:
| SAP CAP handler | Moost DB hook |
|---|---|
before('CREATE' | 'UPDATE', …) | onWrite(action, data): change or reject the body |
before('READ', …) adding a where | transformFilter(filter): scope the rows |
| validation inside the transaction | guardWrite(ctx) |
on('someAction', …) | a controller action or a custom endpoint |
See Moost DB customization and actions.
OData is not served
Atscript DB controllers serve Atscript DB's own REST protocol, not OData. Atscript UI and your own apps use it through @atscript/db-client; a consumer that needs OData (an integration with SAP S/4HANA®, a Fiori elements app) keeps talking to an SAP CAP or other OData service.
Authorization
@requires and @restrict become roles and privileges of Aooth: @ArbacResource and @ArbacAction on controllers, with scopes that narrow the rows a role sees. See Aooth's authorization guide.
Deployment
cds deploy becomes asc db sync: it compares the models with the live database and applies the difference, with --dry-run to preview and --safe to skip destructive steps. See Atscript DB schema sync.