Skip to Content
Technical Articles
Author's profile photo Ramjee Korada

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:

Implementation:

  1. Open the project created in previous blog in Business application Studio.
  2. Navigate to Go to local annotation xml in the path webapp/annotations/annotation.xml
  3. 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>
  4. The complete file looks like below.
  5. 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.
  6.  Save the annotation file and preview the application .
  7. 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
  8. 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.

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Stephan Heinberg
      Stephan Heinberg

      Nice, Thanks!

      Author's profile photo Maher Wahid
      Maher Wahid

      It's not working with me, can you share your code for determination? and for side effect should enabling draft.

      Author's profile photo Ramjee Korada
      Ramjee Korada

      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

      1. To refresh/reload the page and see if the value is correctly filled.
      2. To put a breakpoint and see if the value is correctly calculated.

      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

       

      Author's profile photo Maher Wahid
      Maher Wahid

      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.

      Author's profile photo Ramjee Korada
      Ramjee Korada

      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

      Author's profile photo amr alaa
      amr alaa

      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 ?

       

      Author's profile photo MANEESH SINGH
      MANEESH SINGH

      In your Application does the Total Price calculation works on deletion of any row from booking table?

      If yes please share the code.