4

How to use side effects in RAP

 1 year ago
source link: https://blogs.sap.com/2023/02/23/how-to-use-side-effects-in-rap/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
February 23, 2023 1 minute read

How to use side effects in RAP

0 5 127

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.

RAP-Calculator.gif

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;
}

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;

}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK