Get Example source ABAP code based on a different SAP table
ABAP_RAP - Action with Input Parameter This example demonstrates how a RAP action> with input parameter is defined, implemented, and consumed in a managed RAP BO. Data model> The CDS data model consists of only one root entity DEMO_CDS_ACTION_INPUT_PARAM>. The root entity represents a purchase order item. DDLS DEMO_CDS_ACTION_INPUT_PARAM Behavior definition> The RAP behavior definition> DEMO_CDS_ACTION_INPUT_PARAM>> is defined in RAP BDL> as follows: BDEF DEMO_CDS_ACTION_INPUT_PARAM Action definition> The behavior definition defines one action: deductDiscount>. The action has one input parameter that is typed with the CDS abstract entity DEMO_CDS_ABSTRACT_DISCOUNT> and it defines the output parameter as the same type as the entity for which the action is executed. The purpose is to reduce the purchase order item price by the discount specified via the input parameter. action deductDiscount parameter DEMO_CDS_ABSTRACT_DISCOUNT result [1] $self;> The following CDS abstract entity> is used for typing the input parameter: DDLS DEMO_CDS_ABSTRACT_DISCOUNT 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_ACTION_INPUT_PARAM>>. This global class implements the local handler class LHC_DEMO_CDS_ACTION_INPUT_PARA>, which contains the method deductDiscount> to implement the action. This method is a FOR MODIFY> method and it is typed based on the PurchaseItem> entity. Its signature includes the result parameter. The actual implementation takes place in the BP_DEMO_CDS_ACTION_INPUT_PARAMCCIMP>>.
ABAP_SOURCE_CODE DEMO CL_DEMO_CDS_ACTION_REDUCE
ABAP_DESCRIPTION Access with ABAP using EML> The above source code uses EML> to access the RAP business object from an ABAP class:
The user is requested to enter the discount percentage.
Two BO instances are created with the statement MODIFY ENTITY>.
The action deductDiscount> 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 using the statement COMMIT ENTITIES RESPONSE OF>.
A SELECT> statement is used to read the changed data from the persistent table DEMO_PURCH_DOC_I>. As a result of the action, the price of a purchase order item is reduced by the percentage specified via the input parameter.