Sap Rap Action
Sap Rap Action
RAP: ACTION
Action:
Actions are used to modify the BO without calling the standard operations (CRUD buttons).
Trigger points:
Syntax:
Trigger internally via eml: in order to trigger internally, like inside determination via eml.
Requirement:Toupdatethecountrycodebasedontheuserinput.
To achieve it, I have declared instance non-factory action with abstract entity as parameter, which
provides the country code from user. Since, it's an instance action, we would get the corresponding
keys of the selected BO(9e12812e-cf28-1fe0-81f6-be9f3d6f527b). We need to modify country
code(land1) via EML for the selected BO, with the input parameter from user. Additionally, it is
required to populate the result-derived type.
Action defined in BDEF:
Abstract entity for input parameter:
Note:
Declaredresultasself,astheparameterresulthasthesametypeastheentityforwhichthe
action is executed.
Youcanusedeepparameter(onlyodatav4),ifyouwanttomodifybothparentandchildentity.
Resultparameterisoptional,butifyouhavedeclaredinBDEFinterface,itsmandatorytopass
result in action method, else in ui, you will get blank value.
To achieve this, we can use a static non-factory action. First, we need to fetch details from the
persistence table for the BOs that have the country code set to 'IN'. To modify the country, use the
modify EML within a loop (use 'for' or 'loop at’) to modify all the BOs that satisfy the condition.
Action defined in BDEF:
2. Factory action:
Used to create a new Bo
Bound to the entire BO inside an entity
Instance factory action/copy action: Used to copy the existing Bo and replicate new Bo.
Static factory action: used to create BO with some default value.
Syntax:
2.1. Instance factory action(Copy action):
Requirement: To create vendor (BO) based on the selected vendor.
To achieve this, we can use an instance factory action. Fetch the data from the TX buffer to be
copied using the read EML statement, and create a new BO with a new key, while copying the
remaining fields from the reference BO. Since it’s a create operation, always pass %cid in the
mapped derived type.
To achieve this, we can use the modify EML with default values and pass %cid in the mapped
parameter, as shown below:
3. Saveaction
Save actions are triggered only in save sequence(finalize, adjust number).
A save(finalize) action can be called from the implementation of a RAP determination on save.
Even though its implemented in handler class, we cannot call it in interactive phase.
Use case:
Save action is used in situations where you require to achieve certain functionality without modify a
transactional buffer.