ABAP for Cloud Development
AS ABAP Release 914, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP RAP Business Objects → RAP - Behavior Definitions → RAP - BDL for Behavior Definitions → RAP - Managed and Unmanaged Behavior Definitions → RAP - EntityBehaviorDefinition → RAP - EntityBehaviorCharacteristics →
RAP - persistent table
Syntax
...
persistent table TableName
...
Description
The RAP persistent table is the DDIC database table a RAP BO is based on. The persistent data on the persistent table is processed by RAP BO operations.
Availability
- Available for managed RAP BOs only and for these, it is mandatory to specify a persistent table.
- Exception: In a managed RAP BO with an unmanaged save, defined using
with unmanaged save
, a persistent table must not be defined. - In a projection business object, the persistent table is automatically inherited and need not be specified.
Requirements:
- If the BDEF specifies an ETag field, the persistent table requires a field that is used to describe the state of the database table. This can be, for example, a time stamp field.
- If this field is annotated in CDS with the relevant annotation, such as
@Semantics.systemDateTime.localInstanceLastChangedAt: true
, then it is automatically updated by the RAP framework. - If the RAP BO is draft-enabled and has a total ETag field, the persistent table requires a field that is updated whenever the BO instance is changed. This must be a separate field from the ETag master field. The total ETag field is necessary on the lock master entity.
- If the total ETag field is a time stamp field and if it is annotated in the CDS data model with the annotation
@Semantics.systemDateTime.lastChangedAt
, then this field is updated automatically by the RAP framework. - If the primary key field is of type
raw(16)
(UUID), then it can be filled by the RAP framework using internal numbering. The syntax for this isnumbering:managed
. - If you decide to use UUIDs as primary keys, the following rules apply:
- Every entity needs a field for the UUID key.
- Child entities must have a field for their parent's UUID. This is required to define associations for the CDS composition relationship.
- Any child entity that has no parent-child relationship with the lock master entity must have a field with the lock master's UUID. This is important to define associations to the lock master entity, which is required for ETag handling.
Hints
- If the field names of the persistent database table differ from the field names of the CDS views of the underlying data model, then a RAP type mapping is required in the entity behavior body. This can be the case, for example, if the fields of the CDS data model have alias names.
- A RAP persistent table is a regular DDIC database table and can be accessed as such. Access with ABAP SQL and AMDP is technically possible, but not recommended. It is recommended that a persistent table is accessed using the RAP framework only, for example, with ABAP EML.
Example
The following example shows a managed BDEF based on the CDS root view entity DEMO_MANAGED_ROOT
. It specifies persistent database tables for the parent and the child entity.
managed implementation in class bp_demo_managed_root unique;
strict ( 2 );
define behavior for DEMO_MANAGED_ROOT
persistent table demo_tab_root
lock master
authorization master ( global )
{
create;
update;
delete;
association _child { create; }
field ( readonly : update ) key_field;
}
define behavior for DEMO_MANAGED_CHILD alias child
persistent table demo_tab_child
lock dependent by _parent
authorization dependent by _parent
{
update;
delete;
field ( readonly : update ) key_field;
association _parent;
}
The class CL_DEMO_RAP_EML_MODIFY_OP_2
accesses the business object using EML and performs the following steps:
- Modify operations with
CREATE
andCREATE BY
- Two
MODIFY ENTITY
operations are executed to create data sets for the root entity using theCREATE
statement as well as data sets for the child entity usingCREATE BY
. - Modify operation with
UPDATE
- Data sets of the root entity are updated.
- Modify operation with
DELETE
- Data sets of the root entity are deleted.
- Read operation with
READ
andREAD BY
- Data sets are read from the root and child entities.
The changes are saved with the statement COMMIT ENTITIES
, and, thus, the changed data is persisted to the database tables. All changes to the persistent table are managed by the RAP framework.
Executable Example
The example MODIFY
: Standard Operations (Managed) explains the example displayed above in detail.