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 - BehaviorDefinitionHeader →
RAP - foreign entity
Syntax
...
foreign entity ForeignEntityName alias AliasName ;
...
Description
Defines a RAP BO entity which is not part of the CDS composition tree of the current RAP BO as part of the response structures, thus enabling message mapping for other BOs. An alias name AliasName
can be specified. The length of this alias name can have a maximum of 30 characters.
A foreign entity is defined in the RAP behavior definition header and is therefore included in the response structures of all RAP BO nodes of the current RAP BO. A foreign entity includes the specified entity ForeignEntityName
in the response structures, but not a complete foreign RAP BO. It is possible to specify multiple foreign entities, if required.
Use
Here is an example for a use case: A RAP determination may trigger an operation of another business object that then returns messages. To receive and adapt the messages from a foreign business object, the foreign business object can be registered in the current BO as a foreign entity. The messages are mapped during the save sequence.
A reimplementation of the RAP saver method map_messages
in the ABAP behavior pool is optional.
Availability
RAP foreign entities can be defined in the following types of behavior definitions:
Hint
The association target of a cross-BO association in a BDEF is automatically included in the response types as a foreign entity. This default behavior can be disabled using the syntax addition without response
.
Further Information
- Development guide for the ABAP RESTful Application Programming Model, section Mapping Messages Between Business Objects.
map_messages
, RAP Saver Method
Example
The following example shows a managed BDEF based on the CDS root view entity DEMO_RAP_FOREIGN_ENTITY
. It establishes a connection to the foreign entity DEMO_SALES_CDS_SO_1
.
Note: This example is intentionally kept short and simple and serves demonstration purposes only. The RAP handler methods in the ABAP behavior pool are not implemented here.
managed implementation in class bp_demo_rap_foreign_entity unique;
strict(2);
//enables MAP_MESSAGES:
foreign entity DEMO_SALES_CDS_SO_1;
define behavior for DEMO_RAP_FOREIGN_ENTITY alias RootEntity
persistent table DEMO_DBTAB_ROOT
lock master
authorization master (global)
{
create;
update;
delete;
field(readonly:update) key_field;
}
The class CL_DEMO_RAP_FOREIGN_ENTITY
accesses the BDEF and creates three new entity instances.
Code snippet:
DELETE FROM demo_dbtab_root.
MODIFY ENTITIES OF DEMO_RAP_FOREIGN_ENTITY
ENTITY RootEntity
CREATE FIELDS ( key_field ) WITH VALUE #(
( %cid = '1' key_field = 1 )
( %cid = '2' key_field = 2 )
( %cid = '3' key_field = 3 ) )
MAPPED FINAL(mapped)
FAILED FINAL(failed)
REPORTED FINAL(reported).
COMMIT ENTITIES.
Result: The entities of the referenced foreign business object are added to the reported
structure.