Skip to Content
Technical Articles
Author's profile photo Xiao-fei Song

Creating new services using the CDS Graphical Modeler for SAP Business Application Studio

In this blog post, we’ll demonstrate how to create new services using the CDS Graphical Modeler. For introduction of CDS Graphical Modeler and how to setup the dev space in SAP Business Application Studio, please refer to https://blogs.sap.com/2021/04/23/an-introduction-to-cds-graphical-modeler-for-sap-business-application-studio.

Suppose you have below entity model file in db/data-model.cds:

namespace my.bookshop;

using
{
    cuid,
    managed,
    temporal
}
from '@sap/cds/common';

entity Books : cuid, managed, temporal
{
    title : String;
    stock : Integer;
    author : Association to one Authors;
    publisher : Association to one Publishers;
    chapters : Composition of many Chapters on chapters.owner = $self;
    covers : Association to many Covers on covers.owner = $self;
}

entity Authors : cuid, managed
{
    address : Association to one Addresses;
}

entity Addresses : cuid, managed
{
}

entity Publishers : cuid, managed
{
    industry : Association to one Industries;
}

entity Industries : cuid, managed
{
}

entity Chapters : cuid, managed, temporal
{
    owner : Association to one Books;
}

entity Covers : cuid, managed, temporal
{
    owner : Association to one Books;
}

And you would want to create projections in the srv/cat-service.cds in the context of a new service. So, open srv/cat-service.cds using the CDS Graphical Modeler:

And you will see below after the CatalogService is opened in the CDS Graphical Modeler:

Now let’s create a new service called “AdminService” in this CDS File by clicking the “New Service” toolbar button:

Enter “AdminService” as the service name in the dialog and click “Create” to dismiss the dialog, and the new service “AdminService” is created:

And you can open the srv/cat-service.cds file using the code editor to verify the content:

using my.bookshop as my from '../db/data-model';

service AdminService
{
}

service CatalogService
{
}

Now let’s create a new projection for Books entity defined in my.books namespace:

In the “new projection” dialog select “my.books.Books” entity as its base type:

Click “create” button and the projection is created in the newly created AdminService:

You can check the CDS file content using the code editor:

using my.bookshop as my from '../db/data-model';

service AdminService
{
    entity Books as
        projection on my.Books;
}

service CatalogService
{
}

For more details about how to create projections using the CDS Graphical Modeler, please refer to https://blogs.sap.com/2021/04/19/creating-cds-projections-using-cds-graphical-modeler.

Conclusion

As a summary, in the blog post we demonstrate how to create a new service for a service CDS file in srv/cat-service.cds, and we also demonstrate how to create a new projection in the newly created service.

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.