SAP BDL BEHAVIOR EXT ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_RAP - Behavior Extension
This example demonstrates how the behavior of a RAP BO is extended by means of a BDEF extension.

Original RAP BO
Data model
The CDS data model consists of one root node without child entities:
DDLS DEMO_RAP_BEH_EXT
CDS transactional interface
The following CDS transactional interface is created for the root node to fulfill the RAP BO contract requirements for RAP extensibility.
DDLS DEMO_RAP_BEH_EXT_INT
Behavior definition
The RAP behavior definition DEMO_RAP_BEH_EXT is defined in RAP BDL as shown below. It defines implementation-relevant components and extension points.
BDEF DEMO_RAP_BEH_EXT
Behavior implementation
One ABAP behavior pool (ABP) is created for the RAP behavior definition. The global class of the behavior pool is BP_DEMO_RAP_BEH_EXT, see BP_DEMO_RAP_BEH_EXT===========CCIMP . This global class implements the following methods:
get_instance_features: Instance feature control for the standard operation update. If the value of field int_field1 is greater than 50, updates are not allowed. If the value is less than or equal to 50, updates are allowed.
get_global_authorizations: Global authorization control defines that create, update, and delete are always allowed.
Limit: Validation that checks the value of field int_field2 . If the value is more than 500, the validation fails and the entity instance is not saved.
Interface BDEF
The following interface BDEF DEMO_RAP_BEH_EXT_INT is required as stable interface for extensions.
BDEF DEMO_RAP_BEH_EXT_INT

Extension RAP BO
Data model extension
A child node is added to the RAP BO:
DDLS DEMO_RAP_BEH_EXT_CHILD
CDS transactional interface
A CDS transactional interface is created for the child node to fulfill the RAP BO contract requirements for RAP extensibility.
DDLS DEMO_RAP_BEH_EXT_INT_CH
Behavior extension
The BDEF extension DEMO_RAP_BEH_EXT_CH extends the root node and defines behavior for the extension child node.
BDEF DEMO_RAP_BEH_EXT_CH
ABP extension
The ABP extension is implemented in the global class BP_DEMO_RAP_BEH_EXT_CH, see BP_DEMO_RAP_BEH_EXT_CH========CCIMP . This global class implements the following methods:
Extension of the parent entity
get_global_features: Global feature control for the action setValue. This action can only be executed in the time period between 6 am and 10 pm (day shift).
get_global_authorizations: The original RAP BO defines global authorization control. RAP BO operations added via an extension require an own implementation of the global authorization control. This method generally allows execution of the method setValue. There are no access restrictions.
setValue: Action that sets field int_field2 to value 888.
Extension entity behavior definition for the child entity
get_global_authorizations: The original RAP BO defines global authorization control. For the action ActionExt, defined in the child node, a separate implementation of the authorization control method is required. The implementation generally allows execution of the method ActionExt. There are no access restrictions.
myDet: Determination on modify. Sets the value of field int_field1 to 777.
ActionExt: Action that updates field char_field1 for all requested entity instances.

ABAP_SOURCE_CODE
DEMO CL_DEMO_RAP_BEHAVIOR_EXTENSION

ABAP_DESCRIPTION
Access with ABAP using EML
The above source code uses ABAP EML to access the RAP business object from an ABAP class:
It inserts two parent entity instances and two child entity instances. Authorization is granted, the validation Limit is successful.
It updates the two parent entity instances Update requests are subject to instance feature control. This instance feature check fails for one entity instance. The update is successful only for one entity instance. For the failed entity instance, the error message is displayed. Authorization is granted.
It executes the action setValue. Authorization is granted, global feature control is successful.
It executes the action ActionExt. Authorization control for parent and child entities is successful.
The screen output includes a table that lists the execution order of handler methods of the ABAP behavior pool. This shows which methods in which order are executed when accessing the RAP BO.