In SAP ABAP CDS Views, a transaction can be defined in a CDS view to represent business logic for data manipulation (Create, Update, Delete). A transaction-based CDS view allows the execution of changes to the database table using ABAP code or custom transaction logic in a more structured manner.

While CDS views themselves are primarily designed for read-only access to database tables, transactional CDS views are a feature that extends their capabilities to allow updates and changes.

Transactional CDS Views (For Create, Update, Delete Operations)

A transactional CDS view is a special type of view that allows for insert, update, and delete operations. These operations are typically bound to a specific business object or entity and help to simplify data manipulation in applications that use ABAP RESTful Programming model (RAP) or Fiori apps.

Annotations for Transactional CDS Views

To define transactional behaviors in CDS views, you use the @ObjectModel annotation to indicate that a CDS view can be used for CRUD (Create, Read, Update, Delete) operations.

Basic Example of a Transactional CDS View

@AbapCatalog.sqlViewName: 'ZFLIGHT_TXN'
@EndUserText.label: 'Transactional View for Flight Data'
@ObjectModel.transactionalProcessingEnabled: true
define view ZFLIGHT_TXN
with parameters p_carrid: s_carrid
as select from sflight {
key carrid,
key connid,
fldate,
price
}
where carrid = :p_carrid

Key Annotations Used for Transactional CDS Views:

  1. @ObjectModel.transactionalProcessingEnabled:
  1. @ObjectModel.writeActive:
  1. @ObjectModel.createEnabled:
  1. @ObjectModel.updateEnabled:
  1. @ObjectModel.deleteEnabled:

Example of a Transactional CDS View with Create and Update Capabilities

@AbapCatalog.sqlViewName: 'ZFLIGHT_TXN_CREATE_UPDATE'
@EndUserText.label: 'Transactional CDS View for Flight Data with Create and Update'
@ObjectModel.transactionalProcessingEnabled: true
@ObjectModel.writeActive: true
@ObjectModel.createEnabled: true
@ObjectModel.updateEnabled: true
define view ZFLIGHT_TXN_CREATE_UPDATE
with parameters p_carrid: s_carrid
as select from sflight {
key carrid,
key connid,
fldate,
price
}
where carrid = :p_carrid

Explanation:

Transactional Operations:

  1. Create Operation: You can create new records in the database table that the CDS view references. This is possible if the view is configured with @ObjectModel.createEnabled: true.

Example:

insert into ZFLIGHT_TXN_CREATE_UPDATE (carrid, connid, fldate, price)
values ('LH', '1001', '2025-01-01', 500).
  1. Update Operation: If the view supports updates (@ObjectModel.updateEnabled), you can modify the records based on the CDS view.

Example:

update ZFLIGHT_TXN_CREATE_UPDATE
set price = 600
where carrid = 'LH' and connid = '1001'.
  1. Delete Operation: The DELETE operation can be executed if the view supports deletions via the annotation @ObjectModel.deleteEnabled.

Example:

delete from ZFLIGHT_TXN_CREATE_UPDATE
where carrid = 'LH' and connid = '1001'.

Transactional Views in the ABAP RESTful Application Programming Model (RAP):

The ABAP RESTful Application Programming Model (RAP) makes use of transactional CDS views to enable data changes via the Fiori apps or UI5 applications. RAP allows developers to build applications that leverage CDS views for transactional data manipulation.

Conclusion: