Skip to Content
Technical Articles
Author's profile photo Dhiraj More

Custom CDS Entity on SAP Cloud Restful Programming Model

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 🙂


Dhiraj More


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Ravi Singh
      Ravi Singh

      One thing i still cant figure out is  how to  raise an exception in Get call for custom entity in your custom class which implement IF_RAP_QUERY_PROVIDER.

      Lets say for the filters no values are found, how do we raise an exception and messages in it that can be displayed on Custom UI5 App . We had message container in DPC extension classes. Any idea on this ?

      Author's profile photo Venkata Subba Raju Elluru
      Venkata Subba Raju Elluru
      1. How to overwrite or fill custom value in read operations
      2. When I tried to implement read in behaviour implementation control or breakpoint is not triggering in read operation
      3. Can we use custom CDS for reading Text objects?
      Author's profile photo Venkata Subba Raju Elluru
      Venkata Subba Raju Elluru
      1. can we use a custom CDS entity for reading Text objects?
      2. is it possible to overwrite the values in read operation
      3. when i implement read operation in behaviour implementation in unmanaged scenario break point is not triggering
      Author's profile photo Dhiraj More
      Dhiraj More
      Blog Post Author

      Hi Raju,

      I never tried reading Text objects in Custom CDS entity but I think it is possible as we can write abp code in implementation class and use ABAP API's.

      The same goes for overwriting the values in read operation.

      Normally break point should triggered during read operation in managed scenario.

      Please let me know if you able to achieve it.


      Dhiraj M

      Author's profile photo Venkata Subba Raju Elluru
      Venkata Subba Raju Elluru
      1. I am trying with Custom CDS entity if I achieve will let you know
      2. I find one more approach here using @ObjectModel.virtualElement to read long text from text objects
      3. For unmanaged scenario read method in behavior, implementation system control is not triggering