Technical Articles
SAP ABAP RAP & Fiori Elements to refresh calculated fields without manual refresh ( Part – 2 )
The most common feature in building a transactional application is to calculate/ determine fields based on input from dependent fields.
In real business scenario, these fields can be from same entity or different entities.
In this example, calculated field Total Price is from the Parent (Ex. Travel) entity while dependent fields are Booking Fee from same entity and Flight price from Child ( Ex. Booking ) entity. User expects to see the calculated Total Price on entering/updating the Booking Fee without refreshing the page.
In most of the tutorials, we get the information on building apps with ABAP RAP.
In Part – 1 blog post, Implementation is described when both of them are in same entity.
In this blog post, Implementation is described when both of them are in different entities.
Prerequisites:
- Knowledge on ABAP Restful Application Programming to build basic List Repost Application
- Knowledge on Entity Manipulation Language (EML) to build calculation/determination logic in Application Layer
- Hands on experience in OpenSAP course Building Apps with the ABAP RESTful Application Programming Model
- Create a Fiori app described in Part -1 blog post
Implementation:
- Open the project created in previous blog in Business application Studio.
- Navigate to Go to local annotation xml in the path webapp/annotations/annotation.xml
- Add below annotations for Booking entity and place it after Travel entity.
<Annotations Target="cds_zui_rap_travel_789.BookingType" > <Annotation Term="Common.SideEffects" > <Record > <PropertyValue Property="SourceProperties" > <Collection> <PropertyPath>FlightPrice</PropertyPath> </Collection> </PropertyValue> <PropertyValue Property="TargetEntities" > <Collection > <NavigationPropertyPath >to_Travel</NavigationPropertyPath> </Collection> </PropertyValue> </Record> </Annotation> </Annotations>
- The complete file looks like below.
- Explanation :
- Annotation Term=”Common.SideEffects”
- PropertyValue Property=”SourceProperties”
- These are collections of properties that triggers determination of calculated property. In this example, it is Flight price from Booking entity
- PropertyValue Property=”TargetEntities”
- These are collection of entities that needs to be refreshed based on input of dependent property. In this example, Travel entity.
- Save the annotation file and preview the application .
- The implementation is ready now and check the behaviour of Total price on
- change of Flight price in Booking table in Travel page
- change of Flight price in Booking page
- Watch demo here. [ Video is compressed due to limitation of size ]
Now you learnt how dependent properties across entities can be refreshed automatically. Next challenge is to implement two such behaviours.
Nice, Thanks!
It's not working with me, can you share your code for determination? and for side effect should enabling draft.
Hello Maher,
Please see point #13 in Step 3. Implement the behavior pool for the Travel entity for the source code.
Hints to conclude if there is an issue in Determination or Side effects are
If it is not correctly filled, then issue is in Determination .
If it is correctly filled, then if there is any error in console in Developer tools of the browser.
Best wishes,
Ramjee Korada
Thanks for your reply, I followed the link you shared and added the annotation code as your blog part 1. But refresh happens after saving press, Can update the value after entering before saving? And till now I haven't activated the draft option.
Hi Maher,
As per below documentation,
Side effects for non-draft apps are supported. The side effects are triggered once the user saves the entity and the save action is successful.
https://help.sap.com/docs/ABAP_PLATFORM/468a97775123488ab3345a0c48cadd8f/18b17bdd49d1436fa9172cbb01e26544.html
Best wishes,
Ramjee Korada
HI Ramjee Korada ,
It does not work for me .
Note : the draft is enabled and i am using the odata v2 and the project is in sap web ide .
can you tell me what is the problem , please ?
In your Application does the Total Price calculation works on deletion of any row from booking table?
If yes please share the code.