Get Example source ABAP code based on a different SAP table
• USE ABAP_BDL_PROJECTION • USE CREATE ABAP_BDL_PROJECTION , USE • USE UPDATE ABAP_BDL_PROJECTION , USE • USE DELETE ABAP_BDL_PROJECTION , USE • USE ASSOCIATION ABAP_BDL_PROJECTION , USE • CREATE ABAP_BDL_PROJECTION , USE ASSOCIATION • WITH DRAFT ABAP_BDL_PROJECTION , USE ASSOCIATION • USE ACTION ABAP_BDL_PROJECTION , USE • USE FUNCTION ABAP_BDL_PROJECTION , USE • USE DRAFT ABAP_BDL_PROJECTION , USE • USE ETAG ABAP_BDL_PROJECTION , USE • AS ABAP_BDL_PROJECTION , USE ACTION • EXTERNAL ABAP_BDL_PROJECTION , USE ACTION
ABAP_RAP - use>, Projection BDEF
ABAP_SYNTAX ... use create $[(augment>$[, precheck>$])$] $| use update $[(augment>$[, precheck>$])$] $| use delete $[(precheck>)$] $| use association _Assoc { create $[( augment>$[, precheck>$])$]; $[with draft>;$]} $| use action $[(precheck>)$] ActionName $[result entity ProjResultEntity$] $[as ProjAction$] $[external 'ExtName'$] $[result external 'ExtResultName'$] $| use function FunctionName $[result entity ProjResultEntity$] $[as AliasName$] $[external ExtName$] $[result external ExtResultName$] $| use draft $| use etag ...>
ABAP_VARIANTS: 1 ... use create ...> 2 ... use update ...> 3 ... use delete ...> 4 ... use association ...> 5 ... use action ...> 6 ... use function ...> 7 ... use draft ...> 8 ... use etag ...>
What does it do? The keyword use> allows the reuse of entity behavior characteristics> , draft handling>, 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> Only such elements can be reused that 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. On top of reusing behavior, there are two optional, new additions 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 their own topics, see
precheck>>
augment>> 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.
ABAP_EXAMPLE_VX5 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>>. ABAP_NOTE This example does not fully meet the requirements of the RAP BO contract>. It is intentionally kept short and simple and serves demonstration purposes only. See more information on the RAP BO contract in the Development guide for the ABAP RESTful Application Programming Model>. BDEF DEMO_RAP_PROJECTION_CRUD The ABAP class CL_DEMO_RAP_PROJECTION_CRUD>> uses EML> to access a RAP business object>. It creates, updates, and deletes BO instances. ABAP_EXAMPLE_END
ABAP_FURTHER_INFO
Development guide for the ABAP RESTful Application Programming Model, section Projection Behavior Definition >
ABAP_VARIANT_1 ... use create ...>
What does it do? 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.
augment>>
precheck>> Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD>.
ABAP_VARIANT_2 ... use update ...>
What does it do? 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.
augment>>
precheck>> Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD>.
ABAP_VARIANT_3 ... use delete ...>
What does it do? 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.
precheck>> Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD>.
ABAP_VARIANT_4 ... use association ...>
What does it do? 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 TITLE >. In projection BDEFs, the following additions can be added. Both of them require an implementation in an ABAP behavior pool.
augment>>
precheck>> Example: see above, projection BDEF DEMO_RAP_PROJECTION_CRUD>.
ABAP_VARIANT_5 ... use action ...>
What does it do? 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. Only such actions, draft actions, and determine actions can be reused that are 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/interface. Additions:
precheck>>: a precheck can newly be added in the projection layer. An implementation in an ABAP behavior pool is required.
result entity>: If the base BDEF specifies an output parameter entity> using the keyword result entity>, the projection BDEF must specify the projection of the result entity with the syntax result 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 keyword as>.
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.
ABAP_EXAMPLE_VX5 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 TITLE >. BDEF DEMO_RAP_PROJ_ACTION 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>. IMAGE ABDOC_REJECTED.jpg 304 113 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 An example for reusing draft actions is shown under Variant 7, use draft>. ABAP_EXAMPLE_END
ABAP_VARIANT_6 ... use function ...>
What does it do? The syntax element use function> can be used in a projection or interface BDEF to reuse functions> from the underlying base BDEF. Only such functions can be reused that are defined in the underlying behavior definition. Additions:
result entity>: If the base BDEF specifies an output parameter entity> using the keyword result entity>, the projection BDEF must specify the projection of the result entity with the syntax result 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 keyword as>.
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.
ABAP_EXAMPLE_VX5 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 TITLE >. BDEF DEMO_RAP_PROJ_FUNCTION 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: IMAGE ABDOC_FUNCTION.png 598 365 ABAP_EXAMPLE_END
ABAP_VARIANT_7 ... use draft ...>
What does it do? 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 >. In a projection BDEF, draft actions> should be specified explicitly using the syntax element use action >. They are reused implicitly, but it is recommended that they are written explicitly. If BDEF strict mode> is switched on, it is mandatory to explicitly specify all of the draft actions. In an interface BDEF, draft actions must be specified explicitly using the syntax element use action>, as soon as draft handling is reused. 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>.
ABAP_EXAMPLE_VX5 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>. BDEF DEMO_RAP_PROJECTION_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. ABAP_EXAMPLE_END
ABAP_VARIANT_8 ... use etag ...>
What does it do? If the base BO specifies master or dependent ETag fields for optimistic concurrency control> , 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.
Latest notes: 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. NON_V5_HINTS ABAP_HINT_END
ABAP_FURTHER_INFO Development guide for the ABAP RESTful Application Programming Model, section Optimistic Concurrency Control>.