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 - Projection Behavior Definitions → RAP - EntityBehaviorDefinition, Projection BDEF → RAP - EntityBehaviorBody, Projection BDEF →
RAP - use, Projection and Interface BDEF
Syntax
... use create augment , precheck )
(
use update (augment , precheck )
use delete (precheck)
use association _Assoc { create (augment , precheck ) ;
with draft; }
use action (precheck) ActionName
RedefinedParameter
result entity ProjResultEntity
as ProjAction
external 'ExtName'
result external 'ExtResultName'
use function FunctionName
RedefinedParameter
result entity ProjResultEntity
as AliasName
external ExtName
result external ExtResultName
use draft
use etag
use event EventName RedefinedParameter as AliasName
use side effects
use key KeyName as AliasName
use DefaultValuesFunction ...
Variant
Description
The keyword use
allows the reuse of entity behavior characteristics, draft handling, RAP business events, RAP side effects, RAP alternative keys, RAP default values functions, and RAP BO operations from the base BDEF in a projection BDEF or interface BDEF.
The following operations and characteristics can be reused:
- standard operations
- operations for associations
- actions
- functions
- ETag
- draft handling, including draft actions
- events
- side effects
- BDEF alternative keys
- default values functions
A prerequisite for reuse is that the respective elements were defined in the underlying behavior definition. The behavior is realized by mapping it to the underlying behavior; no implementation in an ABAP behavior pool is required.
Reused behavior can be enhanced. The following optional additions are available for the reused behavior: precheck
and augment
. Both of them require an implementation in the ABAP behavior pool. They are available only in projection BDEFs, not in interface BDEFs. These additions are documented in the following topics:
For the operations and characteristics listed in this topic, no automatic inheritance takes place. They must be explicitly specified in the projection or interface BDEF. Otherwise, the respective feature is not available in the projection or interface.
Example
The following example shows a projection BDEF that reuses standard operations and operations for associations from its underlying base BDEF. The base BDEF is DEMO_SALES_CDS_BUPA_2
.
projection;
strict(2);
define behavior for DEMO_RAP_PROJECTION_CRUD
{
use create;
use update;
use delete;
use association _BuPa { create; }
}
define behavior for DEMO_RAP_PROJ_CRUD_CHILD
{
use update;
use delete;
use association _Address;
}
The ABAP class CL_DEMO_RAP_PROJECTION_CRUD
uses EML to access a RAP business object. It creates, updates, and deletes BO instances.
Further Information
- Development guide for the ABAP RESTful Application Programming Model, section Projection Behavior Definition
Variant 1
... use create ...
Description
The standard operation create
can be reused in a projection or interface BDEF.
In a projection BDEF, the following additions can be added. Both of them require an implementation in an ABAP behavior pool.
Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD
.
Variant 2
... use update ...
Description
The standard operation update
can be reused in a projection or interface BDEF.
In a projection BDEF, the following additions can be added. Both of them require an implementation in an ABAP behavior pool.
Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD
.
Variant 3
... use delete ...
Description
The standard operation delete
can be reused in a projection or interface BDEF.
In a projection BDEF, the following addition can be added. It requires an implementation in an ABAP behavior pool.
Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD
.
Variant 4
... use association ...
Description
The transactional enabling of associations can be reused in a projection or interface BDEF.
If RAP draft handling is enabled in the projection or interface BDEF, associations must be draft enabled using the syntax addition with draft
.
Example: use association _assoc { create; with draft; }
For details on the read-by-association and create-by-association operations as well as draft-enabling of associations, see topic RAP - Operations for Associations.
In projection BDEFs, the following additions can be added. Both of them require an implementation in an ABAP behavior pool.
Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD
.
Variant 5
... use action ...
Description
The syntax element use action
can be used in a projection or interface BDEF to project actions, draft actions, and determine actions from the underlying base BDEF. As a prerequisite for reuse, the respective actions, draft actions, and determine actions must be defined in the underlying behavior definition. If an authorization concept or feature control is specified for an action, this is automatically passed on to the projection or interface.
Additions:
precheck
: A precheck can newly be added in the projection layer. An implementation in an ABAP behavior pool is required.RedefinedParameter
: The input or the output parameter of an action can be redefined in a projection or interface BDEF. For details, see RAP -RedefinedParameter
.result entity
: If the base BDEF specifies an output parameter entityOutputParameter
using the keywordresult entity
, the projection BDEF must specify the projection of the result entity with the syntaxresult entity ProjResultEntity
. Otherwise, it may happen that the action is no longer exposed if the result entity is not included in the service.as
: An action can be given a new alias name in the projection layer using the keywordas
.external
: A new alias name for external usage in OData can be provided in the projection layer. This external name can be much longer than the alias name in ABAP and needs to be used when defining the corresponding UI annotations.result external
: A new alias name for the result entity can be provided in the projection layer. This new name is exposed in the OData metadata.
Example
The following example shows a projection BDEF that reuses the two actions Approve_Order
and Reject_Order
from the underlying base BDEF. The underlying base BDEF is DEMO_CDS_PURCH_DOC_M
.
For a detailed description of the definition and implementation of the base BO, see topic RAP - Action.
projection;
strict(2);
define behavior for DEMO_RAP_PROJ_ACTION
{
use create;
use update;
use delete;
use action Approve_Order as Approve;
use action Reject_Order as Reject;
}
The ABAP class CL_DEMO_RAP_PROJ_ACTION
uses EML to access a RAP business object. It performs the action Reject
on one entity instance.
Result: column Status
of the respective instance is filled with R
for Rejected
.
Example
An example for reusing draft actions is shown under Variant 7, use draft
.
Variant 6
... use function ...
Description
The syntax element use function
can be used in a projection or interface BDEF to reuse functions from the underlying base BDEF. As a prerequisite for reuse, the respective functions must be specified in the underlying behavior definition.
Additions:
RedefinedParameter
: The input or the output parameter of a function can be redefined in a projection or interface BDEF. For details, see RAP -RedefinedParameter
.result entity
: If the base BDEF specifies an output parameter entityOutputParameter
using the keywordresult entity
, the projection BDEF must specify the projection of the result entity with the syntaxresult entity ProjResultEntity
. Otherwise, it may happen that the function is no longer exposed if the result entity is not included in the service.as
: A function can be given a new alias name in the projection layer using the keywordas
.external
: A new alias name for external usage in OData can be provided in the projection layer. This external name can be much longer than the alias name in ABAP and needs to be used when defining the corresponding UI annotations.result external
: A new alias name for the result entity can be provided in the projection layer. This new name is exposed in the OData metadata.
The following special rules apply to RAP key functions:
- Reuse is possible in interface and projection BDEFs.
- As a prerequisite for reusing a key function, the alternative key it refers to must be reused using the syntax
use key KeyName
. - Key functions are reused using the syntax
use function Name
. An alias name can be defined usingas
and an external name can be defined usingexternal
. No other additions are possible.
Example
The following example shows a projection BDEF that reuses the functions getDetails
, calculateTotal
, and calculateDiscount
from the underlying base BDEF. The underlying base BDEF is DEMO_RAP_PROJ_FUNCTION
.
For a detailed description of the definition and implementation of the base BO, see topic RAP - function
.
projection;
strict(2);
define behavior for DEMO_RAP_PROJ_FUNCTION
{
use create;
use update;
use delete;
use function getDetails;
use function calculateTotal;
use function calculateDiscount;
}
The ABAP class CL_DEMO_RAP_PROJ_FUNCTION
uses EML to access a RAP business object. It executes all three functions and displays the content of their result structures. No modify operations are carried out, the functions merely deliver information in their result structure without changing database entries.
Result:
Variant 7
... use draft ...
Description
RAP draft handling can be reused with the syntax element use draft
. As a prerequisite, the underlying RAP BO must be draft-enabled. The draft tables, draft query views (if specified), and the total ETag field are implementation details that are automatically reused and do not have to be explicitly specified in projection BDEFs and interface BDEFs. For details on RAP draft handling, see topic RAP BDL - with draft.
If RAP draft handling is reused, it is mandatory to explicitly reuse the draft actions using the syntax use action
in projections BDEFs and RAP BO interfaces.
Reused associations should be explicitly draft-enabled using the syntax element with draft
.
Example: use association _assoc { create; with draft; }
For further details on draft-enabled associations, see the topic RAP BDL - operations for associations.
Example
The following example shows a projection BDEF that is based on the unmanaged, draft-enabled BDEF DEMO_RAP_UNMANAGED_DRAFT_ROOT
. It reuses the RAP draft handling.
For a detailed description of the definition and implementation of the base BO, see the topic RAP BDL - with draft.
projection;
strict(2);
use draft;
define behavior for DEMO_RAP_PROJECTION_DRAFT
{
use create;
use update;
use delete;
use association _child { create; with draft; }
use action Edit;
use action Activate;
use action Discard;
use action Prepare;
use action Resume;
}
define behavior for DEMO_RAP_PROJECTION_DRAFT_CHIL
{
use update;
use association _parent { with draft; }
}
The implementation is automatically reused from the base BO.
The ABAP class CL_DEMO_RAP_PROJECTION_DRAFT
accesses the business object using EML and performs the following steps:
- It creates two new draft instances of the parent entity and two new draft instances of the child entity and displays the content of the draft tables.
- Then it activates the draft entities using the draft action
Activate
. The content of the draft tables is written to the persistent tables and the draft tables are emptied.
Variant 8
... use etag ...
Description
If the base BO specifies RAP ETag fields, these fields can be reused. The keyword use etag
must be specified for each entity in the projection or interface BDEF individually. If it is not specified explicitly in the projection or interface BDEF, the optimistic concurrency control functionality is lost.
Hint
Even in projection BDEFs without the syntax use etag
, the value of the ETag field is updated during each modify operation. However, the syntax use etag
enables an optimistic lock phase in an OData service. During the optimistic lock phase, on each modify request, the value of the ETag field is checked and if an OData client detects any changes in the ETag value, no data changes are possible. Any attempt to save data fails.
Further Information
Development guide for the ABAP RESTful Application Programming Model, section Optimistic Concurrency Control.
Variant 9
... use event ...
Description
RAP business events can be reused in an interface BDEF.
Caution: Reuse is possible in interface BDEFs only. It is not possible to reuse a business event in a projection BDEF.
Additions:
RedefinedParameter
: The input parameter of an event can be redefined in the interface BDEF. For details, see RAP -RedefinedParameter
.- The optional addition
as
can be used to assign an alias name to the business event in question.
Variant 10
... use side effects ...
Description
RAP side effects can be reused in a projection BDEF and in an interface BDEF.
The syntax use side effects
is specified in the behavior definition header and all side effects from all RAP BO entities of the underlying RAP BO are reused. However, if side effects are defined for BO properties, such as fields or actions, that do not appear in the projection at all, these side effects are filtered out and do not have any effect in the projection.
Note: If a base BO is defined as extensible
, the syntax use side effects
must be specified in the behavior definition header of an interface BDEF or of a projection BDEF to ensure that side effects are reused, even if they are specified in an extension. Otherwise, a syntax check warning occurs.
Example
The following example shows an interface BDEF that reuses the side effects from its underlying base BDEF. The base BDEF is DEMO_RAP_SIDE_EFFECTS
.
interface;
use draft;
use side effects;
define behavior for DEMO_RAP_SIDE_EFFECTS_I alias Root
{
use create;
use update;
use delete;
use action MyActionFC;
use action MyAction;
use action someDetermineAction;
use action Edit;
use action Activate;
use action Discard;
use action Resume;
use action Prepare;
}
Variant 11
... use key ...
Description
BDEF alternative keys can be reused in a projection or interface BDEF. Optionally, an alias name AliasName
can be specified using the addition as
. The reused alternative key can then be used to define a new key function in a projection BDEF or for accessing an internal table using this alternative key.
Variant 12
... use DefaultValuesFunction ...
Description
Default values functions can be reused in a projection BDEF or in an interface BDEF. Both the operation in question and the default values function must be reused separately. For details, see the topic RAP - use DefaultValuesFunction
.