CRUD isn't the whole business
Create, update, delete — the standard operations cover data maintenance. But real business processes need more: approve an order, release a document, copy last month's plan, cancel with a reason code.
That's what RAP actions are for: named business operations with their own logic, exposed as buttons in the Fiori UI and callable through EML.
The three flavors of actions
Instance-bound actions operate on existing objects — approve, reject, release. The user selects rows, clicks the button, your logic runs.
Static actions don't need an instance — think "create from template" on the list report toolbar, operating without a selected row.
Factory actions create new instances — "copy order" or "create follow-up document." They're static actions with a result: new business objects.
Choosing the flavor is a UX decision first: does the user act on something selected, from the list, or to create something new?
Step 1: Declare the action in the BDEF
define behavior for ZI_SalesOrder_TP
{
action approveOrder result [1] $self;
action rejectOrder parameter ZI_RejectReason result [1] $self;
static factory action copyOrder [1];
}
The declaration says everything the UI needs: approveOrder returns the object itself ($self) so the UI can refresh it. rejectOrder takes a parameter — the UI will pop up a dialog for the reason. copyOrder is a factory action producing new instances.
Step 2: Implement it in the behavior pool
METHOD approveOrder.
MODIFY ENTITIES OF zi_salesorder_tp IN LOCAL MODE
ENTITY SalesOrder
UPDATE FIELDS ( Status )
WITH VALUE #( FOR key IN keys
( %tky = key-%tky
Status = 'APPROVED' ) )
FAILED DATA(failed)
REPORTED DATA(reported).
READ ENTITIES OF zi_salesorder_tp IN LOCAL MODE
ENTITY SalesOrder
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(orders).
result = VALUE #( FOR order IN orders
( %tky = order-%tky
%param = order ) ).
ENDMETHOD.
The shape is always the same: MODIFY ENTITIES to apply the change, READ ENTITIES to fetch the result, fill the result parameter so the caller gets fresh data. Learn this skeleton once and every action follows it.
Step 3: Expose it where it's used
Declaring isn't enough — the action must be enabled in the behavior projection (the interface layer your service exposes):
define behavior for ZC_SalesOrder_TP
{
use action approveOrder;
use action rejectOrder;
use action copyOrder;
}
Miss the use action and the button never appears — one of the most common "my action doesn't show up" causes. The projection is a whitelist, just like the BDEF.
Action design tips
- One action, one business meaning. "Approve" and "approve with special handling" should be two actions, not one action with a hidden flag.
- Validate inside actions. Check preconditions (status allows approval?) and report via
failed/reported— same as validations. - Use parameters for user input. A rejection reason, an effective date — parameters become Fiori dialogs automatically.
- Return
$selfwhen the UI should refresh the object after the action runs.
Actions are where your object stops being a data container and starts being a business process. Design them from the user's workflow, not from the database.
What's the most useful custom action you've built — approve, release, copy? Describe it in the comments.