Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 

Introduction to writable CDS Entities 

CDS provides a powerful way to define and consume data models. Traditionally, CDS views were read-only, used primarily for data retrieval. However, with the evolution of SAP's ABAP platform, Writable CDS Entities were introduced to enable direct data manipulation (Update, modify). 

Types of Writable CDS Entities 

  1.Writable CDS View Entities - Wrap DDIC tables for direct writing access. 

  2.Writable External Entities - Enable write access to eternal database. 

In this blog, we are going to focus on CDS Writable Entities. I will walk you through the concept step-by-step, using a practical example to demonstrate how it works and what operations—such as INSERT and UPDATE—we can perform using a writable entity. Let's dive into the example. 

Create a Table 

kalmesh_0-1761035674723.png

 

Next, we will create a writable CDS entity on top of the database table ZTRL_T_AIRPORT, Using the writable CDS entity, we can perform update operations directly, and we can also insert new records by using the MODIFY statement. We will explore how to implement these operations in the upcoming steps. 

kalmesh_1-1761035762682.png

In the next step, we will create a class to perform all the required operations. We will use standard interface methods to execute these operations and display the output in the console for better visibility and testing. 

kalmesh_2-1761035834570.png

Let’s insert some data into the database table. Since we cannot perform insert operation directly through a writable CDS entity, I will proceed with inserting data into the underlying database table.

kalmesh_3-1761035898193.png

Fetch the data from the database table to verify whether the records were successfully inserted, as performed in the previous step. 

kalmesh_4-1761035941906.png

 

UPDATE 

Now, let’s perform an update operation using the writable CDS entity (ZTRL_I_WRENT_DEMO). In this example, we will update the name field to demonstrate how data can be modified through the entity. 

kalmesh_5-1761036054229.png

INSERT 

We will insert a new record by using the MODIFY statement, which allows us to perform insert operations through the writable CDS entity. 

kalmesh_6-1761036103280.png

DELETE 

Direct delete operations are not supported through writable CDS entities. If attempted, the system will raise an error, as shown below. 

kalmesh_7-1761036149147.png

kalmesh_8-1761036170936.png

Conclusion 

Writable CDS Entities offer a powerful and flexible way to interact with database tables in SAP. Through these entities, we can perform update operations and even insert new records using the MODIFY statement. 

Keep experimenting, keep learning—and happy coding! 🚀 

3 Comments
Labels in this area