Users want a 'Create from template' button on the list report. It should open a dialog for the customer and the dates, create a travel with preset values, and open it. How do you build that in RAP?
Say your answer out loud first.
Practise another way
I define a static factory action with an input parameter typed by an abstract entity, for example static factory action createFromTemplate parameter ZA_TravelTemplate [1].
In the handler I create the travel with EML in local mode, reuse the action's %cid, and return the new key in MAPPED. I add the action to the line item annotation as FOR_ACTION. If it should replace the standard Create, I mark it default.
Why a static factory action. Factory actions create instances. Instance-bound ones copy an existing instance; static ones need no instance and create one with prefilled values. A list report button with no selection fits the static kind.
Abstract entity for the dialog
@EndUserText.label: 'Travel template'
define abstract entity ZA_TravelTemplate
{
CustomerID : /dmo/customer_id;
BeginDate : /dmo/begin_date;
EndDate : /dmo/end_date;
}
BDEF
static factory action createFromTemplate parameter ZA_TravelTemplate [1];
The cardinality is mandatory, and output parameters are not allowed. Exactly one static factory action per entity may be marked default (static default factory action ...). Consuming frameworks such as OData use the default factory action as the standard action in certain scenarios.
Handler
METHOD createFromTemplate.
MODIFY ENTITIES OF zr_travel IN LOCAL MODE
ENTITY Travel
CREATE FIELDS ( CustomerID BeginDate EndDate OverallStatus )
WITH VALUE #( FOR k IN keys ( %cid = k-%cid
%is_draft = k-%param-%is_draft
CustomerID = k-%param-CustomerID
BeginDate = k-%param-BeginDate
EndDate = k-%param-EndDate
OverallStatus = 'O' ) )
MAPPED mapped FAILED failed REPORTED reported.
ENDMETHOD.
In a draft-enabled BO, %is_draft from %param makes the new instance a draft, as SAP's RAP110 exercise does. Without it, the action creates an active instance and skips the draft. Reusing the action's %cid for the create links the new instance to the request.
For each %cid, RAP adds the created instances to mapped or the failure to failed. The new key in mapped is what a client needs to open the new object.
Exposure
- Projection BDEF:
use action createFromTemplate; - Metadata extension:
@UI.lineItem: [{ type: #FOR_ACTION, dataAction: 'createFromTemplate', label: 'Create from Template' }], as SAP's flight sample does for its actions. - A
{ default function GetDefaultsForTemplate; }addition can prefill the dialog from code.
Release notes. Static default factory actions appeared with ABAP Platform 2023 (release 7.58) and SAP BTP ABAP environment 2211.
Instance-bound factory actions for managed BOs and result multiplicity ([0..*], [1..*]) came in earlier and later releases; check the release news for your system.
Chooses a static factory action with an abstract-entity parameter, creates with the action's %cid and returns MAPPED, and exposes it with FOR_ACTION and optionally default.
Builds a normal instance action that needs a selected row, or creates the travel with SQL INSERT in the handler.
Writing an instance action for a create use case. It needs a selected row, cannot return new keys in MAPPED, and Fiori cannot navigate to the new object.
- How does an instance-bound factory action like copyTravel differ in its keys and its %cid?
- How do you prefill the dialog values from the user's last travel?
- What changes if the template should create bookings too?
5 official pages and 2 prep guides. Confidence: medium. Checked 3 Dec 2026.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.