How to use Side Effects in ABAP Restful Application Programming Model
source link: https://blogs.sap.com/2022/11/09/how-to-use-side-effects-in-abap-restful-application-programming-model/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to use Side Effects in ABAP Restful Application Programming Model
Hello,
In this beginner blog post we are going to see how we can use Side Effects in ABAP Restful Application Programming Model.
What is Side Effects :
When user makes a change to a field on UI, and this change effect the content of other field, this behavior is called Side Effect.
Annotation to Implement Side Effects:
Some more annotation properties are available but for this demo we are only using below 2 Annotations properties.
Source properties | Properties on which you want to trigger Side Effect behavior. Source properties are responsible to trigger Determination on action (on modify) |
Target properties | Properties you want to manipulate as a result of Side Effects. Target properties contains fields which are updated or modified as result of Determination. |
Implement Determination logic:
Implementing Determination Logic to update Salary based on Role. The problem statement is – when user change Role from Teacher <-> Professor then Salary should be updated without refresh of full page.
Above requirement can be achieved by using Side Effects to update dependent field.
1- In behavior Definition file added Determination with method name changeSalary and action “on modify” with source property as Role.
Determination changeSalary will be triggered as soon as Role property is changed.
Create Service API V4
2- To create Service API V4 to use in Fiori Application. Create new Service Binding.
Once created Activate and Publish Local Service Endpoints.
3- Now we are going to create Fiori Application where we will be using this V4 API.
Create New Fiori Application using Template
Select Service created in previous steps.
Click Next. Select main Entity
Create Module and fill all required Information and click on Finish.
Once Module is ready. Open Annotations Folder and then Annotations.xml file
Update below SideEffects annotation to file.
<Annotations Target=".....">
<Annotation Term="Common.SideEffects">
<Record>
<PropertyValue Property="SourceProperties">
<Collection>
<PropertyPath>Role</PropertyPath>
</Collection>
</PropertyValue>
<PropertyValue Property="TargetProperties">
<Collection>
<PropertyPath>Salary</PropertyPath>
</Collection>
</PropertyValue>
</Record>
</Annotation>
</Annotations>
To add namespace click on QuickFix option.
Click on Availablable option to add Namespace for SideEffects Annotation.
Everything is done. Now run the Application.
Application is loaded.
For Role teacher Salary is 10,000
Change Role to Professor and Hit ENTER, Salary will be updated
Conclusion:
If requirement is to update some of the properties depending on value of other property on UI, SideEffects annotation can be used.
Benefit of using Side Effects :
- When updating 1 or 2 fields on UI based on values of other field does not need full page to be refreshed.
- Can be Implemented quickly by using Annotation called SideEffects.
- Performance Improvement, since we are not refreshing full page to refresh single dependent field.
- Side Effects can be Implemented in Fiori Elements
Thanks-
Abhishek
Recommend
-
92
Technical Articles
-
5
Renzo Colle June 27, 2022 6 minute read ...
-
7
Abhishek Sharma October 6, 2022 3 minute read...
-
6
Frequently Asked Questions This document answers the most frequently asked questions around the ABAP RESTful Application Programming Model (RAP) which offers a standardized programming model to efficientl...
-
2
Intro Hello everyone ! In this blog I am going to talk about RAP model –RESTful ABAP Programming Model. As described by SAP :- The ABAP RESTful Application Programming Model (in short RAP) defines the archi...
-
11
Rajat verma January 4, 2023 3 minute read ...
-
8
Hello, In this beginner blog post we are going to see how we can use #CHANGE_SET (Change Set Processing) in ABAP Restful Application Programming Model. Use Case: Change Set processing can be...
-
4
Abhishek Sharma January 24, 2023 7 minute read...
-
9
Abhishek Sharma February 13, 2023 8 minute read...
-
4
Last edit: 2023-02 This blog is about recommendations for building modern applications and Web APIs with RAP on SAP Business Technology Platform (BTP) ABAP Environment – aka Steampunk – and SAP S/4HANA. A. W...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK