Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
rohitvolvo127
Explorer
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.



As you can see we have 3 major folders

  • app

  • db

  • srv


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

Step 1: Create Database Entity



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.



Name the file as data-model.cds
data-model.cds



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 :



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.



 

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.



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



Name the file as cat-service.cds
cat-service.cds



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



The final project structure should look like this.



 

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



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



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



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



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



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



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



Now, let's click on the SalesOrders Entity.



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 add data to our databse entity.

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

Next Episode: Adding Data to the Database Entities on BAS for CAPM Full Stack UI5 Development
2 Comments
Labels in this area