Static Default Factory Action in RAP
Learn how to use a static default factory action in ABAP RAP to replace the standard create with a custom action popup and parameters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"Step 1 – Define static default factory action in R_* BDEF
define behavior for ZR_ROOT alias ROOT
{
create;
update;
delete;
static default factory action createCustomer parameter ZD_CustomerData [1];
}
"Here, createCustomer will be triggered instead of the standard create.
"Step 2 – Create abstract entity for action parameters
@EndUserText.label: 'Customer Data'
define abstract entity ZD_CustomerData
{
@EndUserText.label: 'Customer ID'
CustomerId : int4;
@EndUserText.label: 'First Name'
FirstName : abap.char(20);
@EndUserText.label: 'Last Name'
LastName : abap.char(20);
}
"This entity defines the parameters passed to the static action.
"Step 3 – Implement custom logic in the action handler
METHOD createCustomer.
CHECK keys IS NOT INITIAL.
MODIFY ENTITIES OF ZR_Root IN LOCAL MODE
ENTITY Root
CREATE FIELDS ( id Fname Lname Age )
WITH VALUE #(
FOR key IN keys (
%cid = key-%cid
%is_draft = key-%param-%is_draft
Id = key-%param-CustomerId
Fname = key-%param-FirstName
Lname = key-%param-LastName
Age = 25
)
)
MAPPED mapped
FAILED failed
REPORTED reported.
ENDMETHOD.
"Here, the incoming parameters are mapped to the entity fields before creation.
"Step 4 – Expose the action in ZC_* (projection) BDEF
define behavior for ZC_Root alias Root
{
use create;
use update;
use delete;
use action createCustomer;
}
"This makes the action available in the projection layer.
"Result
"When the Create button is clicked in the SAP Fiori Elements UI:
"The createCustomer static default factory action is triggered automatically.
"Custom parameter handling and default value logic are executed before entity creation.
"The standard create operation is bypassed (even if enabled).
This post is licensed under CC BY 4.0 by the author.