| Subject | Code Snippet | Notes |
|
Field-specific characteristics
|
field ( readonly ) field_a, field_b, field_c;
field ( readonly : create ) field_d;
field ( readonly : update ) field_e;
field ( mandatory ) field_f;
field ( mandatory : create ) field_g;
field ( mandatory : update ) field_h;
field ( suppress ) field_i;
field ( features : instance ) field_j;
|
- You can provide RAP BO fields with certain characteristics regarding access and provision.
- It is possible to combine certain characteristics (with restrictions identified by syntax checks) within parentheses (for example,
field ( mandatory : create, readonly : update) field_k;).
- The field characteristics are static. Only the
features : instance variant represents dynamic field characteristics.
- Typically, key fields are specified with
readonly or readonly : update.
- Notes on the specifications:
readonly: Values for the fields must not be created or updated by the RAP BO consumer (for example, key field values are provided solely by the RAP BO provider in internally managed numbering scenarios). By using readonly : create or ... update, you explicitly specify a field as readonly during create or update operations.
mandatory: Values for the fields must be provided before persisting the instance. By using mandatory : create or ... update, you explicitly specify a field as mandatory for create or update operations. In external numbering scenarios, a typical specification combination for key fields is mandatory : create and readonly : update.
suppress: Used to remove a field from BDEF derived types and all RAP APIs.
features : instance: Defines access restrictions for fields based on the RAP BO instance state. When specified, the restrictions must be implemented in the FOR INSTANCE FEATURES handler method. For example, you might want to ensure that a field is mandatory or readonly when a RAP BO instance has a specific state (for example, when a field has a certain value).
|
|
Managed internal numbering
|
field ( numbering : managed ) key_field;
|
- Defines managed internal numbering for a RAP BO key field.
- This specification applies only to managed RAP BOs.
- When creating instances, the framework automatically assigns unique values to the specified fields. These fields must be the primary key in the underlying CDS data model and have a 16-character byte-like type to hold UUID values.
- Typically, the key fields are specified as
readonly to prevent RAP BO consumers from passing key values, enabling a full internal numbering scenario. However, there are cases where you may choose not to use the readonly characteristic, allowing RAP BO consumers to provide values for the key fields. This optional external numbering use case means the framework supplies values only if the consumer provides initial values.
- For custom numbering, the
early numbering specification is required, which requires implementing the numbering in a RAP handler method.
|
|
Standard operations (CUD operations)
|
create;
update;
delete;
//Multiple additions are available (but the operation itself can
//only be specified once). Combinations are possible. Examples:
internal create;
create ( features : global, precheck, authorization : none );
create { default function GetDefaultsForCreate; }
update ( features : instance );
delete ( authorization : update );
|
- Specifying CUD operations is optional. If you do not specify
update, you cannot perform update operations for RAP BO instances.
- In a managed RAP BO, these operations (along with read operations) are automatically handled, requiring no custom implementation. This differs from unmanaged RAP BOs, where you must implement the entire logic in dedicated RAP handler methods.
- Various additions can be specified (unless stated otherwise, these additions apply to all CUD operations):
internal: Defines operations as internal.
features : instance: Enables dynamic feature control for update or delete (not create).
features : global: Enables global feature control.
precheck: Enables precheck.
authorization : none: Excludes operations from authorization checks.
authorization : update: Delegates authorization control to the update operation's authorization check implementation. This applies only to delete operations.
{default function ...}: Defines a RAP default values function for the create operation only, which sets default field values on the user interface.
[!NOTE]
- The read operation is always implicitly enabled for each entity listed in a BDEF and cannot be explicitly declared (there is no
read syntax).
- Delete operations on RAP BO instances of the parent entity in managed RAP BOs also delete associated child entity instances that are in a composition relationship.
|
|
Actions as non-standard operations
|
action act1;
internal action act2;
static action act3;
repeatable action act4;
action ( features : global ) act5;
action ( features : instance ) act6;
action ( precheck ) act7;
action ( authorization : global ) act8;
action ( authorization : instance ) act9;
action ( authorization : update ) act10;
action ( authorization : none ) act11;
action ( lock : none ) act12;
action act13 parameter SOME_ENTITY;
action act14 parameter SOME_ENTITY result [1] $self;
action act15 deep table parameter SOME_ENTITY;
action act16 deep result selective [1] SOME_ENTITY;
action act17 external 'SomeName';
action act18 {default function SomeFuncName;}
factory action act19 [1];
default factory action act20 [1];
save(...) action act21;
[!NOTE]
- Different kinds and flavors of actions can be specified, and numerous syntax additions are available. The code snippet shows a selection only.
- Combinations are possible. Make sure that you get the complete picture in the ABAP Keyword Documentation as not all options are listed in the ABAP cheat sheet.
|
- Actions are self-implemented in dedicated handler methods and represent non-standard operations for modifying RAP BO instance data.
- Notes on syntax options:
- When neither the
factory nor save specifications are used (as in act1), the action is categorized as non-factory, meaning its primary purpose is to modify rather than create instances.
static: Defines a static action not bound to any RAP BO instance but related to the entire RAP BO entity.
repeatable: Defines a repeatable, non-factory action that can execute multiple times on the same RAP BO instance within one request.
internal: Restricts access to the action to within the business object implementation.
external: Allows specification of an alias name for external use.
lock : none: Prevents locking on the RAP BO instance.
features : instance: Enables dynamic feature control for actions, allowing the action to be available only if certain preconditions regarding the instance state are met.
features : global: Enables global feature control for actions, allowing availability only if specific global, RAP BO-external preconditions are met.
precheck: Enables a precheck for actions to prevent unwanted changes from reaching the transactional buffer.
authorization : none: Excludes authorization checks.
authorization : update: Delegates authorization control to the check implemented for the update operation.
authorization : global: Replaces the specified authorization control in the authorization master entity with global authorization checks.
authorization : instance: Replaces the specified authorization control in the authorization master entity with instance authorization checks.
... parameter ...:
- Defines an input parameter for actions.
- The input parameter can be flat or deep (using the specifications
deep and deep table).
- For flat parameters,
SOME_ENTITY represents a CDS abstract entity or a DDIC type.
- For deep parameters (structures or tables),
SOME_ENTITY represents an abstract BDEF defined with with hierarchy.
... result ...:
- Defines an output parameter for actions.
- Used to store the result. When specified, the handler method in the ABP includes the
RESULT addition in the signature.
- There are several syntax options after
result, including:
selective: Returns only parts of the result, such as just the keys. When used, the corresponding handler method includes the input parameter REQUEST ... to mark the desired fields.
[...]: Defines the cardinality of the output parameter. Examples: [0..1], [1], [0..*], [1..*].
$self: Indicates that the result type matches the entity type.
entity some_entity: Specifies that the result type corresponds to another CDS view entity.
default function: Defines a RAP default values function for the action, which defaults input parameter values. As a prerequisite, the action must specify an input parameter.
factory: Defines a factory action
- Used to create RAP BO instances (including child entities).
- Can be either instance-bound (for copying specific field values from an instance) or static (for creating instances with predefined default values).
- Output parameters are not permitted here.
- Cardinality specifications:
[1] (creates exactly one entity instance), [0..1] (creates none or exactly one entity instance), [0..*] (creates none or any number of instances), [1..*] (creates any number of instances, but at least one).
- Besides
internal and static, factory actions can be specified with static default factory .... This addition is evaluated by consuming frameworks, such as OData, which use the default factory action as the standard action in certain scenarios.
save( ... ):
- Defines save actions callable only during specific RAP saver methods.
- The parentheses can include
finalize and/or adjustnumbers.
|
|
Functions as non-standard operations
|
function func1 result [0..*] $self;
static function func2 result [1] SOME_ENTITY;
function func3 parameter SOME_ENTITY result [1] $self;
[!NOTE]
- Different kinds and flavors of functions can be specified, and numerous syntax additions are available. The code snippet shows a selection only.
- Combinations are possible. Make sure that you get the complete picture in the ABAP Keyword Documentation as not all options are listed.
|
- Functions are self-implemented in dedicated handler methods, designed for non-standard operations that return information, such as calculations or read operations, without locking or modifying data.
- You can also define static, internal, repeatable, and default functions, specify external names and input parameters.
- It is possible to define RAP key functions, which accept values of an alternative key as input and return matching entity instances. These functions are commonly used in cross-BO association contexts. Find more information here.
- Specifying an output parameter is mandatory. Refer to the actions section for details on specification options, including cardinality.
|
|
Operations for associations
|
association _Assoc;
association _Assoc { create; }
association _Assoc
{
create;
link action some_link_action;
unlink action some_unlink_action;
inverse function some_inv_func;
}
[!NOTE]
Numerous syntax options are available in that context. Find more information here.
|
- The syntax allows operations along association paths and impacts association targets. You can enable both standard operations (such as create-by-association and read-by-association) and non-standard operations (such as link and unlink actions or inverse functions) for associations.
- As a prerequisite, you must define behavior for the association target using
define behavior ....
- Read-by-association operations are automatically enabled when you specify the association, for example, using
association _Assoc;.
- The statement
association _Assoc { create; } enables create-by-association as well as read-by-association operations. Note that create can be enhanced with additional specifications, such as precheck, feature control, authorization, and more. Find more information here.
- The supported non-standard operations for associations include:
- Link action: Associates RAP BO instances with other instances using foreign key settings.
- Unlink action: Disconnects two associated RAP BO instances by removing the value of the foreign key field.
- Inverse Function: Receives the values of the foreign key fields from the association target instances as input and provides the corresponding association source instances as output. Explicit output parameters are optional.
|
|
Draft actions
|
draft action Activate optimized;
draft action Discard;
draft action Edit;
draft action Resume;
draft determine action Prepare;
draft determine action Prepare
{ determination ...;
validation ...; }
|
- Draft actions, available only for draft-enabled RAP BOs, manage the state of draft and active instances during their lifecycle.
- The implementation is implicitly provided, requiring no additional implementation in the ABP. However, the draft actions
activate, discard, edit, and resume support the optional addition with additional implementation. When specified, you can add a custom implementation for the respective FOR MODIFY ... ACTION method in the ABP.
- Notes on the draft actions:
Edit: Copies an active instance to the draft database table.
Activate: Transfers the content of the draft database table to the persistent database table and clears the draft table. This method call implicitly executes the draft determination action Prepare. For better performance, it is advisable to use the optional addition optimized, which reduces the number of determinations and validations executed.
Discard: Deletes draft instances from the draft database table.
Resume: Is automatically executed whenever a draft instance, whose exclusive lock has expired, is modified. It re-establishes the lock for the corresponding entity instance in the active database table.
draft determine action Prepare: Executes the determinations and validations (only those specified with on save) assigned to it in the behavior definition. draft determine action Prepare; denotes that it is possible not to define any determinations or validations.
- Find more information here.
|
|
Validations
|
validation val1 on save { create; update; }
validation val2 on save { delete; }
validation val3 on save { field some_field; }
validation val4 on save { delete; field some_field; }
|
- Validations check the consistency of RAP BO instances based on trigger conditions. A called validation can reject inconsistent instance data from being saved and return messages (via failed and reported entries) to the RAP BO consumer.
- They are automatically called during the save sequence (indicated by the addition of
on save) when trigger conditions are met.
- Trigger conditions may include modification operations (create, update - only in conjunction with create -, delete) or specific field modifications (that is, when particular field values change during create and update operations). If multiple trigger conditions are specified, the evaluation occurs if at least one condition is met.
- Validations are implemented in the
FOR VALIDATE RAP handler method.
- When inconsistent RAP BO instance data is rejected, the entire transactional buffer is rejected, including instances without inconsistencies. This "all or nothing" approach ensures that a final commit to the database occurs only if all data is consistent. Therefore, inconsistencies must be resolved, or the transactional buffer must be rolled back.
|
|
Determinations
|
determination det1 on save { create; }
determination det2 on save { delete; }
determination det3 on save { field some_field; }
determination det4 on modify { create; }
determination det5 on modify { field some_field; }
|
- Determinations are used to modify RAP BO instances based on trigger conditions. A determination can be used for calculations and data modifications.
- They are automatically triggered when conditions are met.
- Trigger conditions include modify operations (create, update - only together with create in case of
on save -, and delete) or specific field modifications (that is, when specific field values change during create and update operations). If multiple trigger conditions are specified, the determination is executed if at least one condition is satisfied.
- There are two types of determinations based on the program flow stage:
on modify: Is executed immediately after data changes occur in the transactional buffer, making the result available during the transaction.
on save: Is executed at the end of a transaction during the save sequence when changes from the transactional buffer are persisted to the database.
- Determinations are implemented in
FOR DETERMINE RAP handler methods.
- Note that the execution order of multiple specified determinations is arbitrary.
|
|
Determine actions
|
determine action det_act
{
determination det1;
determination ( always ) det2;
validation val;
}
|
- Determine actions execute assigned determinations and validations on request.
- Only
on save determinations and validations can be assigned. on modify determinations cannot be assigned.
- By default, assigned determinations and validations are only executed if trigger conditions are met. You can use the
always addition to ensure they are executed regardless of trigger conditions.
- Execution order: First determinations, then validations. The order among determinations and validations is independent of the specification order.
- After
determine action, you can specify authorization-specific additions (such as authorization : none).
- Note that the draft determine action
Prepare corresponds to these determine actions.
|
|
RAP business events
|
event evt1;
event evt2 parameter SOME_ENTITY;
event evt3 deep parameter SOME_ENTITY;
managed event evt4 on evt1 parameter SOME_ENTITY;
event evt5 for side effects;
|
- A RAP business event typically represents information about the outcome of a CUD operation.
- RAP business events enable asynchronous communication between an event provider and an event consumer. An event consumer that subscribes to events can receive and process them. The information passed, known as the event payload, always includes the instance key and, if necessary, additional details.
- To pass information, you can define an optional input parameter
parameter .... SOME_ENTITY refers to a CDS abstract entity. The syntax deep parameter ... is also available, requiring SOME_ENTITY to be an abstract BDEF specified with with hierarchy.
- RAP business events are typically triggered in ABPs during the RAP late save, using the ABAP EML statement
RAISE ENTITY EVENT. For managed RAP BOs, it is advisable to define the BO with with additional save and raise business events in the save_modified method.
- Special types of RAP business events:
- RAP derived events (
managed event): These events are defined in relation to an existing RAP business event, allowing for a redefined payload. They are automatically raised when the referenced event is triggered.
- RAP business events for side effects (
... for side effects): These events are used solely for an RAP event-driven side effect, meaning a RAP side effect is initiated by this business event.
- Note that once a RAP business event is created and raised, you must define an event binding to map the event to an event type.
|
|
RAP side effects
|
side effects {
// Side effect with single source property
field a affects field b;
$self affects field y;
// Side effect with multiple source properties and trigger action
determine action someDetermineAction
// trigger field group
executed on field c,
field d,
field _Assoc.e
affects field f;
// Side effect that triggers the reload of feature control
field g affects permissions(field h);
// Side effect on an action with operation control and messages
action act1 affects field *,
permissions(action act2),
messages;
// Side effect for refreshing data of an entity
action act3 affects field i, entity _Assoc;
event evt affects field j;
}
|
- RAP side effects define interdependencies among RAP BO properties that trigger a reload of affected properties in the user interface.
- No custom implementations are required.
- Multiple side effects can be summarized within curly brackets, separated by semicolons (
;).
- Notes on selected trigger properties:
field ... affects: When the defined field changes on the user interface, the side effect is triggered, and the specified targets are reloaded.
$self affects: When the current RAP BO entity undergoes a CUD operation, the side effect is triggered, and the specified targets are reloaded. Note that the targets may include fields from associated entities but cannot include fields from the current entity.
action ... affects: When the action is executed on the user interface, the side effect is triggered, and the specified targets are reloaded.
determine action ...: Defines a side effect that triggers a determine action. When any defined source following executed on changes, the determine action is executed, and the specified targets are reloaded.
event: Defines a business event for side effects. When the defined event occurs, a side effect is triggered, and the specified targets are reloaded.
- Regarding the targets (
affects ...):
field: The specified field is reloaded when a side effect is triggered. One or more fields can be indicated. field * means all fields of the same instance are reloaded. Fields from other entities can be accessed via the association path (_Assoc.e).
entity: Triggers a determine action when anything in the specified entity changes.
permissions: Reloads feature and authorization control. Syntax options include fields (permissions(field a)), actions (permissions(action act)), standard operations (permissions(create)), and all previously mentioned for associated entities (e.g., permissions(_Assoc.e) or permissions(create _Assoc)).
$self: Reloads the own entity.
entity: Reloads the specified entity. Grouping options are available, such as ... entity (_Assoc1, _Assoc2) ... and ... entity _Assoc1.(_ItemAssoc1, _ItemAssoc2) ....
message: Reloads all reported messages.
|
|
Type Mapping
|
mapping for demo_dbtab_root
{
KeyFieldRoot = key_field;
DataFieldRoot = data_field;
CharFieldRoot = char_field;
DecFieldRoot = dec_field;
}
|
mapping for maps data types defined in CDS for a RAP business object to non-matching types. For example, it is used in behavior definitions to connect database field names to CDS element names.
- If the field names in the DDIC structure and the current data model are identical, no mapping is needed. Otherwise, it is mandatory and will trigger a syntax check warning. In particular, for a managed RAP BO, the field names in the RAP persistent table must align with the corresponding RAP BO entity names. If they do not match, a type mapping is necessary to avoid a syntax check warning.
- Syntax variants are available including
control and corresponding. Find more information here.
|