Skip to Content

Create a Business Service Using CDS

0 %
Create a Business Service Using CDS

Create a Business Service Using CDS

Define a data and service model using SAP Web IDE Full-Stack and the SAP Cloud Application Programming Model based on Core Data and Services (CDS).

You will learn

  • How to develop a simple business service on SAP Cloud Platform using the SAP Cloud Application Programming Model and SAP Web IDE Full-Stack


Step 1: Start a project
  1. In SAP Web IDE choose File | New | Project from Template.

  2. Search for SAP Cloud Platform Business Application.

    Select the project template

    If you do not see the template, make sure All Categories is selected from the Category drop-down menu and try again. If you still do not see the template, make sure the SAP Cloud Platform Business Application Development Tools are enabled. See Developing SAP Cloud Platform Business Applications.

  3. Enter bookshop as the project name and choose Next.

  4. In the Template Customization tab leave the default values.

  5. Complete the Project Details tab as shown in the screenshot, ensuring that the Include sample files in project checkbox is checked.

    Complete the project details

    You should update the Java Package to match the namespace used in this sample application, which is my.bookshop.

  6. Choose Finish.

Log on to answer question
Step 2: Define a data model
  1. Open db/data-model.cds and replace the template with the following CDS definitions:

    namespace my.bookshop;
    entity Books {
      key ID : Integer;
      title  : String;
      author : Association to Authors;
      stock  : Integer;
    entity Authors {
      key ID : Integer;
      name   : String;
      books  : Association to many Books on = $self;
    entity Orders {
      key ID : UUID;
      book   : Association to Books;
      buyer  : String;
      date   : DateTime;
      amount : Integer;
    Define the data model
  2. Save the file.

Why might the type of the ID property in the Orders entity be different from the ID properties in the Books and Authors entities?
Step 3: Define a service
  1. Open the file srv/cat-service.cds.

  2. Replace the template with the following CDS definitions:

    using my.bookshop from '../db/data-model';
    service CatalogService {
      entity Books    @readonly as projection on bookshop.Books;
      entity Authors  @readonly as projection on bookshop.Authors;
      entity Orders   @insertonly as projection on bookshop.Orders;
    Define the service model
  3. Save the file.

What is the name of the service?
Step 4: Test-run the service
  1. Click on the srv module and choose Run from the global toolbar.

    This might take a few minutes because a new cloud container has to be initialized and started. Subsequent restarts are much faster, because hot deployment is used.

    Choose Run

    If the build is unsuccessful, check the console log for errors. Errors similar to this one: Could not create the 'bookshop-bookshop-hdi-container-D0oRdR+pMxiYd6NYDr' instance of the 'hana' service type for the 'bookshop-hdi-container' resource. No hdi-shared plan available found in this space." To fix this issue, try the following:

    1. Make sure your HANA entitlement is assigned.

    2. Go to SAP Cloud Platform Cockpit | Cloud Foundry | Entitlements.

    3. Click on Edit.
      Edit entitlements

    4. Scroll down until you find HANA and change the value to 1.
      Change hdi-shared value

    5. Save your changes, and re-try to run your service.

  2. Go to the Run Console and click on the URL.

    Run console

    A new browser window opens containing a link to the OData service.

  3. Click on the service link.

    The OData service document opens.

  4. Add /$metadata to the URL and refresh.

    The OData metadata document opens in EDMX format.

  5. Replace /$metadata with /Books.

    An error message is displayed because we have not added a database yet.

Log on to answer question

Next Steps

Back to top