6

Creating Database Entities on BAS for CAPM Full Stack UI5 Development

 2 years ago
source link: https://blogs.sap.com/2022/04/01/creating-database-entities-on-bas-for-capm-full-stack-ui5-development/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
April 1, 2022 4 minute read

Creating Database Entities on BAS for CAPM Full Stack UI5 Development

Welcome to the third episode of the Series: SAP CAPM Full Stack UI5 Application with CRUD Operations. Till now we have created Development Space in BAS and set up a project structure for further development. In this episode, we will create a database entity for the project and expose the same.

Assumption(OR Must Have to Start):

  • You have followed our previous episode to set up the Project.

For now, we have the below project structure.

p23-2.png

As you can see we have 3 major folders

We will work on them one by one & get to know the functionality.

Step 1: Create Database Entity

25-6.png

Let’s start with the DB Folder: It contains the Database Entity which is based on CDS Model. The design-time artefacts declared in this file will be converted to run-time, physical artefacts in the database. In this example, the entities will become tables.

Right Click on db folder & create a New File.

26-7.png

Name the file as data-model.cds

data-model.cds

27-7.png

Now, let’s create an entity, you can copy the below code and paste it into the created file.

namespace cap_tutorial;


entity SalesOrders {
    @title : 'Sales Order Number'
  key soNumber: String;
  @title : 'Order Date'
  orderDate: Date;
  @title : 'Customer Name'
  customerName: String;
  @title : 'Customer Number'
  customerNumber: String;
  @title : 'PO Number'
  PoNumber: String;
  @title : 'Inquiry Number'
  inquiryNumber: String;
  @title : 'Total Sales Order'
  totalOrderItems: Integer; 
}

It should look like this :

28-6.png

We have created an Entity with the name SalesOrders, which have 7 properties. It will create a table with 7 fields. Here key denotes the Primary key of the table @title is an annotation that we are using to define the text for our table properties.

28-6.png

Step 2: Create Service

Now go to the srv folder. We will be declaring services to expose the database entities we declared in the previous step.

29-6.png

Create a new file in srv folder by right-clicking on the same.

30-7.png

Name the file as cat-service.cds

cat-service.cds

31-6.png

Copy & Paste the below code in the created file.

using { cap_tutorial as db } from '../db/data-model';

service CatalogService@(path:'/CatalogService')
    {

    entity SalesOrder as projection on db.SalesOrders
    }

The file should finally look like this. Here we have created a CAP service that will expose our entity SalesOrders

32-6.png

The final project structure should look like this.

33-7.png

Let’s build the project now once. For that do cds build

cds build

34-5.png

So, you will see the below screen, your project is built now.

35-3.png

Now, let’s finally see what we have built. Let’s do cds watch it will run your project built till now.

36-2.png

Finally, once all checks are passed your project will start running & you will get an option to Expose and Open, click on the same to see the final build.

cds watch

37-2.png

You will get the screen something like below, where you will the the SalesOrder Entity Exposed on the page.

38-2.png

Now, you can click on $metadata to check the MetaData / Structure of the Exposed Odata Service.

39-2.png

You can further click and check the Catalogue Service to see all the endpoints available.

40-2.png

Now, let’s click on the SalesOrders Entity.

41-2.png

Right now it will show no Data as we haven’t inserted any Data in our Table.

Feel free to drop your comments in the comment section.

In this blog post we have learnt how to create database entity and expose the same.

In the next blog post we will see how to set add data to our databse entity.

Further reading – https://cap.cloud.sap/docs/guides/

Next Episode: Coming Soon.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK