Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
12,146

How to use side effects in RAP


A long awaited feature became available with the latest upgrade to 2302 of the SAP BTP, ABAP Environment and SAP S/4HANA ABAP Environment systems.

It is now possible to configure side effects in the behavior definition of your RAP business object.

This feature (amongst lots of other cool features 😉 ) is also implemented in the SAP Fiori Elements Feature Showcase App:

The SAP Fiori Elements feature showcase with RAP and ABAP CDS annotations | SAP Blogs

Feature Showcase App Guide · SAP-samples/abap-platform-fiori-feature-showcase Wiki (github.com)

and we now also have a very comprehensive video available that explains this feature in more detail as well

RAP Side Effects in a Nutshell | SAP Blogs

 

RAP calculator app using side effects


 




For demo and educational purposes I have build a simple example of a RAP based calculator app.

Here you can add two operands and an operator ( +, - , * or / ).

When changing one value, either one operand or the operator the data in the results field will be changed.

This app you can build yourself based on the table that is listed at the end of this post.

Once you have generated the RAP BO you only have to add the
side effects

{

}

statement to your behavior definition where you list which field is effected by another field of your RAP BO.
side effects
{
field OperandA affects field CalcResult;
field OperandB affects field CalcResult;
field Operator affects field CalcResult;
}

determination CalculateCalcResult on modify { field OperandA, OperandB, Operator; }

And in the behavior projection you have to enable the use of side effects by adding a
use side effects;

statement.
projection;
strict ( 2 );
use side effects;
use draft;

define behavior for ZC_CalculatorTP_01 alias Calculator
use etag

{
use create;
use update;
use delete;

use action Edit;
use action Activate;
use action Discard;
use action Resume;
use action Prepare;
}

SAP Online Help


More information can be found in the SAP Online Help

Side Effects | SAP Help Portal

Table


@EndUserText.label : 'Pocket Calculator'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zcalculator {

key client : abap.clnt not null;
key calc_uuid : sysuuid_x16 not null;
operand_a : abap.int4;
operand_b : abap.int4;
operator : abap.char(1);
calc_result : abap.fltp;
created_at : abp_creation_tstmpl;
created_by : abp_creation_user;
last_changed_by : abp_lastchange_user;
last_changed_at : abp_lastchange_tstmpl;
local_last_changed_at : abp_locinst_lastchange_tstmpl;

}

 

 

 
14 Comments
Prashant4
Explorer
Thanks Andre for sharing this. It's a needed functionality in RAP.
saikrishnaravi010
Associate
Associate
0 Kudos
Hi Andre

One question how to define side effects on multiple fields ?

For instance field 1 affects field 2 ; field 3 ;

 

Regards

Sai
0 Kudos
Hi Andre,

I tried to use the same in SAP 2020 on-premise, It is not working.

How can I use this feature in my version?

Best Regards,

Anil.

 
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Defining side effects in the behavior definition is not supported in on premise releases so far.

It is planned to be supported with the next upcoming on premise release where features of the current cloud release 2302 will be shipped with.

In on premise releases you unfortunately still have to create side effect annotations in the UI project using business application studio.

 

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos
The syntax is the following (taken from the SAP Fiori Elements feature showcase app).


side effects {

field IntegerValue affects field ProgressIntegerValue, field RadialIntegerValue;

field NavigationID affects entity _Navigation;

action resetTimesChildCreated affects field TimesChildCreated, permissions ( action resetTimesChildCreated );

determine action validateDate executed on field ValidTo affects messages;

determine action validateChild executed on entity _Child affects messages;

}




 
Quick question: Can we use side effects in the Embedded abap (3SL) stack of s/4hana cloud ? it will be great feature to experiment this against s/4hana public cloud with the support of embedded abap stack, i love it if it works.
yogeendar
Explorer
Hi Andre,

 

It seems currently Side Effects are available only for Draft enabled BO.

Is there a way to use Side Effects in Non-Draft BO? I am using Managed Scenario without draft in S/4 Public Cloud and want to recalculate some fields on UI dynamically, but neither Determination on Modify nor Side effects are working. Any suggestions on this?

 

Regards,

Yogeendar
scott_bleier
Explorer
0 Kudos
Hi Andre - I have the same question as Yogeendar Rao.  Have you heard any update around supporting side-effects on non-draft RAP applications?  This is a very useful feature but often we have apps that do not require draft programming but we still need this feature.  I could not find anything on the roadmap - do you happen to know if side-effects will be supported for non-draft apps in the future?

Thanks -
Scott
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Scott,

it is not clear to me how a side effect could be used in a non-draft application.

Because in this case the data is only sent to the backend as part of the save sequence.

A side effect does the following.

When field A changes then a new value for field B has to be calculated.

This calculation happens in the backend.

By defining the side effect, the UI is informed via the metadata that if field A changes it has to perform a GET request in order to read the newly calculated data from the backend.

If no draft is used there is no communication between the UI and the backend before the SAVE takes place.

That means that neither the content of field A is sent to the backend nor that field B is newly calculated.

So how shall a side effect work in this case?

Kind regards,

Andre

 
scott_bleier
Explorer

Hi Andre - Thank you for the reply.  It makes sense what you say in terms of the communication with the backend.  In our non-draft scenario, we would like to use a "side-effect" concept to update the UI with calculated or determined fields before the user sends the final request to save the data in the backend (so purely a UI screen update initially).  In many cases, we have a situation where a user updates a front-end field manually (types in a value) and this value determines several other screen field values they would like to see before hitting "save" to trigger the back-end update.  Currently, we are handling this type of UI update via java script (so only UI fields are updated with values on the screen - no backend update is triggered until user hits "save").  In some cases, we use a value help with binding to other fields in the UI and this works well when appropriate.

We were hoping it might be possible to use a "side-effect" type annotation in the future to avoid the need for constant Javascript coding.  Perhaps there is another approach we missed that would be better?  Basically we need to trigger a back-end "get" request for certain fields after a user updates a field or collection of fields so we can update related screen fields.  In many cases, users would like the UI updated before the "save" sequence is triggered.

Let me know your thoughts.
Thanks,
Scott

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
Thanks for the detailed explanation of your use case.

I'll check with my colleagues if there's anything I might have overlooked.

But what hinders you to add draft support to your app?
scott_bleier
Explorer

Hi Andre - we are actually considering updating the app to handle draft support but this would entail quite a bit more effort.  This particular RAP app is a RAP façade calling a legacy BAPI so it's not a pure RAP core app (thus adding the draft tables and support would require special effort).  We've been evaluating this effort so we can leverage using side effects which have significant advantages.  Currently, the users do not require any draft handling for this application but there are of course benefits to enabling drafts.   For now it's just an evaluation of adding draft capabilities against leaving the current design in place with Javascript UI updates so we'd thought we'd solicit your advice and at least ascertain as to whether side effects might be supported in a non-draft use case (as this gives us another path to consider).

We appreciate the feedback.

Best regards,
Scott

adam_hartwig
Discoverer
0 Kudos

Hey Andre,
great post, thank you very much!!!
I tried it straight away.
Unfortunately my virtual fields are not updating.
Is this possible with side effects?
If not, how do I recalculate the virtual fields after a change in a field?
Thank you!
br Adam

Robert_Schulte
Explorer
0 Kudos

Hello Andre,

maybe can you give me a hint what i need to do to achieve the following (or tell me that it is not possible atm).

I have a draft enabled complex RAP entity and on its object page, inline editing of its text table is possible. In the header section i show the root entities ID together with its localized text.

Is there a way to achieve that when i press enter after changing the text in logon language - means: saving draft is triggered - to also update the field in the header?

What works is changing the entry, pressing enter, navigating into it's details and back.

Talking about BTP ABAP 24xx.

Best regards,

Robert