ABAP for Cloud Development
AS ABAP Release 914, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP RAP Business Objects → RAP - Behavior Definitions → RAP - BDL for Behavior Definitions → RAP - Managed and Unmanaged Behavior Definitions → RAP - EntityBehaviorDefinition → RAP - EntityBehaviorBody → RAP - RAP BO Operations → RAP - Non-Standard Operations → RAP - action →
RAP - action, factory
Syntax
internalstatic default factory action
(
features: instance global
precheck
authorization:none
authorization:update
authorization:global
authorization:instance
lock:none
)
ActionName external 'ExternalName'
InputParameter
[cardinality]
{default function GetDefaultsForActName external 'GetDefaultsForExtName' ;}
Description
Factory actions are used to create RAP BO entity instances. Factory actions can be instance-bound or static. Instance-bound factory actions can copy specific values of an instance. Static factory actions can be used to create instances with prefilled default values. Factory actions may also create child entity instances.
For factory actions, the same rules apply as for non-factory actions with the following differences:
- Output parameters
OutputParameter
are not allowed. A factory action always creates one or more new BO entity instances of the RAP BO entity for which it is declared. Therefore, it is not necessary to specify the result in the BDL. - It is mandatory to specify a cardinality. The cardinality can be one of the following values:
[1]
: Exactly one entity instance is created.[0..1]
: None or exactly one entity instance is created.[0..*]
: None or any number of instances are created.[1..*]
: Any number of instances is created, but at least one.
For each unique BDEF derived type %cid
(for static factory actions) or %key
(for instance-bound factory actions) passed to the action, the number of newly created instances (none, one, or multiple) are added to the response parameter MAPPED
(success) or FAILED
.
Exactly one static factory action can be defined as default factory action using the syntax addition default. This definition of default factory actions has an effect on consuming frameworks, such as OData. For further details, see topic RAP - Default Factory Action.
Availability
- Managed RAP BO
- Unmanaged RAP BO
- In a projection BO, factory actions from the base BDEF can be reused. For details on reuse, see topic RAP -
use
, Projection and Interface BDEF. It is also possible to specify new factory actions as described in topic RAP BDL - actions and functions, projection BDEF. - In a RAP BO interface, factory actions from the base BDEF can be reused. For details on reuse, see topic RAP -
use
, Projection and Interface BDEF.
Hint
For factory actions, the optional addition AUTO FILL CID
can be used to automatically fill the BDEF derived type component %cid
.
Example
The following example shows a managed BDEF which defines two factory actions:
copy_instance
: All values of the requested entity instance are copied and a new key value is assigned.new_instance
: A new entity instance is created with default values.
managed implementation in class bp_demo_rap_factory_action unique;
strict(2);
define behavior for demo_rap_factory_action
persistent table demo_dbtab_root
lock master
authorization master ( instance )
{
create;
update;
delete;
field(readonly:update) key_field;
// copy instance, assign new unique key value
factory action copy_instance [1];
// create new instance with default values
static factory action new_instance [1];
}
The actions are implemented in behavior pool BP_DEMO_RAP_FACTORY_ACTION
. The class CL_DEMO_RAP_FACTORY_ACTION
accesses the business object using EML and executes both actions.
Result: the entity instance with key field 1 is copied and a new entity instance with default values is created.
Executable Example
The example above is explained in detail in the executable example RAP BDL - factory action.