SAP BDL AUGMENT ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_RAP - Operation Augmentation
This example demonstrates how to define and implement the operation augmentation in a RAP projection business object.
ABAP_NOTE This example does not fully meet the requirements of the RAP BO contract. It is intentionally kept short and simple and serves demonstration purposes only. See more information on the RAP BO contract in the Development guide for the ABAP RESTful Application Programming Model.
Base BDEF
The base BDEF is the managed RAP behavior definition DEMO_RAP_MANAGED_ASSOC_ROOT. It defines the behavior for two entities which are connected via a CDS composition relation.
BDEF DEMO_RAP_MANAGED_ASSOC_ROOT
Projection BDEF
The projection behavior definition is defined as shown below. It reuses the standard operations from the base BDEF and augments the create , update, and create-by-association operations.
BDEF DEMO_RAP_PROJ_AUGMENT
Behavior implementation
In the ABAP behavior pool, the operation augmentation is implemented in three methods: augment_create, augment_update, and augment_cba_child.
augment_create implements the following:
It augments an original base instance for the operation create. Whenever new instances are created, the value of field CharFieldRoot is set to A.
It augments the operation create by adding new instances. Whenever a create operation is performed, the augmentation adds an additional entity instance. The key value for this new entity instance is a random integer.
METH BP_DEMO_RAP_PROJ_AUGMENT(CCIMP)=>AUGMENT_CREATE
augment_update augments an original base instance for the operation update. Whenever an existing entity instance is updated, the value of field DecFieldRoot is set to 100.2.
METH BP_DEMO_RAP_PROJ_AUGMENT(CCIMP)=>AUGMENT_UPDATE
augment_cba_child implements the following:
It augments an original base instance for the operation create by association. Whenever new child instances are created via the parent entity, the value of field DataField is set to AAA.
It augments the operation create by association by adding new child instances. For each parent instance, an additional child instance with the key value 26 is added.
METH BP_DEMO_RAP_PROJ_AUGMENT(CCIMP)=>AUGMENT_CBA_CHILD
For the full implementation, see BP_DEMO_RAP_PROJ_AUGMENT======CCIMP.

ABAP_SOURCE_CODE
DEMO CL_DEMO_RAP_PROJ_AUGMENT

ABAP_DESCRIPTION
Access with ABAP using EML
The above source code uses EML to access the RAP business object from an ABAP class:
It creates two parent entity instances. The operation augmentation automatically adds the value A for field CharFieldRoot for each entity instance. Moreover, for each created entity instance, another entity instance is added by the operation augment with a random integer as key value.
It updates one of the entity instances. The operation augmentation automatically adds the value 100.2 for field DecFieldRoot for all updated entity instances.
It creates a child entity instance for each parent entity instance via a create-by-association operation. The operation augmentation automatically adds the value AAA for field DataFieldRoot for each newly created child entity instance. Moreover, it adds an additional child entity instance for each parent entity instance with the child entity key 26.