BO Behavior – Determinations
The RAP framework invokes the Determination when its trigger condition is met. Trigger conditions can include modify operations and modified fields.
In this tutorial, we are going to set status to “Open” when creating new travel records. If you want to learn more on determination check out our detailed explanation on What is determination in the RAP?
Let’s first modify Behavior Definition ZR_RAPTECH_TRAVEL with below code
In this tutorial, we are going to set status to “Open” when creating new travel records. If you want to learn more on determination check out our detailed explanation on What is determination in the RAP?
Let’s first modify Behavior Definition ZR_RAPTECH_TRAVEL with below code
determination setStatusToOpen on modify { create; }


Implementing logic to set new travel records to Open by default
Now it’s time to implement code under method setStatustoOpen, before that let’s first define some constant variables under private section which we are going to use in our method.
CONSTANTS:
BEGIN OF travel_status,
open TYPE c LENGTH 1 VALUE 'O', "Open
accepted TYPE c LENGTH 1 VALUE 'A', "Accepted
rejected TYPE c LENGTH 1 VALUE 'X', "Rejected
END OF travel_status.

We need to fetch list of records from Travel Entity based on keys, add below code under setStatustoOpen method.
" Fetch data based on keys from Travel Entity
READ ENTITIES OF ZR_RAPTECH_TRAVEL IN LOCAL MODE
ENTITY Travel
FIELDS ( OverallStatus )
WITH CORRESPONDING #( keys )
RESULT DATA(travels)
FAILED DATA(read_failed).
Now check if records don’t have Overall status set already, if it is set then remove those records before proceeding further.
"If overall travel status is already set, do nothing, i.e. remove such instances
DELETE travels WHERE OverallStatus IS NOT INITIAL.
CHECK travels IS NOT INITIAL.
Now its time to modify rest all records with Overallstatus = ‘O’. Add below lines of code to so same.
"Set records to Open
MODIFY ENTITIES OF ZR_RAPTECH_TRAVEL IN LOCAL MODE
ENTITY Travel
UPDATE FIELDS ( OverallStatus )
WITH VALUE #( FOR travel in Travels ( %tky = travel-%tky
OverallStatus = travel_status-open ) )
REPORTED DATA(update_reported).
"Set the changing parameter
reported = CORRESPONDING #( DEEP update_reported ).

" Fetch data based on keys from Travel Entity
READ ENTITIES OF ZR_RAPTECH_TRAVEL IN LOCAL MODE
ENTITY Travel
FIELDS ( OverallStatus )
WITH CORRESPONDING #( keys )
RESULT DATA(travels)
FAILED DATA(read_failed).
"If overall travel status is already set, do nothing, i.e. remove such instances
DELETE travels WHERE OverallStatus IS NOT INITIAL.
CHECK travels IS NOT INITIAL.
"Set records to Open
MODIFY ENTITIES OF ZR_RAPTECH_TRAVEL IN LOCAL MODE
ENTITY Travel
UPDATE FIELDS ( OverallStatus )
WITH VALUE #( FOR travel in Travels ( %tky = travel-%tky
OverallStatus = travel_status-open ) )
REPORTED DATA(update_reported).
"Set the changing parameter
reported = CORRESPONDING #( DEEP update_reported ).
Save and Activate the class and lets test it. Run you Travel Service and try to create new record.

Hooray!!! you have learned how to write determination in RAP. Don’t forget to complete entire series of RAP Tutorial