
What is determination in SAP?
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;
}
}
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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
20 | |
8 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 |