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 - Abstract Behavior Definitions →
RAP - Entity Behavior Definition, Abstract BDEF
Syntax
define behavior for AbstractEntity alias AliasName
extensible
with control
{
entity behavior body
}
scalar entity AbstractEntity field FieldName
behavior for ChildEntity1 , behavior for ChildEntity2 , ...
Description
Defines the behavior for a RAP abstract behavior definition in the RAP BDL. The abstract behavior definition must be based on a root CDS abstract entity AbstractEntity
and it can define the behavior for one or more of the nodes of the CDS composition tree.
For each node of the CDS composition tree, there are two possibilities how to include them in the behavior definition:
- A node can be integrated into the hierarchical type as a structured type using the syntax
define behavior for
. In this case, an entity behavior body is mandatory. - A node can be integrated into the hierarchical type as a scalar type using the syntax
scalar entity
.
Both alternatives are described with their additions below.
Example
The following example shows an abstract BDEF with two nodes, one of them being a scalar entity.
abstract;
strict(2);
with hierarchy;
define behavior for DEMO_CDS_SCALAR_ROOT_1 alias Root
{
mapping for demo_cds_scalar_1 corresponding
{
field1 = r_fd1;
field2 = r_fd2;
field3 = r_sib;
}
association _item1;
}
scalar entity demo_cds_scalar_child_1 field i1fd2;
Alternative 1
... define behavior for ...
Description
Entity behavior definition for a CDS abstract entity. It can consist of the following additions and components:
alias
: an alias name can be specified using the keywordalias
. The length of an alias nameAliasName
is restricted to 30 characters.extensible
: To enable BDEF extensions, a declaration in the abstract BDEF header is required and the keywordextensible
must also be declared after the statementdefine behavior for
for each entity that allows BDEF extensions. For details, see the topic RAP - Extensibility Enabling for Abstract BDEFs.with control
is an optional addition that adds a%control
structure to the corresponding derived type structure. That means that for each component of the hierarchical type, stemming either from an entity field or from an association, an identically named component of the built-in ABAP typex(1)
is added as part of the structure%control
which is appended at the end. As a result, all or some levels of the hierarchical types contain%control
components which may be used by applications to indicate the provisioning of the equally named payload components.- As a prerequisite to use
with control
, the abstract BDEF must use the additionwith hierarchy
. - An entity behavior body is mandatory and it can define field characteristics, associations, or type mapping. Transactional behavior is not possible in an abstract BDEF.
Hint
Entity behavior characteristics cannot be specified for abstract BDEFs.
Alternative 2
... scalar entity ...
Description
An entity in the CDS composition tree can be integrated into the hierarchical type not as a structured type, but as a scalar type, for example, an integer or a character. This is often defined for leaf entities. For a scalar type, the following syntax must be used instead of the usual define behavior for
syntax:
... scalar entity AbstractEntity field FieldName;
The specified field FieldName
of the scalar entity AbstractEntity
is taken for the scalar type. All other entity fields are ignored. Suppressing unwanted fields and type mappings are irrelevant.
It is also possible to declare the root node as scalar entity. Then the complete hierarchical type turns into one scalar type. This enables entity-based action parameter types which are elementary or internal tables with elementary line types.