When a user modifies the content of a field, and it affects the other fields in the UI. This is known as a side effect.
Side Effects annotations indicate which targets are to be refreshed in order to display updated values. These field values change due to the change of a field, action, or decision action. There are various ways to annotate side effects by combining the triggers and the affected components.
When a user modifies the data of draft instance on UI, it is not necessary that all the fields will trigger a READ request. This could result in inconsistent data display on the draft instance. This situation can be overcome by the use of side effects.
The following RAP BO attributes have side effects that can be defined in the base behavior definition:
Example:
– side effects { field MyField affects field Targets, messages; }
– side effects { field MyField affects entity Targets, messages; }
– side effects { field MyField affects $self, messages; }
Example:
– side effects { action MyAction affects field Targets, messages; }
– side effects { action MyAction affects entity Targets, messages; }
– side effects { action MyAction affects $self, messages;}
Example:
– side effects { determine action MyDetermineAction executed on sources affects Targets, messages; }
When the user changes the value of InputDays
, the determination CalculateDate
is called and modifies the values of OutputDate
by adding InputDays in CurrentDate. In order to show the updated values without a refresh, side effects is required.
Step 1 – Add a statement to your behavior definition in which you indicate which RAP BO fields are affected by other fields.
Code Snippet for Behavior Definition –
side effects
{
field InputDays affects field OutputDate;
}
determination CalculateDate on modify { field InputDays; }
Step 2 – Add ‘use side effects’ in the behavior projection to enable the side effects.
Code Snippet for Behavior Projection –
projection;
strict ( 2 );
use draft;
use side effects;
define behavior for ZC_Calculate_Date alias CalculateDate
use etag
{
use create;
use update;
use delete;
use action Edit;
use action Activate;
use action Discard;
use action Prepare;
use action Resume;
}
During User Input –
Output
I would encourage you to read through other blog posts on such topics at: https://blogs.sap.com/tags/7e44126e-7b27-471d-a379-df205a12b1ff/
You can post and answer questions on related topics at: https://answers.sap.com/tags/7e44126e-7b27-471d-a379-df205a12b1ff
Please provide your feedback and ask questions in the comment section.
Regards,
Anubhav Jain