RAP: Unmanaged Determination.

Estimated read time 8 min read

What is determination in SAP?

Determinations are used to execute specific business logic automatically whenever data in a business object changes.They help ensure that dependent values and calculated fields are correctly set when data is created, modified, or saved.We have 2 types in determinationOn Save: It will trigger during the time of saving the data into DB.On modify: It will trigger before saving the data into DB.

Steps to achieve determination Scenario: I have to calculate the total price based on car price and quantity field, If the car quantities are edited by user, the total price should be calculated. Based on the car price and quantity by using determination. We declare determination in behavior definition of interface view.

Behavior Definition:

 

unmanaged implementation in class zbp_sag_i_car unique;
strict ( 2 );
with draft;
define behavior for ZSAG_i_CAR
draft table zsag_dr_car
lock master total etag LastChangedAt
authorization master ( instance )
early numbering
{
create;
update;
delete;
determination total_price on modify { field Quantity; field CarPrice; }
side effects
{ field quantity affects field totalprice;
field CarPrice affects field TotalPrice; }
draft determine action Prepare { }
draft action Activate optimized;
draft action Discard;
draft action Edit;
draft action Resume;
field ( readonly ) totalprice, CarId;

mapping for zsag_dt_car control zsg_s_car
{
CarId = car_id;
CarBrand = car_brand;
CarModel = car_model;
CarPrice = car_price;
CukyField = cuky_field;
quantity = quantity;
totalprice = total_price;
LastChangedAt = last_changed_at;
}
}

 

Note: It is not mandatory to specify the CRUD operation inside {}, If we specify any CRUD operation such as create or update along with the fields as trigger conditions then the determination will be triggered multiple times on each create/update of any other fields in the same entity. Specifying only the fields as trigger condition will limit the call of determination on change of that of field only and will save the extra computation time and improve the application performance. We will get the warning after declaring determination so implement the method Implementation. 

 

determination total_price on modify { field Quantity; field CarPrice; }

 

Database Table:

 

@EndUserText.label : ‘Car table’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED

define table zsag_dt_car {
key clnt : abap.clnt not null;
key car_id : abap.char(8) not null;
car_brand : abap.char(20);
car_model : abap.char(20);
@Semantics.amount.currencyCode : ‘zsag_dt_car.cuky_field’
car_price : abap.curr(7,2);
cuky_field : abap.cuky;
quantity : int1;
@Semantics.amount.currencyCode : ‘zsag_dt_car.cuky_field’
total_price : abap.curr(7,2);
last_changed_at : abp_locinst_lastchange_tstmpl;
}

 

Projection View:

 

projection;
strict ( 2 );
use draft;
use side effects;
define behavior for ZSAG_C_CAR
{
use create;
use update;
use delete;
use action Prepare;
use action Activate;
use action Discard;
use action Edit;
use action Resume;
}

 

Read Method:

 

METHOD read.
SELECT FROM zsag_DT_CAR
FIELDS *
FOR ALL ENTRIES IN
WHERE car_id = -CarId
INTO
TABLE (lt_result).
result = CORRESPONDING #( lt_result MAPPING TO ENTITY ).
ENDMETHOD.

 

For Calculating ‘Total Price’ method:

 

METHOD for_total_price.
READ ENTITY IN LOCAL MODE zsag_i_car
ALL FIELDS WITH
CORRESPONDING #( keys )
RESULT DATA(lt_res).
DATA(ls_res) = VALUE #( lt_res[ 1 ] OPTIONAL ).
IF ls_res-Quantity IS NOT INITIAL.
ls_res-TotalPrice = ls_res-Quantity * ls_res-CarPrice.
MODIFY ENTITY IN LOCAL MODE zsag_i_car
UPDATE
FIELDS ( TotalPrice )
WITH VALUE #( ( %tky = ls_res-%tky
TotalPrice = ls_res-TotalPrice ) ).
ENDIF.
ENDMETHOD.

 

Save:

 

METHOD save.
IF lhc_ZSAG_i_CAR=>lt_create IS NOT INITIAL.
INSERT zsag_dt_car FROM TABLE @lhc_ZSAG_i_CAR=>lt_create.
ENDIF.
IF lhc_ZSAG_i_CAR=>lt_delete IS NOT INITIAL.
DELETE zsag_dt_car FROM TABLE @lhc_ZSAG_i_CAR=>lt_delete.
ENDIF.
IF lhc_ZSAG_i_CAR=>lt_update IS NOT INITIAL.
UPDATE zsag_dt_car FROM TABLE @lhc_ZSAG_i_CAR=>lt_update.
ENDIF.
ENDMETHOD.

 

OUTPUT:

While creating a record:

If user click on enter, the determination logic will get triggered based ON MODIFY and side effects statements:

After clicking on ‘Create’ button the record will store in database. 

NOTE: If you are using Determination ‘on save’, you need to include Determination method in the Draft prepare action.

Conclusion: 

Use determinations for automatic field derivations and validations during lifecycle operations instead of coding logic manually in the application layer. 

 

​ What is determination in SAP? Determinations are used to execute specific business logic automatically whenever data in a business object changes.They help ensure that dependent values and calculated fields are correctly set when data is created, modified, or saved.We have 2 types in determinationOn Save: It will trigger during the time of saving the data into DB.On modify: It will trigger before saving the data into DB.Steps to achieve determination Scenario: I have to calculate the total price based on car price and quantity field, If the car quantities are edited by user, the total price should be calculated. Based on the car price and quantity by using determination. We declare determination in behavior definition of interface view.Behavior Definition: unmanaged implementation in class zbp_sag_i_car unique;
strict ( 2 );
with draft;
define behavior for ZSAG_i_CAR
draft table zsag_dr_car
lock master total etag LastChangedAt
authorization master ( instance )
early numbering
{
create;
update;
delete;
determination total_price on modify { field Quantity; field CarPrice; }
side effects
{ field quantity affects field totalprice;
field CarPrice affects field TotalPrice; }
draft determine action Prepare { }
draft action Activate optimized;
draft action Discard;
draft action Edit;
draft action Resume;
field ( readonly ) totalprice, CarId;

mapping for zsag_dt_car control zsg_s_car
{
CarId = car_id;
CarBrand = car_brand;
CarModel = car_model;
CarPrice = car_price;
CukyField = cuky_field;
quantity = quantity;
totalprice = total_price;
LastChangedAt = last_changed_at;
}
}  Note: It is not mandatory to specify the CRUD operation inside {}, If we specify any CRUD operation such as create or update along with the fields as trigger conditions then the determination will be triggered multiple times on each create/update of any other fields in the same entity. Specifying only the fields as trigger condition will limit the call of determination on change of that of field only and will save the extra computation time and improve the application performance. We will get the warning after declaring determination so implement the method Implementation.  determination total_price on modify { field Quantity; field CarPrice; }  Database Table: @EndUserText.label : ‘Car table’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED

define table zsag_dt_car {
key clnt : abap.clnt not null;
key car_id : abap.char(8) not null;
car_brand : abap.char(20);
car_model : abap.char(20);
@Semantics.amount.currencyCode : ‘zsag_dt_car.cuky_field’
car_price : abap.curr(7,2);
cuky_field : abap.cuky;
quantity : int1;
@Semantics.amount.currencyCode : ‘zsag_dt_car.cuky_field’
total_price : abap.curr(7,2);
last_changed_at : abp_locinst_lastchange_tstmpl;
}  Projection View: projection;
strict ( 2 );
use draft;
use side effects;
define behavior for ZSAG_C_CAR
{
use create;
use update;
use delete;
use action Prepare;
use action Activate;
use action Discard;
use action Edit;
use action Resume;
}  Read Method: METHOD read.
SELECT FROM zsag_DT_CAR
FIELDS *
FOR ALL ENTRIES IN
WHERE car_id = -CarId
INTO
TABLE (lt_result).
result = CORRESPONDING #( lt_result MAPPING TO ENTITY ).
ENDMETHOD. For Calculating ‘Total Price’ method: METHOD for_total_price.
READ ENTITY IN LOCAL MODE zsag_i_car
ALL FIELDS WITH
CORRESPONDING #( keys )
RESULT DATA(lt_res).
DATA(ls_res) = VALUE #( lt_res[ 1 ] OPTIONAL ).
IF ls_res-Quantity IS NOT INITIAL.
ls_res-TotalPrice = ls_res-Quantity * ls_res-CarPrice.
MODIFY ENTITY IN LOCAL MODE zsag_i_car
UPDATE
FIELDS ( TotalPrice )
WITH VALUE #( ( %tky = ls_res-%tky
TotalPrice = ls_res-TotalPrice ) ).
ENDIF.
ENDMETHOD.
 Save: METHOD save.
IF lhc_ZSAG_i_CAR=>lt_create IS NOT INITIAL.
INSERT zsag_dt_car FROM TABLE @lhc_ZSAG_i_CAR=>lt_create.
ENDIF.
IF lhc_ZSAG_i_CAR=>lt_delete IS NOT INITIAL.
DELETE zsag_dt_car FROM TABLE @lhc_ZSAG_i_CAR=>lt_delete.
ENDIF.
IF lhc_ZSAG_i_CAR=>lt_update IS NOT INITIAL.
UPDATE zsag_dt_car FROM TABLE @lhc_ZSAG_i_CAR=>lt_update.
ENDIF.
ENDMETHOD.  OUTPUT:While creating a record:If user click on enter, the determination logic will get triggered based ON MODIFY and side effects statements:After clicking on ‘Create’ button the record will store in database. NOTE: If you are using Determination ‘on save’, you need to include Determination method in the Draft prepare action.Conclusion: Use determinations for automatic field derivations and validations during lifecycle operations instead of coding logic manually in the application layer.    Read More Application Development Blog Posts articles 

#SAP

You May Also Like

More From Author