Get Example source ABAP code based on a different SAP table
ABAP_RAP - Factory Action This example demonstrates how factory actions are defined, implemented, and consumed in a managed RAP BO. Data model> The CDS data model consists of a single root entity DEMO_RAP_FACTORY_ACTION>: DDLS DEMO_RAP_FACTORY_ACTION Behavior definition> The RAP behavior definition> DEMO_RAP_FACTORY_ACTION>> is defined in RAP BDL> as follows: BDEF DEMO_RAP_FACTORY_ACTION Action definition> Two factory actions are defined:
The instance factory action copy_instance> copies all values of the requested entity instance and assigns a new key value.
The static factory action new_instance> creates new entity instances with default values. 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_RAP_FACTORY_ACTION>>. This global class implements the local handler class LHC_DEMO_RAP_FACTORY_ACTION>, which contains two methods, copy_instance> and new_instance> , to implement the factory actions. The actual implementation takes place in the BP_DEMO_RAP_FACTORY_ACTION====CCIMP>>: copy_instance>: METH BP_DEMO_RAP_FACTORY_ACTION(CCIMP)=>COPY_INSTANCE new_instance>: METH BP_DEMO_RAP_FACTORY_ACTION(CCIMP)=>NEW_INSTANCE
ABAP_SOURCE_CODE DEMO CL_DEMO_RAP_FACTORY_ACTION
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 entity instances are created with the statement MODIFY ENTITY>.
The action copy_instance> is executed on one of the two instances with the statement EXECUTE> and the changes that were performed by the action in the transactional buffer are committed to the database with the statement COMMIT ENTITIES>.
The action new_instance> is executed with the statement EXECUTE> and 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_DBTAB_ROOT>. As a result, two new entity instances are created: one is a duplicate of the entity instance with key value '1', but is has a new key value. One is created with default values.