Arunagirish RAP Notes
Arunagirish RAP Notes
Main objective:
This documentation answers all those topics. That’s why I start right from the
prerequisites for RAP — explaining topics like the different SAP systems and
how they differ, various tech stacks for Fiori, when to use RAP, and real-
world RAP use cases. I also break down buzzwords like extensibility (side-by-
side, developer), clean core, and how that’s achieved using Steampunk and
embedded Steampunk.
A huge part of this book focuses on the architecture and flow of RAP from
multiple viewpoints, like list & object pages, analytics RAP, unmanaged
queries, and much more.
I’ve further covered AUnits and the Test Double Framework, with examples
tailored for RAP.
[Link]
Disclaimer:
3. Draft - pg no: 26
3.1 Why do we need draft / Drawbacks of non-draft
3.2 How draft helps
3.3 Locking in draft
3.3.1 Exclusive lock
3.4 Total ETag
3.4.1 What is Total ETag
3.4.2 Why Total ETag vs ETag Master/Dependent
3.5 Steps to add draft
3.5.1 In BDEF interface
3.5.2 In BDEF for child entity
3.5.3 In BDEF projection
3.6 %key vs %tky
3.7 Draft actions
3.7.1 Edit
3.7.2 Activate
3.7.3 Resume
3.7.4 Prepare
3.7.5 Discard
3.8 Draft flows
3.8.1 Create flow
3.8.2 Edit flow
4. EML Statements
- pg no: 35
4.1 Common additions
4.1.1 In-local mode
4.1.2 Privileged mode
4.2 Read EML
4.2.1 Short form (single entity)
4.2.2 Long form (multiple entities)
4.2.3 Dynamic read
4.2.4 Read by table or fixed value
4.3 Modify EML
4.3.1 Multiple modify (create from itab)
4.3.2 Hardcode few values
4.3.3 Create by association
4.4 Get permission EML
4.5 Commit entities EML
4.6 Modify augmenting EML
5. Numbering - pg no: 41
5.1 Early numbering
5.1.1 External early numbering
5.1.2 Managed internal early numbering
5.1.3 Unmanaged internal early numbering
5.2 Late numbering
5.2.1 Adjust numbers in saver
5.3 Summary of numbering
Based on the system you are using, the usage of RAP (RESTful ABAP Programming
Model) will differ. So, it is important to understand the different SAP systems:
1. S4 hana on premise:
This is primarily used by large-scale companies that require extensive
customization and want full control over their infrastructure (hardware,
databases, servers). The customer is responsible for deployment and
maintenance.
The public cloud runs on a shared platform and can only be accessed through
Eclipse ADT (ABAP Development Tools). GUI access is not supported, and you
cannot directly access standard tables or BAPIs. Instead, you must use CDS
views and business object interfaces (RAP facades).
Here, you can use both the SAP GUI and Eclipse ADT and supports classical
abap aswell.
1
Abap language version:
You might have noticed when you create project, it asks you whether it’s a ABAP
project or abap cloud project.
If you create cloud project it supoprts only abap for cloud and normal abap project
supports both standard abap and abap for cloud development.
Standard abap:
Is done using gui and eclipse adt, These are nothing but your classical abap
ricefw and modern abap like cds,rap. These doesn’t have any restriction for
cloud check.
can be done only using eclipse adt, It doesn’t support classical abap like
ricefw. Only supports modern abap like rap, cds, cloud badi, classes. you
cannot use objects that are declared for standard abap directly in abap on
cloud. They have to be released in c1 contract. If they need to be used. That
2
is the reason we don’t use standard table and bapi Instead, you must use
CDS views and business object interfaces (RAP facades).
Note:
if you are migrating code from standard to cloud or releasing it for c1
contract. Always do atc check with ABAP_CLOUD_READINESS variant
[Link]
US/abenabap_versions.htm
[Link]
members/smooth-transition-to-abap-for-cloud-development-cheat-
sheet/ba-p/13571567
Refernce link:
[Link]
fiori/using-sap-fiori-launchpad_a9103226-f903-4afb-b471-c07be29c59e3
3
Types of Fiori Applications
Freestyle Fiori:
In this approach, developers manually design the ui and ux of application
using front-end technologies like SAPUI5. It offers full control over the UI
making it suitable for custom requirement from front-end level.
Fiori Elements:
This approach uses predefined UX templates provided by SAP to develop
applications with minimal coding. Instead of building the UI from scratch, you
consume annotations to generate the interface. Technologies like RAP
(RESTful ABAP Programming), CAP (Cloud Application Programming Model),
and SAP Build often use Fiori Elements to accelerate development.
reference link:
[Link]
members/sap-fiori-elements-vs-freestyle-apps-when-to-use-what/ba-p/14100734
4
4. SAP Build Apps:
SAP Build Apps is used to create Fiori-like applications with minimal technical
expertise by leveraging no code-low code. It's ideal for business users or end
users who want to build applications quickly without deep coding knowledge.
Best suited for: Rapid app development, prototyping, or empowering
non-developers
Strengths: Drag-and-drop interface, pre-built integration s, and tight
coupling with BTP services
The SAP Business Accelerator Hub is a platform where you can find released
objects such as APIs, CDS views, Business Objects (BO), events, and more.
These resources are particularly useful for extensibility scenarios, including
side-by-side extensions and developer/on-stack extensibility for various SAP
products. Using the released content from the hub helps minimize the need
to create custom objects, promoting reuse and standardization. In the
context of RAP (RESTful ABAP Programming), the hub can be leveraged for
developer extensibility to access information about CDS views, BO interfaces
(RAP façades), and cloud BADIs.
The clean core principle refers to keeping your core system—typically your
S/4HANA system—as free from custom modifications as possible. The goal is
to avoid unnecessary changes to the standard SAP code-base to ensure the
system remains cloud-ready and upgrade-stable.
5
cloud/on premise, if you have standard abap repositories you can use
wrapper to make it cloud ready, using 3 tier extensibility.
6
Extensibility in ABAP
What is an Extension?
An extension adds additional functionality on top of the standard features
provided by SAP. It's important to understand that extensibility does not
involve modifying standard objects. Instead, it allows you to extend existing
functionality without altering the core SAP code.
7
Types of Extensibility in ABAP:
1. Classic Extensibility
Classic extensibility involves directly modifying standard SAP code through
enhancements, user exits, or modifications in classical ABAP.
This approach is not recommended because it violates the clean core
principle
In order to find about the object you can go to business accelerator hub
public cloud->on- stack extensblity.
8
application, developed on BTP, consumes these APIs to deliver additional
features or business processes.
9
Use cases of rap, I have primarily focused on common use case:
10
Answering wh questions of RAP:
What is rap?
It’s a framework used by abapers to build cloud ready Fiori application, odata
services, extension and etc. it works only from s4 hana 1909 system.
11
Since rap can be used only in eclipse ADT, First download eclipse adt:
Follow this steps to download: [Link]
install-adt..html
Then setups abap environment in you btp trial account:
[Link]
onboarding..html
Architecture of RAP:
12
Data Model:
Depending on the use case, data models support either transactional access
or query access to the database. Accordingly, they are used in business
objects (for transactional scenarios) or queries (for read-only scenarios).
Transactional access: refers to create, update, and delete (CRUD)
operations where you are modifying the database. If you are building a
transactional application (CRUD), then a BDEF is required.
Queries: refer to how you read data from the database. If you are
building a read-only application, a behaviour definition (BDEF) is not
mandatory.
Its not mandatory to mention vdm type, but it’s a good practice, These are
used to maintain a structural representation of cds view and define what role
particular cds view plays.
1. Basic View:
Represents the foundational data model; exposes raw data from
database tables and serves as a reusable building block for other views.
2. Composite View:
Builds on basic views by adding logic or combining basic view; used for
more specific domains like analytical processing.
Consumption View:
Tailored for specific use cases or applications, especially UI; delivers exactly
the data and annotations needed for consumption. These are nothing but
your projection view.
13
Data model for static data fetching: Managed Query
Have you ever wondered how data is fetched with querries like filters, top,
skip, or select while using CDS views as data models, even though you didn’t
write any specific logic for it?
This is possible because RAP uses the SADL framework , which automatically
handles these runtime queries. Since the framework handles the query logic,
this is known as a managed query—you don’t need to write custom code for
query handling.
14
Refer this link for unamnaged querry:
[Link]
entity..html
Projection View :
A projection view defines how data should be presented in an API or a Fiori
UI.
Metada extension:
It’s considered good practice to write UI annotations in a metadata extension
rather than directly on the projection view.
Why?
This approach helps separate the UI layer from the CDS logic, ensuring
better modularity.
It allows you to define multiple UI annotations for a single projection
view, providing greater flexibility.
If multiple metadata extensions exist, the one with the highest priority is
used. The priority is determined using the @[Link] annotation.
15
Refer this blog to learn in detail about metadata extension :
[Link]
applications/explaining-metadata-extension_e6f582d8-ee73-410a-9b96-
897452de936d
Why do we need a projection view? Can't we expose the interface view directly to
the UI?
The main reason for using a projection view is to introduce flexibility and
modularity. The interface view typically contains generic, reusable data and
logic, while the projection view allows for service-specific customization
Like:
You can add virtual elements (e.g., calculated fields) in the projection
view.
Refer this blog to learn about virtual elements:
[Link]
members/how-to-use-virtual-elements-in-abap-restful-application-
programming-model/ba-p/13532828
You can exclude certain fields that aren't needed in a specific application
or service.
This separation ensures that your interface view remains clean, reusable,
and generic, while the projection view adapts to the needs of each specific
service or application.
16
Types of Projection Views / Provider Contracts:
1. Transactional query:
Used for modeling the projection layer of a business object in the ABAP
RESTful Application Programming Model (RAP).
2. Transactional interfaces:
Usually used by SAP-released business objects for extensibility purposes.
These don’t have new associations or fields added to them; they are meant
to be extended. You can check the properties of the released consumption
view to understand how they are released and their provider contract in sap
accelarator hub.
Link:
[Link]
ws
3. Analytics query:
This is built only on top of analytical objects like cube or dimension CDS
views. These are specifically designed to run on the analytical engine.
Refer to this link to better understand projection view:
[Link]
views
Business object(BO):
17
BO stands for Business Object. For which business process did you create the
RAP application? For example, if you created an application to create Sales
Orders, then 'Sales Order' would be one of the BOs, and 'Items' and 'Partners'
would be other related BOs.
We refer to the parent node as the root, and the lowest-level child in the
hierarchy as the leaf.
Behaviour definition(Bdef ):
This will include all the characteristics of your Business Object (BO), such as
CRUD operations, action buttons to approve the sales order, validations to
check the character limit of the sales order, and determinations to calculate
the price based on amount and quantity, and so on.
In RAP, we have to create 2 BDEF, bdef interface on top of interface view and
bdef projection on top of projection view
Managed
In a managed scenario, the framework handles:
1. Create, Update, Delete (CUD) operations.
2. Transactional buffer management.
3. Full save sequence execution.
When to use:
For greenfield implementations — when starting from scratch.
Limited control — most logic is handled by the framework.
18
Handled by the framework:
1. CUD operations.
2. Transactional buffer.
Handled by the developer:
Developer manages the save sequence.
Unmanaged
In an unmanaged scenario, everything is handled by developer
1. CUD operations are written in the ABAP behavior pool.
2. Developer creates and maintains the transactional buffer (typically in
global class internal tables).
3. Save sequence is fully developer-driven.
When to use:
Ideal for brownfield implementations — reusing legacy code such as
classes, BAPIs, or function modules.
Offers complete developer control over logic and flow.
19
Behaviorur implementation:
In the BDEF, you only declare the characteristics of the Business Object (BO);
the logic is implemented in the ABAP Behavior Pool.
It is the class in which we write the logic for the behavior of the Business
Object (BO). As soon as you create the ABAP behavior class, a global class
(which is abstract and final) is automatically created along with a local class.
We will not write any logic in global class because Rap is strictly editable only
20
on eclipse. Local classes, which can only be edited in Eclipse, provide security and
control over the implementation. This is crucial because:
If we were to write code in a global class, it could be modified through the GUI,
which could introduce security risks and unwanted changes.
Note: A global class can contain one or more local RAP handler classes, but only
1 RAP saver class.
21
Structure of local class:
Local class is divided into local handler class and local saver class.
At the top of the BO API class hierarchy is CL_ABAP_BEHV, the foundation class
for both the handler and saver classes. This class defines:
Fundamental data types used in behaviour processing (e.g., field names in
derived type structures).
Methods for message creation .
The classes that inherit from CL_ABAP_BEHV include:
CL_ABAP_BEHAVIOR_HANDLER – The base class for the handler.
CL_ABAP_BEHAVIOR_SAVER – The base class for the saver.
Derived Types:
22
typically declare. Instead, they are called derived types. These are implicitly
derived by the ABAP compiler from the involved CDS views and the behavior
definition. To check the derived type, place the cursor on the method and
press F2. You will see the importing and changing parameters of the method.
These parameters are of derived types, and each derived type has its own
derived components.
Derived Components:
Internal structures and tables declared with derived data types do not
contain only key and data fields. They also include other components that
are not directly derived from the CDS entity's line type. These additional
components have special, tailor-made line types that provide extra
information required for transactional processing. The names of these RAP
components begin with a % symbol to avoid naming conflicts with
components of the CDS entities. We will see about each of the % components
as we proceed.
Service definition:
A business service definition (short form: service definition ) describes which CDS
entities of a data model are to be exposed. It can be either interface view or
projection view. If you don’t expose that searvice not be showed in application.
23
Service binding:
BO Runtime:
24
* Transactional Buffer: A runtime-generated temporary memory (not a physical
database). It holds raw data entered by the end user and is cleared once the data is
moved to the persistence table.
* Persistence Table: The database table on which the application is built. It is called
a persistence table because the records created in the application are ultimately
stored (persisted) in this table.
25
RAP: Draft
1. Odata services are rest api, which means they are stateless. They don’t store
any session data. Since its stateless,any termination in current session
cannot be recovered. For example lets say you are creating an sales order
with rap non-draft app. If the power is lost whatever changes you have
done is lost, because its stateless.
2. No feedbaack (eg; message,feature control) until “save” is triggered.
26
Locking in draft:
Exclusive lock:
Total Etag:
27
Why do we need Total etag, when we have etag master/dependent?
In draft bo, there are 2 tables, draft table and active table. When you want
draft bo to be consistent the total ETag value of the draft instance should be
compared to the total ETag value on the active instance. Only if the values
coincide can the draft be resumed. etag master/dependent validates only
etag in active table. So its mandatory to include Total etag in draft bo.
Bdef interface:
For child entity add assocaition with draft and etag dependent.
28
Bdef projection:
%key vs %tky :
Draft action:
Draft actions are actions that are implicitly available for draft business
objects. draft actions can be completely handled by the RAP framework, in
managed and in unmanaged implementation scenarios.
An application developer can add additional implementation for each draft
action if the addition with “additional implementation” is used.
Trigger conditions:
UI trigger points like edit,save button.
Triggered using eml execute action.
List of draft action :(refer end of the page to see detailed flow)
Edit action: When user clicks edit button, The data from active instance is
copied to draft table and exclusive lock is created.
29
Activate action: is the opposite of edit action, it is used to copy data from
draft instance to active instance ,deletes data from draft table and release
the exclusive lock.
Resume action: used to put exclusive lock, when user starts resuming from
modified session.
Discard action: Triggered when user clicks on discard button, it deletes the
data from draft table and release the exclusive lock.
Flow of draft :
1. When user clicks create button or trigered by eml with %is_draft = true, new
key is assigned and draft instance is created.
30
Draft table
2. If there is any termination of the session. The data will be in draft table.
3. Once you open the session again “Resume action” will place the exclusive
lock and you can fill in data.
4. Once you fill the fields and click on save, “Activate action” will be triggered
which will copy the data from draft instance to active instance and persisted
to persistance table. Then the draft data is discarded and exclusive lock is
release.
Persistence table
Draft table
1. When user click on edit button, “Edit action” is triggered, the data will be
copied from active instance to draft table.
Persistance table
31
Draft table
2. Once the user provides a value and clicks the 'Save' button, the 'Activate'
action will be triggered. This action moves the data from the draft instance
to the active instance, deletes the data from the draft table, and releases
the exclusive lock.
32
Edit action workflow for draft
33
Activate action workflow for draft
34
RAP: EML staments
1. In-local mode:
We know that both Modify and read eml will trigger the interactive phase of
rap. But if we don’t want to call the authorisation and feature control
methods, then we can use in-local mode.
2. Privieged mode:
If you want to use the privilaged mode additon in eml, your bdef interface
should have “with privilaged mode”.
In Bdef we will define certain auth object under privilage mode, if we use
the privilage mode in eml we will get exemption from the authorization
check for that auth object defined in bdef.
If you want to read only a single entity, then you can use read entity. In this
example you are reading the data from tx buffer which matches the key and
the corresponding result are added to lt_lfa2.
35
2. Read entities(long form)
If you want to read multiple entity of a bdef, then you mention the name of
the bdef interface and their corresponding entities( here zi_lfa1_2 and
zi_lfb1_2).
The dynamic form of the READ statement allows collecting multiple instances
to be read in multiple entities in one READ statement.
Op_tab, here is an operation table, where you provide whether it’s a read or
read by association in op field, the entity to be read in instance tab and the
output will be filled inside result tab.
36
4. Reading based on a table and based on a fixed value
Modify eml
When you want to change multiple records of a tx buffer. Use “create from
itab” syntax instead of running eml inside a loop, to reduce time
complexcity. Append all the records into an itab and run eml only once, this
way the code is optimized.
Use auto fill cid, if you don’t want to provide cid manually.
37
2. To hard code value
In scenerio where you need modify only few rows, you can use “with value
itab” syntax.
3. Create by association
38
Get permission eml:
If your commit should trigger only early save sequence, then use the
addition “in simulation mode”, this will execute only early save sequence
and not the save method.
39
Modify augmenting eml:(refer my augmnetatin blog)
40
RAP: Numbering
Early numbering:
The numbering type early numbering refers to an early value assignment for the
primary key field. In this case, the final key value is available in the transactional
buffer instantly after the MODIFY request for CREATE.
41
[Link] Internal Early Numbering:
• Managed early numbering is only possible for
key fields with ABAP type raw (16) (UUID) of
BOs with
implementation type managed.
• UUID is read-only.
syntax:
Syntax:
Bdef:
42
Local handler class:
Late numbering:
• The RAP runtime engine assigns values to the primary key fields.
• In the ABAP behaviour pool, the RAP saver method adjust_numbers must be
implemented to assign a final primary key value for each entity instance.
• The key value for an instance is assigned just before the instance is saved
on the database. Thus, a gapless assignment of unique keys is ensured.
• Late numbering is available for managed and unmanaged implementation
scenarios with and without draft.
Note:
• late numbering can't be external, since a consumer can't influence the SAVE
sequence after the point of no return.
43
• If draft enabled, it is mandatory that the RAP draft table has an
additional key field DRAFTUUID of data type raw (16).
Summary:
• passed externally by the application user: External numbering
• set internally by the framework: Managed internal
• set internally by developer (implementation the FOR-NUMBERING
method): Unmanaged Internal
44
Lockingin RAP
Concurrency Control
45
Optimistic Concurrency Control (E tag):
HowETagWorks:
Ex:Whenthebusinessobject“3eb9b5aa-d3ff-1edf-b583- f100044fee6b”is
accessed, a batch call fetches the "last changed at" timestamp.
46
checksthe E tagvalue
Etagismodifiedwithcurrenttimestamp
3. Ifthee tagdoesn’t match,it meansanotheruserhas
[Link], advisingthe user to
refreshbefore proceeding.
47
Variantsof E tag:
ETagMaster:
ETagDependent:
48
Whenchangesarerequestedforanetagdependententity, the systemchecks
thee tagvalue ofits masterentityto
ensure no conflictingchanges occurred.
Syntax:etagdependentby_Assoc
Total ETag
InaTotaletagscenario,whendraftinstancesareupdated, thesystemensures
thatonlythelatestversionof thedraft instance can be modified. This prevents
the issue where multipleusersmighttrytomodifydifferentversionsofthe
draft instance concurrently.
It’srecommendedtousebothTotaletagandetag
master/dependenttogetherindraftscenario.
Syntax: total e tag TotalEtagField
Etag definition
InBdefprojection,declare“useetag”toenableetag.
49
Authorization In RAP
Authorization:
In RAP, we primarily check whether the user has access to perform a specific
operation? and whether they have access to a particular business object
(BO)?.
Not all system has same way of creating auth object, for ex in private cloud
and on premise we use su21,pfcg. But in public cloud and abap environment
in btp we don’t have tcode. So I will provide links for each sytem to refer.
Abap environment/steampunk:
[Link]
authorization..html
50
means that if the user is not authorized to access the root BO, they are also
not authorized to access the corresponding child entity—and vice versa.
51
Detailed explanation with example:
In global authorization, we are restricting the update access for the entire BO. As
shown below, by passing 'requested_authorization' as‘01’for both update and
action, both the update and action buttons are disabled.
The approve and update button is disabled for the entire bo.
code
52
The update is disabled for bo(3eb9b5aa-d3ff-1edf-b583-f100044fee6b)
Code
53
Keys as importing parameter in instance authorization
In Precheck, we validate the incoming value (country: IN) for the selected BO (3eb9b5aa-
d3ff-1eef- b5b0-b978a97335af).
You can add authorization to action with the syntax ( authorization : global ) in bdef
For the Read operation, RAP architecture checks the authorization from DCL, and
for Modify, it checks from the behaviour implementation method.
54
Why authorization checks are not allowed in functions?
Function is used to read the data only, and for the Read operation, the DCL takes
care of authorization. Therefore, we do not need to mention authorization for
functions.
55
RAP: Action
What is action?
Actions are used to modify the BO without calling the standard operations
(CRUD buttons).
Trigger points:
1. Trigger via ui: In order to trigger the action via ui button.
Syntax:
Syntax of action:
Internal:
This means the action can be triggered only within the ABAP behavior pool (via
EXECUTE EML) and cannot be triggered externally from an OData or Fiori
application (through UI annotations).
56
Repeatable:
Used when you want to trigger the same action from within its own
implementation. The action calls itself using the EXECUTE EML statement. Each
time EXECUTE EML is triggered, the action will recursively call itself. Be careful
to handle this properly to avoid an infinite loop. This is only possible for non-
factory, instance actions.
57
Types of action:
1. Non-factory action:
Used to modify the existing Bo
By default, instance action. Need to explicitly provide static, for static
action.
Instance non-factory action is used to modify the selected BO.
Static non-factory action has access to modify any Bo, bound to the
entire entity.
Syntax:
58
1.1. Instance non-factory action:
Instance(you do the operation for the selected Bo only) + non-factory (not
creating any new record/bo)
To achieve it, I have declared instance non-factory action with abstract entity
as parameter, which provides the country code from user. Since, it's an
instance action, we would get the corresponding keys of the selected
BO(9e12812e-cf28-1fe0-81f6-be9f3d6f527b). We need to modify country
code(land1) via EML for the selected BO, with the input parameter from user.
Additionally, it is required to populate the result-derived type.
Action defined in BDEF:
59
Action method in abp:
Note:
Declared result as self, as the parameter result has the same type as
the entity for which the action is executed.
You can use deep parameter(only odata v4), if you want to modify
both parent and child entity.
Result parameter is optional, but if you have declared in BDEF interface,
its mandatory to pass result in action method, else in ui, you will get blank
value.
60
To achieve this, we can use a static non-factory action. First, we need to fetch
details from the persistence table for the BOs that have the country code set
to 'IN'. To modify the country, use t
2. Factory action:
Used to create a new Bo
Bound to the entire BO inside an entity
Instance factory action/copy action: Used to copy the existing Bo and
replicate new Bo.
Static factory action: used to create BO with some default value.
Syntax:
61
2.1. Instance factory action(Copy action):
Instance(you do the operation for the selected Bo only) + factory (creating an
new record/new bo).
To achieve this, we can use an instance factory action. Fetch the data from
the TX buffer to be copied using the read EML statement, and create a new
BO with a new key, while copying the remaining fields from the reference BO.
Since it’s a create operation, always pass %cid in the mapped derived type.
62
2.2. Static factory action:
Static (you do the operation for the entire Bo ) + factory (creating an new
record/new bo).
To achieve this, we can use the modify EML with default values and pass %cid
in the mapped parameter, as shown below:
63
3. Save action
Use case:
Save action is used in situations where you require to achieve certain
functionality without modify a transactional buffer.
Function:
Function is similar to action, but function is used for only reading purpose
and not modifying unlike action.
Since functions are similar to actions, I won't go into detail here. You can
refer to this blog for a more in-depth explanation.
Link: [Link]
64
RAP: Precheck
Precheck:
Note: when accessing an operation with the ABAP EML statement IN LOCAL
MODE, the precheck method is not called.
standard operations
operations for associations
actions
Precheck vs validation:
65
Steps to develop precheck:
66
Requirement: In Modify operation, restrict user to not provide country as US.
67
RAP: Default Values Functions
Note:
The paramters changes depending on where you are using it. Like for
instance importing parameter is keys and static %cid.
create
create by association
Action
Function
68
2. Implement the logic for Default values function in abap behaviour pool.
69
Requirement: To assign default value(country ‘DE’ and name ‘default’) in ui,
when the user clicks “create” button.
To achieve this, we have to append the default value in result. As its create
operation. Its mandatory to pass %cid. Depending on where you are using default
value function concept the parameters may vary and needs to be altered
accordingly.
70
RAP: Augmentation
Augmentation:
Note:
It is not possible to set a field in augment which was already set for the
original instance. For example, values set in the original request cannot be
changed. Only fields which are unset in the original request can be added.
It is not possible to set fields in augment that are defined as read only .
create
update
create by association
In Augmentation method,we cannot use a normal read, modify eml as the data is
not moved into tx buffer yet. So we need to use:
71
Flow of augmentation method in interactive phase:
Both Augmentation and determination are similar concept, as both are used to
modify the request based on some standard trigger condition. But here are some
differnces.
Augmentation Determination
Used to modify the request before Modifies the request after reaching
reaching transactional buffer. transactional buffer.
Used only in BDEF Projection Used only in BDEF Interface
Executed in interactive phase Can be executed in both interactive
and save sequence.
Only for create and update For create,update and delete
72
Steps to develop augmentation:
73
Requirement: If the user doesn’t provides value for field “name”, Then it should be
assigned with an default value “test”, in modify request.
74
Entities importing parameter.
75
RAP: Determination
Determination:
used to determine the value of certain entity based on the trigger condition.
Note:
The execution order of determinations is not fixed. If there is more than
one determination triggered by the same condition, the execution order
is arbitrary.
Once a determination has been triggered, it must run independently
from other determinations.
In unmanaged scenarios, determinations are only supported for
draft instances, not for active instances.
For determinations defined as on save, update works only in
combination with the trigger operation create.
Trigger conditions:
Create
Update
Deletee
Field modification
Good practices:
Don't change the field that is being triggered, as it could cause an infinite
loop. The trigger field and the calculation field should always be different.
For example, if you use 'field1' as the trigger field and then update the
same field within the method, it will trigger the method again, resulting
in an endless loop.
The trigger conditions can contain only fields of that entity. It
cannot contain fields of child / parent entity.
It is recommended to use either a trigger condition as a standard
operation or a field to avoid multiple calls. For example, if you have a
trigger condition set to 'update' and 'field1,' every time you update the
field, it will trigger the determination twice because you have two trigger
conditions.
76
Differnce between determination on modify and on save:
On modify On save
Executed just after the Executed before persisting on table.
modification of transactional
buffer.
Triggered before save and on save Triggered only at save
as well.
Executed in interactive phase Executed in save sequence.
Flow of determination:
77
Determination on save and finalize:
78
Requirement: If the user provides name as “Test1”, Then the country should be
“IN”.
79
RAP: Validation
Validation:
Trigger conditions:
Create
Update
Deletee
Field modification
Validation vs precheck:
80
Flow of validation:
Note: Validation logic for unmanaged scenarios should be written inside the
check_before_save method, while for managed scenarios, it should be
implemented in the validation method.
81
Steps to develop validation:
Requirement: The user should not provide a country code longer than 2 characters.
If they do, a warning message should be
displayed.
To achieve this, we have declared the validation with create as the trigger condition.
82
country. Now check the length and if the length is greater than 2 populate error
message in reported derived type.
83
RAP: Feature control
Feature control:
As the name suggests, you are controlling the features displayed in the UI, such as
fields and buttons.
Throughout the application the property you set for a ui element remains
same, for example: key should be always read-only, or some field is
mandatory.
84
2. Dynamic feature control:
1. Define the feature control for the operation required in bdef interface.
The feature of the ui element is determined based on the bo that user has
selected.
85
Detailed explanation with example:
Requirement: If the country of the selected bo is “In”, then disable the action
button.
When the feature of a UI element remains the same throughout the entire BO,
you can use a global feature. This is useful when you need to control UI
elements based on timing or user context.
Requirement: If the country of the selected bo is “In”, then disable the action
button.
86
For global authorization, the requested feature is the only input parameter,
while result and reported are changing output parameters.
In this example, I checked if the date is the 15th; if so, the "Create" button is
disabled.
87
RAP: Side effects
Before knowing what is side effect, we should know the problem statement.
When you click on save 2 calls happen first post call, then get call. So every
change you make will update in the db and reflect in ui.
But,in a draft scenario, any changes made at runtime on draft instance are
reflected in the draft table. However, these changes are not reflected in the
UI, as no GET call is triggered.
The only way to reflect the changes in ui, is to refresh the page. Because
once you render the ui. There will be a get call happening.
Why there is no get call, when we update the field in draft instance?
Because odata is stateless, it doesn’t store session data, so the frame work
doesn’t know whether you have changed or not. Only when you are
persisting the data in active table, the get call happens.
Example:
Now lets jump to the example. Here initially the bo has name as “Test_GE”
and country “GE”.
Now,If I click on edit button, there is draft instance created and data is
copied to draft table from active instace.(refer my draft blog to understand
how edit action works)
88
I will change the name to “Test_in” and tap enter. This will trigger a merge
call for determination. Since I have not clicked save button, neither it will
trigger save sequence or persist to active db. But the changes will be
available in draft table.
But since ther is no get call happened, the ui is not aware of the backend
change and still shows country as GE, whereas in draft table its changed to
IN.
Solution:
Side effect: now what side effect does, every time any change happen it
reloads only that particular field and triggers get call for that particular field.
So that the data in ui is consistent.
Side effects can be used with multiple combinations like action,
determination, determine action. I will take determination to explain with
an example.
Not only reload of fields, we can reload permission,message etc.
Syntax: mention the trigger and target: Here name1 is trigger and land1 is
target ex: side effects {field Name1 affects field Land1;}
89
Lets resolve the issue for the same example mentioned above.
1. Define side effects in bdef interface, For the above example, name1 is trigger
and land1 is target.
Now for the same example, lets try changing the name and check whether the
country is updated in runtime or not.
Now if we modify the draft instance, the changes are reflected in ui as well,
90
RAP: Facade
While practising rap we would have mostly worked on travel and booking
application where we persist the data directly in table. But in real buisness scenerio
we cannot directly persist it into an db, for ex: if you want to create purchase order,
you cannot directly build an rap application on top of ekko and persist the data into
ekko. In classical abap, we achieve it via bapi. But however if you are working on
cloud project. Its not advisable to use bapi.
Not only bapi, any repositary object which is of standard abap version and
not c1 released. Is not advisible to be used in cloud development.
Rap has its own LUW(RAP LUW), so providing commit statemnet on same
luw is not allowed( however this can be overcome using update fm wrapper
or bgpf ) and most of the bapis have their own commit statements.
Rap has lot of restriction on classical abap statements like(call screen,call
dialog), which are used in most of the bapi.
91
How do we achieve buisness operation in public cloud.
[Link]
workshops/blob/main/rap6xx/rap610/[Link]
92
To understand better lets look at the example:
2. Use modify entities to trigger the interctive phase workflow so that data is
moved to tx buffer.
3. Use commit entities to trigger the save sequence and persisting data from tx
buffer to db. Also provide final key statement for late numbering.
93
Code:
94
Output:
95
RAP: Background processing framework ( BGPF )
you are an end user and you are supposed to create a sales order with
sales order items. Now, let's say you create a sales order with 100 sales
order items. It takes a lot of time to create a sales order with this many
line items. You will be stuck on a loading page until the operation is
completed.
Solution:
Now, with the help of BGPF, you can run sessions asynchronously. This
means you can create a sales order in the background and still proceed
with creating another sales order while the previous one is processing.
You no longer have to wait on a loading screen. This is especially helpful
in scenarios involving large-scale processing.
Note: BGPF doesn’t make your processing faster, rather run it on background. So
that you can continue with other session.
Types of bgpf:
* controlled luw: is a key reason why classical ABAP is shifting toward RAP. In
classical ABAP, developers are responsible for ensuring data consistency manually.
In RAP, changes are made to the transactional buffer during the interactive phase,
and only consistent data is saved during the save sequence.
96
Working of Bgpf:
There are mainly 2 classes required for bgpf:operation class and starter class:
Starter class(in our case local saver class): does the operation and handover
to the bgpf.
Operation class: holds the logic to be executed asynchronouly in background.
97
Workflow of bgpf:
98
Steps:
2. After, the save sequence is executer Rap luw commit will happen. Then
your data will be persisted to persistence table. After which 2nd session will
run in background.
99
->1 st and 2 nd session
1. Go to abap cross trace, and create cross trace for background process:
100
2. After completion of bgpf, you can deactivate andcheck in results [Link]
would see both the sessions
101
RAP: Business event
For example, suppose there are two applications—one for managing shipping
and another for handling billing. If there is a requirement that a bill should be
generated as soon as a product is shipped, both applications need to
communicate with each other. This communication can be achieved using a
business event.
1. Define Event:
Define the event in the BDEF interface.
102
2. Raise event:
Event is raised in save sequence, so provide inside save method. Based on my
testing,I tried placing it in a few other methods within the save sequence,
and it appeared to work. However, when I tried raising the event in a method
from the interactive phase, it raised dump. So, try providing in save method
[Link] syntax is raise entity event and the event name and pass the values
to be passed to consumer.
3. Consume Event:
Event can be consumed in 2 ways:
Local Consumption:
In this case, the event is consumed within the same system. Events are
handled locally through an event handler class.
Remote Consumption:
Here, the event is consumed by other systems. This is typically done via
SAP Event Mesh, which allows events to be distributed across different
systems. Since Event Mesh is not available in the BTP trial version, I will
not include detailed steps for remote consumption in this document.
Refer this blog: [Link]
by-sap/how-to-create-rap-business-events-in-sap-s-4hana-on-premise-
2022/ba-p/13553312
Note:
To check the availability, pricing, or regional support for any service
provided by SAP BTP—such as Event Mesh—you can visit the SAP
Discovery Center:
[Link]
103
To consume the event, I have created a global class, which serves as the
event handler class. The syntax FOR EVENTS OF <BDEF> is used to handle the
events declared in the specified BDEF.
Global class
The actual logic is implemented inside a local class. To make the local class an
event handler class, it should inherit from cl_abap_behaviour_event_handler.
Then, create a method corresponding to the event you want to handle from
the BDEF.
I have written a MODIFY EML statement, which triggers the interactive phase
of the same application and creates a new record based on the parameters
passed. Typically, this is where we would write logic to interact with another
application. However, since I don’t have a second application, this example is
only intended to demonstrate that the event mechanism works—not to
represent a real-world use case.
Local class
104
Aunits for RAP
Aunits:
AUnits are unit tests written by ABAP developers to test each functionality of
their code. In RAP, AUnits are used to test functionalities such as validations,
determinations, actions, and CRUD operations etc. Your AUnits should aim
for maximum coverage of your code. It is recommended to follow TDD (Test
Driven Development), where you write the test cases first and then
implement the logic. This ensures that the test cases are based on the actual
requirements and are not influenced by the implementation.
Basics of Aunits:
Test classes can be either local or global. Unit tests should typically be
implemented as local classes within the program object that is being tested.
However, you can use global test classes to host reusable logic for unit tests
across different programs. In Eclipse ADT, there is a separate environment for
managing local test classes
105
For Testing: The addition FOR TESTING is used to identify a test class.
These are the classes that will be executed when you run ABAP Unit
tests. I will explain further how AUnits are triggered and how to execute
them.
Risk Level
CRITICAL:The test changes system settings or customizing data.
DANGEROUS:The test changes persistent data.
HARMLESS:The test does not change system settings or persistent
data.
Duration
SHORT:Execution time is imperceptible, expected to take only a few
seconds.
MEDIUM:Execution time is noticeable, around a minute.
LONG:Execution time is very noticeable, taking more than a minute.
Good Practices
It’s a good practice to have a separate method for each functionality,
with no dependencies inside the method. Each method should be
treated as a single test case.
Always include both positive and negative test cases.
106
Flow of test case:
CLASS_SETUP
This static method is executed once before the first test of the test
[Link] this method for fixtures that are time-consuming to create
and for which you are sure the settings will not be changed by any of
the test methods.
Example: Setting up a test double in the test environment.
SETUP
This instance method is called before each test of the test class. Use
this method for fixtures that you want to create fresh for every test
case.
Example: Creating an instance of the CUT (Class Under Test).
TEARDOWN
This instance method is called after each test of the test [Link] it to
undo changes made in the SETUP [Link] is especially important if
SETUP modifies persistent data (such as system configuration,
customizing, or master data).
Example: Clearing test doubles so that each test starts with fresh data.
CLASS_TEARDOWN
This static method is executed once after the last test of the test class.
Use it to clean up or destroy the test environment set up in
CLASS_SETUP, once all tests are completed.
Example: Tearing down the overall test environment.
107
How do we run test class:
To run abap units either execute abap unit test. This will trigger the test class.
If you run abap application it will not trigger test class.
108
Solution — Test Double Framework
So, how do we overcome this? Instead of relying on dependencies that are
beyond our control, we mock or stub these dependencies. This allows us to
influence how they behave and interact during testing, thereby avoiding test
case failures due to external dependencies. This approach is implemented
using the Test Double Framework.
The main purpose of both mock and stub is to not to test from actual data
but rather a fake data that we can configure. Because our test class will fail if
its dependent on real time data as it will be different in different
environment.
1. STUB: Stubs just provide predefined response.
2. MOCK: You design how the interaction should be. Like if you provide
this value this is how the output would be and also verify it.
I will now discuss in detail how we write ABAP Unit tests with a simple example.
Requirement:
Write a positive test case to check the validation check_country, which
should throw an exception if we pass a country code with more than 2
characters. Also, remove the dependency on the CDS view.
109
Steps
Identify CUT and dependencies
Here, I have taken a validation method as an example for testing. The CUT
(Code Under Test) is the validation method, and the dependency is the CDS
view. So, I will use the STUB methodology to configure the response of the
CDS view.
Note: This is just an example program. Typically, mocking, adding mock data,
and different functionalities would be implemented in separate methods. It
is not a good practice to combine everything into a single method. Each
method should have only one responsibility. Here, I have combined them
solely to showcase the concept.
110
111
Deploying rap application:
RAP applications are not directly consumed by end users from Eclipse ADT. They
are mostly consumed in the form of Fiori Launchpad (FLP) tiles.
Deploying applications in the Fiori Launchpad is a long process, so I recommend
referring to the official SAP documentation and videos for detailed steps. You can
also practice the deployment process using a BTP trial account.
2. ABAP Environment:
Deployment can also be done directly in the ABAP environment:
[Link]
[Link]
112