RAP - Real Time UI Updates Using Event-Driven Side Effects
Hello Everyone! 👋
Real-Time UI Updates in RAP Using Event-Driven Side Effects
We've all come across situations where something changes in the backend, and we want those updates to automatically reflect in the UI without manually refreshing the page.
In traditional setups, we used ABAP Channels for this but how can we achieve the same in RAP?
Here's a simple example: I'm updating the travel status in one class/report, while the app is open in parallel. As soon as the status is updated in the backend, it automatically reflects in the UI no refresh needed! This is made possible through Event-Driven Side Effects.
This is useful when:
- Background jobs update data
- We want to notify users with messages in real time
- Multiple users are working on the same data simultaneously
Step 1 – Add the event-driven side effects in the BDEF
managed with additional save ....
..
define behavior for YR_YABS_TRAVEL alias Travel
....
{
....
event StatusChanged for side effects;
side effects { event StatusChanged affects field OverallStatus; }
}
Step 2 – Expose the Event and side effects in the Projection BDEF
....
use side effects;
define behavior for YC_YABS_TRAVEL alias Travel
...
{
....
use event StatusChanged;
}
Step 3 – Raise the event in the save_modified of BIL Class
Note: We can raise entity events only at the save sequence.
METHOD save_modified.
IF update-travel IS NOT INITIAL.
LOOP AT update-travel ASSIGNING FIELD-SYMBOL(<travel>).
IF <travel>-%control-OverallStatus = if_abap_behv=>mk-on.
RAISE ENTITY EVENT yr_yabs_travel~StatusChanged
FROM VALUE #( ( %tky = CORRESPONDING #( <travel>-%key ) ) ).
ENDIF.
ENDLOOP.
ENDIF.
ENDMETHOD.
Whenever we update the status field from EML from another class, report, or jobs, this save_modified will get triggered. Based on the status change indicator, we are raising an event, and this event will affect the status field. So the new status will be displayed in the page automatically.
Sample (Trigger) Code
CLASS ycl_travel_gen_data DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ycl_travel_gen_data IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
MODIFY ENTITIES OF yr_yabs_travel
ENTITY Travel
UPDATE FIELDS ( OverallStatus )
WITH VALUE #( ( TravelID = '00000001'
OverallStatus = 'A' ) )
REPORTED DATA(lt_reported)
FAILED DATA(lt_failed).
COMMIT ENTITIES.
out->write( 'Status updated' ).
ENDMETHOD.
ENDCLASS.
How It Works
- The trigger code updates the OverallStatus field using EML.
- The save_modified method detects the change and raises the StatusChanged event.
- The event triggers the side effect, which automatically updates the UI field.
- Users see the updated status in real-time without refreshing!
🎥 Demo: Event Driven Side Effects
Note:
Event-Driven Side Effects are available in SAP BTP ABAP Environment and SAP S/4HANA Public Cloud,
and from release 2025 also in on-premise and private cloud systems.
#RAP #ABAP #SAPFiori #S4HANA #SideEffects #EventDriven #RealtimeUpdates
Thank you very much Balaji ! In my experience, backend side effects fail a lot compared to front end ones. If this works, it will be a game changer !
ReplyDelete