RAP Draft Application Part 40 53 1731359829
RAP Draft Application Part 40 53 1731359829
with
Draft Capabilities
ABAP RESTful Application Programming Model (RAP)
Part – 40
SAP TECHNOMANIAC
Draft
➢The draft concept fills the gap between a
stateless communication pattern and a
stateful application by applying REST
principles:
SAP TECHNOMANIAC
Draft Advantage
Device Switch:
SAP TECHNOMANIAC
Draft Basic Principles
SAP TECHNOMANIAC
Draft is available for managed,
Unmanaged, mixed scenarios .
SAP TECHNOMANIAC
Draft Restrictions - Draft-Enabled Business Objects
SAP TECHNOMANIAC
Draft Restrictions-Unmanaged Business Objects with Draft
There are features that can be defined in the behavior definition of an unmanaged
business object and thus used on active instances, but not on draft instances:
•Create-enabled associations that aren't modeled as part of a composition
•Direct creates on child instances
The aggregated admin data fields aren't Associations that use NOT in the
updated automatically when a draft binding condition can't be draft-
instance is saved. enabled.
SAP TECHNOMANIAC
Development Flow
SAP TECHNOMANIAC
Editable Entities of the Business Object
➢/DMO/A_TRAVEL_D
➢/DMO/A_BOOKING_D
➢/DMO/A_BKSUPPL_D.
SAP TECHNOMANIAC
We want to see internal managed early numbering so every
entity needs a field for the UUID key and this scenario will be
based on a UUID key layout
/DMO/A_TRAVEL_D • ZR_Travel_D
/DMO/A_BOOKING_D • ZR_Booking_D
/DMO/A_BKSUPPL_D. • ZR_BookingSupplement_D
SAP TECHNOMANIAC
Creating CDS View Projections
/DMO/A_BOOKING_D • ZR_Booking_D->ZC_Booking_D
/DMO/A_BKSUPPL_D.
• ZR_BookingSupplement_D
->ZC_BookingSupplement_D
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
Development Flow
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
(Authorization )
SAP TECHNOMANIAC
Development Flow
SAP TECHNOMANIAC
Authorization Checks for Read Operations :- DCL used
Authorization Control
SAP TECHNOMANIAC
Global Authorization:- Instance Authorization:-
Authorization Control
SAP TECHNOMANIAC
Authorization Control
SAP TECHNOMANIAC
RAP - Authorization
➢Each RAP BO entity must be
declared as authorization
master entity or as
authorization dependent entity
using the syntax
➢The RAP BO root entity must
be defined as authorization
master entity. All other RAP
BO entities can be either
authorization master or
authorization-dependent
entities.
SAP TECHNOMANIAC
◦authorization:none
The authorization control that is defined for a RAP BO ◦authorization:update
entity applies to all RAP BO operations of that
◦authorization:global
particular entity.
◦authorization:instance
•If a root entity is defined as authorization master entity, then it is recommended that each child entity that is
behavior-enabled is defined as an authorization dependent entity.
RAP - Authorization
SAP TECHNOMANIAC
Managed RAP BO • RAP Framework checks for Global and instance Authorization
RAP – Authorization
Availability
SAP TECHNOMANIAC
Generally, CRUD operations and actions reused with use inherit the authorization
control from the base behavior definition
If you define new actions on projection level as described in Actions and Functions in
Projection Behavior Definitions and the projection behavior definition is defined as
strict, you can add authorization control for these actions on projection level
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Authorization in Draft Scenarios
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
(Authorization Implementation)
SAP TECHNOMANIAC
Global Authorization
Implementation
➢Global :- Restrict if user don’t have access to create,
Update, Delete access
➢We will use existing ‘/DMO/TRVL’ Auth object
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
(Abstract Entity and Actions )
SAP TECHNOMANIAC
Input Parameter in Actions
➢The input parameter for an action or function is
defined with the keyword parameter.
➢The input parameter entity ParameterEntity
can be a CDS abstract entity or a classic DDIC
type
➢Input parameters with $self are only allowed
on static actions or functions(result type is the
same type as the entity for which the action or
function is defined)
SAP TECHNOMANIAC
Output Parameter in Actions
➢The output parameter for an action or function is
defined with the keyword result.
➢If a result parameter is declared it must be filled
inthe implementation in the ABP.
➢Cardinality :- This is a mandatory addition.
SAP TECHNOMANIAC
Not created as a
Represents a data type. database object hence Abstract entities are
Thes are CDSCDS transient
transient entities
entities.
CDS transient client handling is not non-SQL CDS entities.
defined.
entities
CDS-Abstract Entity
SAP TECHNOMANIAC
CDS-Abstract Entity
SAP TECHNOMANIAC
acceptTravel :- The action sets the rejectTravel :- The action sets the
travel status to Accepted (A). travel status to Rejected (X).
Developing Actions
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( Actions Implementation )
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
(Determinations & Side Effect )
SAP TECHNOMANIAC
Determinations
➢A determination is an optional part of the BO behavior that
modifies instances of BO based on trigger conditions
➢A determination is implicitly invoked by the BO’s framework
if the trigger condition of the determination is fulfilled.
➢Trigger conditions can be modify operations CUD and
modified fields
➢An invoked determination can compute data, modify entity
instances according to the computation result and return
messages to the consumer by passing them to the
corresponding table in the REPORTED structure.
SAP TECHNOMANIAC
RAP - determination
➢Trigger conditions can be modify operations CUD or modified fields
SAP TECHNOMANIAC
Determinations Points
➢The determination result must not change if the
determination is executed several times under the same
conditions (idempotence).
➢The execution order of determinations is not fixed. If there is
more than one determination triggered by the same
condition, you cannot know which determination is executed
first.
➢Once a determination has been triggered, it must run
independently from other determinations.
SAP TECHNOMANIAC
Developing Determinations
Travel entity
Booking entity
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( Side Effect )
SAP TECHNOMANIAC
The SAP Fiori UI doesn't necessarily trigger a reload of all related BO properties after
every user input, as it simply doesn't know anything about data changes on the tables.
Side effects are used to reload data, permissions, or messages based on data
changes in UI scenarios with draft-enabled BOs.
Side effects are translated into annotations in the OData metadata of a RAP service. An
implementation in an ABAP behavior pool is not required.
These are available from 2302 of the SAP BTP, ABAP Environment and SAP S/4HANA
ABAP Environment
Side Effects
SAP TECHNOMANIAC
Side Effects - Trigger
SAP TECHNOMANIAC
RAP - side effect, Targets
1. ... field ...
3. ... $self
4. ... entity
5. ... messages
SAP TECHNOMANIAC
RAP - side effect, Target Field
SAP TECHNOMANIAC
RAP - side effect, Target
permissions
➢The feature and authorization control of the specified
properties are reloaded when the side effect is triggered.
➢Multiple permissions can be listed in parentheses, separated
by commas
• Example: permissions(action MyActionFC, update).
SAP TECHNOMANIAC
RAP - side effect, Target
➢$self
• The current RAP BO entity is reloaded.
• Limitation: In case of the trigger property $self, it is not allowed to
specify the current entity $self as target.
➢entity _MyAssoc
• The specified associated entity _MyAssoc is reloaded when the side
effect is triggered.
➢message
• All messages stored in the response parameter reported are reloaded
when the side effect is triggered.
SAP TECHNOMANIAC
RAP - side effect, Targets
➢One type of side effect can affect multiple targets.
SAP TECHNOMANIAC
Restriction
SAP TECHNOMANIAC
Side Effect in BDL
➢Side effects can be specified exactly once for each RAP
BO entity in the entity behavior definition.
➢Multiple side effects can be summarized within curly
brackets, separated by a semicolon (;), if required.
SAP TECHNOMANIAC
RAP - use, Projection and
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
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( State vs Transition Messages & Validations )
SAP TECHNOMANIAC
Messages -RAP
SAP TECHNOMANIAC
Messages in RAP -Implementation
SAP TECHNOMANIAC
Messages in RAP -Implementation
SAP TECHNOMANIAC
A state message must
You musn't define state
State messages are always be bound to a
messages in an action or
semantically related to the business object entity and
function added on projection
state of business object can't be allocated to the
level (Dump)
%OTHER component.
If a validation returns an
error message regarding an
Draft scenario, they’re
Managed scenario, the incorrect value in a field, the
persisted until the state that
messages are buffered until state message is persisted
caused the message is
the end of the session until the value is changed
changed
and the save sequence is
triggered again
State Messages
SAP TECHNOMANIAC
➢The %state_area
Component
➢The %path Component for
Child Entities
➢Invalidating State
Messages
SAP TECHNOMANIAC
State Messages
Using state messages is only recommended for
the following cases:
Managed Scenario:
Determinations/Validation on Save
SAP TECHNOMANIAC
State Message
SAP TECHNOMANIAC
Message Behavior in EML
SAP TECHNOMANIAC
Messages in OData V4
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( Validations & State vs Transition Messages )
SAP TECHNOMANIAC
RAP - validation
➢A validation is an optional part of the business object behavior that checks
the consistency of business object instances based on trigger conditions.
➢It is automatically invoked by the RAP framework if the trigger condition of
the validation is fulfilled
➢Trigger conditions can be :- CUD operation or modified fields (update for
validations is only supported in combination with create)
➢Validations are always invoked during the save sequence at the end of a
transaction and this is indicated by the mandatory addition on save.
➢Validations must be implemented in the RAP handler
method FOR VALIDATE in the local ABAP
behavior pool (ABP).
SAP TECHNOMANIAC
RAP - validation
SAP TECHNOMANIAC
Trigger Time
➢ Validations on save are executed:
• In the checkBeforeSave method of the save sequence
• On request by executing a determine action, if the validation has been assigned to
such an action in the behavior definition. For more information, see Determine
Actions.
SAP TECHNOMANIAC
Validating for the Travel Entity
SAP TECHNOMANIAC
Validating for the Booking Entity
SAP TECHNOMANIAC
Validating for the BookingSuppl
Entity
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( Adding Draft Capabilities to Managed BO )
SAP TECHNOMANIAC
The addition with draft enables RAP draft handling for a
business object
SAP TECHNOMANIAC
Let's Do Practical
SAP TECHNOMANIAC
Draft table: To store draft instance
Total etag: Indicates changes between the active and the draft version
Draft actions: They allow data to be manipulated on the RAP draft table.
Draft - Dependencies
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( Draft Table, Total Etag, Draft Action )
SAP TECHNOMANIAC
Draft Database Table
➢A RAP draft table is a DDIC database table used
to store draft data
➢The draft table must reflect the fields of the
underlying CDS entity
➢The first field must be a client field that has the
data type CLNT.
➢The field names of the fields of the draft tables
are the same as the field names of the
underlying CDS entity. If the CDS entity has
assigned alias names, these alias names must be
used.
➢The data types and field lengths must match
exactly.
➢Additionally, the draft table must contain some
technical information the RAP transactional
engine needs to handle the draft. Using draft
admin include SYCH_BDL_DRAFT_ADMIN_INC.
SAP TECHNOMANIAC
Draft Database Table
While the active database table stores many instances, but
rarely has access on these instances, it is vice versa for the
draft table.
Access with ABAP SQL and AMDP is technically possible, but not
recommended. It is recommended that a draft table is accessed
using the RAP framework only, for example, with EML, so that
the draft metadata get updated automatically.
SAP TECHNOMANIAC
Total-ETag
SAP TECHNOMANIAC
Total-ETag Update
The RAP managed framework is able to update the total ETag field automatically on saving a draft instance if the following
conditions are fulfilled:
If you don’t enable the framework to update the field, you have to include your own updating logic in the
business logic of the BO.
SAP TECHNOMANIAC
Total ETag vs ETag
➢As soon as the exclusive lock expires ➢Hence, the ETag prevents changes of the BO
and an edit-draft is resumed, the total that are not noticed by the OData consumers
ETag value of the draft instance is
compared to the total ETag value on
the active instance. ➢With ETag master, each BO entity can be
checked independently.
➢The total ETag is compared for all
entities of a BO
SAP TECHNOMANIAC
Draft-Enabled Associations
SAP TECHNOMANIAC
RAP - draft action
Draft actions are available for draft-enabled RAP BOs
only.
SAP TECHNOMANIAC
RAP - draft action Availability
In projection In RAP BO
BDEFs that interfaces that
reuse RAP draft reuse RAP draft
handling, the handling, the
draft actions draft actions
must be reused must be reused
SAP TECHNOMANIAC
RAP - draft action
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
( Draft Runtime & Draft Action )
SAP TECHNOMANIAC
Draft Runtime
➢All data undergo several states while being processed
by a draft business object. There are three distinct
states
• New-draft instance
• Active instance
• Edit-Draft instance
SAP TECHNOMANIAC
New-draft instance
➢ Initial data that is not yet persisted on the active database table
➢ New-draft instances do not have a corresponding active instance
➢ They are created using the modify CREATE operation having the draft
indicator %IS_DRAFT set to true
SAP TECHNOMANIAC
Active instance
➢ Active instances are created by activating new draft instances or using the
modify CREATE operation with the draft indicator %IS_DRAFT set to false
➢ The data that is stored on the persistent database table is called active data
SAP TECHNOMANIAC
Edit-Draft instance
➢ Edit-drafts always exist in parallel to the corresponding active data.
➢ Whenever active data is edited, the active instance is copied to the draft table.
➢ All modifications are saved on the draft DB table before the changes are finally
applied to the active data on the active DB table again
➢ Edit-draft instances
are created by
using the EDIT
action on active
instances.
SAP TECHNOMANIAC
Locking During Draft
When working with draft instances, an exclusive lock is set on
the instance. For edit-drafts, this prevents any other user from
Exclusive lock modifying the corresponding active instance
In case of a new-draft, the primary key number is locked
exclusively to avoid duplicate key failure on the database.
SAP TECHNOMANIAC
Creating Draft Data
“Modify CREATE Request”
➢Using EML with %is_draft =
true
➢On a Fiori Elements UI,
clicking the Create button
sends a CREATE request with
the draft indicator set to true,
so active instances cannot be
created directly this way.
SAP TECHNOMANIAC
Creating Draft Data
“Edit Action”
➢An edit action creates a new draft document by automatically copying the
corresponding active instance data to the draft table.
➢At the same time, the EDIT triggers an exclusive lock for the active
instance
➢The edit action has a parameter preserve_changes,if it is set to true, your
action request is rejected if a draft already exists. If preserve_changes is
set to false (default setting), the edit action is executed.
➢Instance authority and feature control are both checked for the action.
➢Trigger:-
• Fiori Edit button ( preserve_changes set to true).
• EML
SAP TECHNOMANIAC
Runtime Edit Action
SAP TECHNOMANIAC
Runtime CREATE Draft
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Developing Transactional Apps
with
Draft Capabilities
(Draft Runtime & Draft Action )
SAP TECHNOMANIAC
Draft Runtime & Draft Action
SAP TECHNOMANIAC
Creating Active Data
“Modify CREATE Request”
➢Using EML with %is_draft =
false
➢Creating a new active
instance for a draft BO
from scratch is not
possible from a Fiori
Elements UI.
SAP TECHNOMANIAC
Creating Active Data
“Activate Action”
➢By executing the draft action ACTIVATE on a draft instance, you copy the draft instance to
the active application buffer
➢Once the active instance is successfully created or updated, the draft instance is discarded
➢The activate action does not save the active instance on the database. The actual save is
executed separately, either by COMMIT ENTITIES via EML or by calling the save sequence
in case of OData.
➢The activate action is only possible on draft instances.
➢On a Fiori Elements UI, the activate action is triggered when choosing the Save button after
editing data. It triggers the save sequence after the activation.
SAP TECHNOMANIAC
Creating Active Data
“Activate Action”
SAP TECHNOMANIAC
Runtime Activate Action
SAP TECHNOMANIAC
Runtime Activate Optimized Action
Draft activation
➢Without optimization
• When draft instances are
modified, determinations
on modify are executed if
their trigger conditions are
met. In the activate variant
without optimization, these
determinations are executed
again during draft activation,
when the RAP runtime takes
over the changes from the
draft instances to the active
instances.
SAP TECHNOMANIAC
Runtime Activate Optimized Action
Draft activation
➢With optimization
• In the optimized variant, the
determinations on modify are
not executed again on the
active instances during draft
activation. Determinations on
modify that are triggered by
determinations on save
during Prepare are skipped
as well.
SAP TECHNOMANIAC
Runtime Activate Optimized Action
Save after draft activation
➢Without optimization
• After activating a draft
instance, determinations and
validations with the trigger
time on save are executed
during the save sequence
SAP TECHNOMANIAC
Runtime Activate Optimized Action
Save after draft activation
➢With optimization
• Those determinations and
validations that have been
executed as part of the draft
determine action prepare
before activating the draft
instance are not executed
again when saving the active
instance.
SAP TECHNOMANIAC
Runtime Activate Optimized Action
SAP TECHNOMANIAC
Changing and Reading Instances of
a Draft BO
➢Updating Instances of a Draft BO
➢Executing Actions on a Draft BO
➢Reading Instances of a Draft BO
SAP TECHNOMANIAC
Changing and Reading Instances of
a Draft BO
➢Updating Instances of a Draft BO
• Fields of draft BO instances are changed by the modify
request for UPDATE.
• Fiori Element UI
• EML
SAP TECHNOMANIAC
Changing and Reading Instances of
a Draft BO
➢Executing Actions on a Draft BO
• Actions on draft business objects are executed by modify
requests for action execution.
• Fiori Element UI
• EML
SAP TECHNOMANIAC
Changing and Reading Instances of
a Draft BO
➢Reading Instances of a Draft BO
• Business object instances of a draft BO are read by a read
request.
• Fiori Element UI
• EML
SAP TECHNOMANIAC
Runtime MODIFY Draft
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC
Deleting Instances of a Draft BO
SAP TECHNOMANIAC
Runtime Discard Action
SAP TECHNOMANIAC
Preparing Draft Instances for
Activation
➢The draft determine action PREPARE is executed automatically at
least once before draft data is activated during the activate
action
➢It ensures that the draft instance is consistent by calling the
validations and determinations on save that are specified for the
prepare action in the behavior definition.
➢The prepare action can only be executed on draft instances.
➢On a Fiori Elements UI, the PREPARE action is invoked by
choosing Save on a draft instance. The UI then sends the request
for PREPARE before executing the action ACTIVATE.
SAP TECHNOMANIAC
Runtime Prepare Action
SAP TECHNOMANIAC
Resuming Locks for Draft
Instances
➢The draft action RESUME is executed automatically
whenever there is a modification on a draft instance
whose exclusive lock has expired.
➢It recreates the lock for the corresponding active
instance on the active database table.
➢On a Fiori Elements UI, the action is invoked when the
user chooses a draft instance and continues with editing
data if the exclusive lock is expired.
SAP TECHNOMANIAC
Runtime Resume
Action
SAP TECHNOMANIAC
draft action Resume
SAP TECHNOMANIAC
Saving Data to the Database
➢Draft data does not have to be in a consistent state to be saved.
➢No validations are triggered when saving draft data to the draft database
➢The save sequence of the active provider is not triggered. That means, there is no Finalize
and no Check_Before_Save when saving draft instances on the draft database table.
➢On a Fiori Element UI, the state of the application buffer is saved to the draft database table
whenever the input fields are edited. This is done for each field separately. That means, after
leaving one input field, the data is transferred to the draft database table. The UI displays
the message Draft saved after each roundtrip.
SAP TECHNOMANIAC
THANK YOU
CONTACT
Ram Niwas
LinkedIn :- https://www.linkedin.com/in/ram-niwas-04/
FB group :-
https://www.facebook.com/groups/586730659057346/
SHARE THANKS
SAP TECHNOMANIAC