SAP BDL ACTION1 ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_RAP - Action
This example demonstrates how a RAP action is defined, implemented, and consumed in a managed RAP BO.
Data model
The CDS data model consists of the root entity DEMO_CDS_PURCH_DOC_M and its child entity DEMO_CDS_PURCH_DOC_I_M. The root entity represents a purchase order and the child entity represents a purchase order item.
Root entity:
DDLS DEMO_CDS_PURCH_DOC_M
Child entity:
DDLS DEMO_CDS_PURCH_DOC_I_M
Behavior definition
The RAP behavior definition DEMO_CDS_PURCH_DOC_M is defined in RAP BDL as follows:
BDEF DEMO_CDS_PURCH_DOC_M
Action definition
Two actions are defined: Approve_Order and Reject_Order. If an employee wants to order equipment, the employee creates a purchase order and the manager can approve or reject this purchase order. Both actions have the output parameter $self with cardinality 1, so the parameter result has the same type as the entity for which the action is executed. action Approve_Order result [1] $self; action Reject_Order result [1] $self;
Behavior implementation
For the above RAP behavior definition, one ABAP behavior pool (ABP) is created. The global class of the behavior pool is BP_DEMO_CDS_PURCH_DOC_M. This global class implements the local handler class LHC_PURCHASEDOCUMENT, which contains two methods, Approve_Order and Reject_Order , to implement the actions. The actual implementation takes place in the BP_DEMO_CDS_PURCH_DOC_M=======CCIMP and it works as follows:
For the passed entity instance, column Status is updated with A for Approved or R for Rejected, using the MODIFY ENTITIES statement.
A local structure lt_purchase is created and filled with the entity instance using the statement READ ENTITIES.
The output parameter result is filled. If an output parameter is defined, then it must always be filled.

ABAP_SOURCE_CODE
DEMO CL_DEMO_CDS_PURCHASE

ABAP_DESCRIPTION
Access with ABAP using EML
The above source code uses EML to access the RAP business object from an ABAP class:
Two BO instances are created with the statement MODIFY ENTITY.
The action Approve_Order is executed on one of the two instances with the statement EXECUTE.
The result, failed, and reported parameters are returned.
The changes that were performed by the action in the transactional buffer are committed to the database with the statement COMMIT ENTITIES.
A SELECT statement is used to read the changed data from the persistent table DEMO_PURCH_DOC. As a result of the action, the column Status of the respective instance is filled with A for Accepted.