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 - RAP BO Operation, Additions →
RAP - default function
Description
RAP BO operation addition that defines a RAP default values function for a RAP BO operation. A default values function defaults field values or input parameters for a RAP BO operation on the user interface. An implementation in the RAP handler method FOR READ ... FOR FUNCTION ...
is required. default function
can be used for the standard operation create
, the create-by-association operation, actions, and functions.
The name DefaultValuesFunctionName
and the optional external name GetDefaultsForExtName
of the default values function must start with GetDefaultsFor
. The name of the default values function must be unique within the current BDEF. The external name does not have to be unique. If specified, it is exposed in the OData metadata.
Default values functions are defined by adding the keywords {default function GetDefaultsForOperation;}
behind the respective operation and parameter definition.
Special rules apply to this addition for each operation:
- A dedicated name after
default function
is optional. If specified, the name must beGetDefaultsForCreate
. - An external name
GetDefaultsForExtName
is not possible. - A syntax diagram is available in the topic RAP - Standard Operations.
default function
must be specified in combination withcreate
within curly brackets.- An external name
GetDefaultsForExtName
is possible. - A syntax diagram is available in the topic RAP - Operations for Associations.
- The default values function can default values for the input parameter for the action. As a prerequisite, the action must specify an input parameter
InputParameter
. Flat, deep, and deep table parameters are supported. - An external name
GetDefaultsForExtName
is possible. - A syntax diagram is available in the topic RAP -
action
.
- The default values function can default values for the input parameter for the function. As a prerequisite, the function must specify an input parameter
InputParameter
. Flat, deep, and deep table parameters are supported. - An external name
GetDefaultsForExtName
is possible. - A syntax diagram is available in the topic RAP -
function
.
Availability
- Managed RAP BO
- Unmanaged RAP BO
- In a projection BO, default values functions can be defined for actions and functions defined in the projection layer. See the topic RAP -
action
, Projection BDEF for details. - In a projection BO, default values functions can be reused with the addition
use
. The operation in question and the default values function must be reused separately. For details, see the topic RAP -use DefaultValuesFunction
. - In a RAP BO interface, default values functions can be reused with the addition
use
. The operation in question and the default values function must be reused separately. For details, see the topic RAP -use DefaultValuesFunction
.
Hints
- The defaulting of values takes place in an OData service only. When accessing an operation that has a default values function attached using ABAP EML, the default values function is not accessed and no default values are provided.
- The RAP default values function can be triggered in ABAP EML like other RAP functions, using the
READ ENTITIES ... EXECUTE
statement.
Further Information
- Development guide for the ABAP RESTful Application Programming Model, section Operation Defaulting.
- Topic Handler Methods for RAP Default Values Functions.
Example
The following managed BDEF defines a default values function for the operations create, create-by-association, the RAP action InstanceAction
, and the RAP function StaticFunction
.
managed implementation in class bp_demo_rap_default_values_fun unique;
strict ( 2 );
define behavior for DEMO_RAP_DEFAULT_VALUES_FUNC alias Root
persistent table demo_dbtab_root
lock master
authorization master ( instance )
{
//Default values function for create
create { default function GetDefaultsForCreate; }
update;
delete;
field ( readonly : update ) key_field;
//Default values function for create-by-association
association _to_child
{ create { default function GetDefaultsForChild; } }
//Default values function for action
action InstanceAction parameter demo_cds_abstract_entity
{ default function GetDefaultsForAction; }
//Default values function for static function
static function StaticFunction parameter demo_cds_abstract_entity
result [0..*] $self
{ default function GetDefaultsForStaticFunction; }
}
define behavior for DEMO_RAP_DEFAULT_VALUES_CHLD alias Child
persistent table demo_dbtab_child
lock dependent by _to_parent
authorization dependent by _to_parent
{
update;
delete;
field ( readonly ) key_field;
field ( readonly : update ) key_field_child;
association _to_parent;
}
The default values function for the operation create is implemented in the ABAP behavior pool BP_DEMO_RAP_DEFAULT_VALUES_FUN
. The RAP handler method GetDefaultsForCreate
provides default values for the fields char_field
and lchg_date_time
.
METHOD GetDefaultsForCreate.
LOOP AT df_create ASSIGNING FIELD-SYMBOL(<df_create>).
INSERT INITIAL LINE INTO TABLE df_create_result
ASSIGNING FIELD-SYMBOL(<df_create_result>).
GET TIME STAMP FIELD DATA(lv_timestamp).
<df_create_result> = VALUE #(
%cid = <df_create>-%cid
%param = VALUE
#( char_field = 'Default Value'
lchg_date_time = lv_timestamp ) ).
ENDLOOP.
ENDMETHOD.
The effect is that in an OData service, when creating a new entity instance, the fields char_field
and lchg_date_time
are filled with default values.