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.
GitHub Repository
I have published the source code on GitHub in the following repository:
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;
}