Get Example source ABAP code based on a different SAP table
ABAP_RAP - Draft Actions Edit, Discard, Prepare This example demonstrates how the draft actions Edit>, Discard >, and Prepare> are defined, implemented, and consumed in a managed RAP BO. Data model> The CDS data model consists of the root entity DEMO_RAP_MANAGED_DRAFT_ACTIONS>: DDLS DEMO_RAP_MANAGED_DRAFT_ACTIONS Behavior definition> The RAP behavior definition> DEMO_RAP_MANAGED_DRAFT_ACTIONS>> is defined in RAP BDL> as shown below. It is draft-enabled and strict mode is switched on. Therefore, it is mandatory to explicitly declare all draft actions. The determination setCharField> is defined. It is executed on save whenever the field Timestamp> is modified. It is implemented in the ABAP behavior pool and it sets the value of the field CharFieldRoot> of the respective entity instance to 'A'. BDEF DEMO_RAP_MANAGED_DRAFT_ACTIONS 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_MANAGED_DRAFT_ACTI>>. This global class implements the local handler class LHC_PARENTENTITY>, which contains the method setCharField> to implement the determination. The actual implementation takes place in the BP_DEMO_RAP_MANAGED_DRAFT_ACTICCIMP>>. It sets the value of the field CharFieldRoot> of the respective entity instance to 'A'.
ABAP_DESCRIPTION Access with ABAP using EML> The above source code uses EML> to access the RAP business object from an ABAP class:
Two active BO instances are created with the statement MODIFY ENTITY >.
The draft action Edit> is executed on both instances with the statement EXECUTE>. No changes are made, the only effect of the draft action Edit> in this example is that the active instances are copied to the draft database table.
The draft action Prepare> is executed for the two draft instances that were copied from the persistent table to the draft table during the Edit>. The assigned determination setCharField> is executed and it inserts a value into field CharFieldRoot>.
The draft action Discard> is executed. It deletes both instances from the draft database table.
Using the AB-SQL SELECT> statement, the content of the draft and persistent tables are displayed. It can be seen that the draft action Edit> copies the active BO instances to the draft database table. The action Prepare> fills the field CharFieldRoot> of the draft database table. The draft action Discard> deletes the instances from the draft database table.