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
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.
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.
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.
Fetch the data from the database table to verify whether the records were successfully inserted, as performed in the previous step.
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.
INSERT
We will insert a new record by using the MODIFY statement, which allows us to perform insert operations through the writable CDS entity.
DELETE
Direct delete operations are not supported through writable CDS entities. If attempted, the system will raise an error, as shown below.
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! 🚀