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 - Operations for Associations
Syntax
... internal association _Assoc
abbreviation newName
without response
{
internal create
(features:instance features:global
,precheck
,authorization:none
,authorization:update ;)
{default function GetDefaultsFor_Assoc external 'GetDefaultsForCBA' ;}
with draft ;
}
Description
Enables read-by-association and create-by-association operations for associations:
- Read-by-association allows RAP BO consumers read access to the association target of a RAP BO entity.
- Create-by-association allows RAP BO consumers creating new instances of the association target entity.
The following rules apply:
- The read-by-association and create-by-association operations can be defined for intra BO associations and for cross-BO associations.
- The association target entity must be behavior enabled, in other words, the association target entity must have its own behavior definition.
- In the case of intra-BO associations, it is mandatory to define at least read access to the associations to RAP BO entities that are also behavior-enabled.
The syntax for enabling read-access to an association target entity is as follows:
association _Assoc { }
Alternative spelling option: association _Assoc;
- This is allowed in both directions, from parent to child and vice versa. As this syntax enables only read access to an association target, the create-by-association is explicitly not allowed.
The syntax for enabling read access and create access to an association target entity is as follows:
association _Assoc { create; }
- Create-by-association is only available for to-child associations. It is not allowed for to-parent associations. In other words, child nodes can be created via their parent node, but parents cannot be created via their child nodes.
RAP BDL Operation Additions
The following RAP BDL operation additions are possible:
internal
: Can be used in two places:- in front of the association:
- Example:
internal association _Assoc;
- In this case, the complete association can only be accessed from its own business object implementation. This affects both read and create operations along CDS associations.
- in front of
create
within the curly brackets: - Example:
association _Assoc { internal create; }
- If only create is marked as internal, read access to the association target is allowed, but create-by-association operations are only allowed internally.
The following additions are only possible in combination with { create; }
and therefore, in case of a composition relationship, can only be declared for the parent entity.
Example: association _Assoc { create(addition);}
features:instance
: Enables dynamic feature control for the association in question.features:global
: Enables global feature control for the association in question.precheck
: Prevents illegal changes from reaching the application buffer by prechecking modify operations.authorization:none
: Excludes the association in question from authorization checks.authorization:update
: Delegates the authorization control to the authorization check that is implemented for the update operation.{default function GetDefaultsFor_Assoc
external 'GetDefaultsForCBA' ;}: Defines a RAP default values function for the create-by-association operation. The effect is that field values are defaulted on the user interface.
Restriction
In a managed RAP BO, create-by-association works only on direct child entities. Entities that are part of the same composition tree, but more than one level below the RAP BO root entity, can be read enabled, but not create enabled. In an unmanaged RAP BO, this limitation does not apply.
Availability
- Managed RAP BO: In a managed RAP BO, operations for associations are provided by the managed RAP BO provider.
- Unmanaged RAP BO: In an unmanaged RAP BO, operations for associations must be implemented in the ABAP behavior pool in the RAP handler method
FOR MODIFY
. - Projection BDEF: In a projection BDEF, operations for associations can be reused from the base BDEF. This can be done using the keyword
use
. For further details, see topic RAP -use
, Projection and Interface BDEF. - RAP BO interface: In a RAP BO interface, operations for associations can be reused from the base BDEF. This can be done using the keyword
use
. For further details, see topic RAP -use
, Projection and Interface BDEF.
Hints
- For create-by-association operations, the optional addition
AUTO FILL CID
can be used to automatically fill the BDEF derived type component%cid
.
Further Information
Development guide for the ABAP RESTful Application Programming Model, topic Create by Association Operation.
Addition 1
... abbreviation newName
Description
Defines an alternative name for an association. The abbreviation newName
can have a maximum of 16 characters. Associations are in the namespace of their root entity and can have up to 30 characters. This is under certain circumstances too long to be processed in ABAP RAP. Whenever a shorter name is required, you are prompted to assign an abbreviation to the association with no more that 16 characters. The abbreviation should start with a character, not with an underscore.
Addition 2
... without response
Description
The optional addition without response
is for cross-BO associations that have an association target from another BO. The association target entity of cross-BO associations is automatically included in the response types of the current RAP BO as foreign entity. In this way, issues with the target entity can become part of the response types during read-by-association or create-by-association operations. without response
prevents the default behavior. It excludes the foreign entity from the response types.
Notation: association _ext without response { create; }
Addition
... with draft; ...
Description
Draft-enables an association. A draft-enabled association retrieves active data if it is followed from an active instance and draft data if it is followed from a draft instance (for details about RAP draft handling, see RAP BDL - managed, with draft).
If a BO is draft-enabled, then all associations should be draft-enabled, so that the associations always lead to the target instance with the same state (draft or active).
As soon as you draft-enable a BO by adding with draft
, all BO-internal associations are automatically draft-enabled. To make this behavior explicit, the behavior prompts you to specify the to-child associations within a draft BO with with draft
.