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: 
dhiraj_more
Participant
Hello Everyone,

Writing my first blog on Custom CDS Entity on SAP Cloud foundry environment and Restful Programming Model.

In this blog, we will see what is custom CDS entity and one of the use case where I have used it.

Before we moved to Custom CDS Entity, we need to understand Restful Programming Model  and Core Data Services.

In Restful Programming model, CDS is used for data modeling and then we have Behavior definition and implementation which will have business logic for different operations(including CRUD). And then we have Service definition and binding which expose our data model(CDS entity) to external world applications.

As compare to traditional Fiori application or Fiori ABAP programming model, we have below limitations with Restful Programming model.

  1. Since we don't have SEGW gateway project, we cannot create our own entities manually or structures directly. All entities are based on CDS and is based on SELECT statement. Any requirement which is not realized by Select statement will have issues.

  2. We used to have extension class DPC_EXT where we used to redefine respective methods for CRUDQ in case of additional requirements. But here we don't have any classes DPC/MPC/DPC_EXT/MPC_EXT.


In order to overcome the above 2 limitations we have the concept of Custom CDS entity.

Here comes the concept of Custom CDS entity.A Custom CDS Entity enables you to expose data using ABAP classes in the Application Server ABAP. A CDS custom entity provides the signature of a CDS entity. The implementation of the logic to retrieve the data is implemented in an ABAP class.

In simple terms, custom CDS entity provide us to declare required attributes/fields as we do when creating normal structures and then create an ABAP class that implements the interface IF_RAP_QUERY_PROVIDER. That means, we can call FM, different class methods apart from Select statement more like report.

This class needs to be referenced in the entity annotation @ObjectModel.query.implementedBy.

Next to provide a Use case w]here we can apply custom CDS entity.

Basically I had a requirement where in one single ODATA query call we have to do two operations, one is to read record from table based on provided filters. And second if query fails means no record found then I have to save the provided filter value in other table as log of failed queries. And then there will be a team which will go through log table records and update the main table if required.

Now if I will go with normal CDS entity I can only read/query main table but cannot save the filters to log table. Therefore I created a custom entity. Now in implementation class, first I am reading main table based on filter, if record not present then updating filter values to log table.

This way I used custom CDS entity concept in my use case.

I conclude my blog with "Custom entities are used for data models whose runtime is implemented manually".

In case if something is missing or incorrect please let me know I will update it.

Happy Learning 🙂

Thanks,

Dhiraj More

 
5 Comments
Labels in this area