In the previous exercise, you've defined and implemented the early numbering for assigning automatically an identifier (ID) for a new instance of the BO entity Travel (see Exercise 3).
In the present exercise, you will define and implement a determination, setStatusToOpen
, which will be used to set a default value for the overall status of a Travel entity instance. You will use the Entity Manipulation Language (EML) to implement the transactional behavior of the Travel business object.
- 4.1 - Define the Determination
setStatusToOpen
- 4.2 - Implement the Determination
setStatusToOpen
- 4.3 - Preview and Test the Enhanced Travel App
- Summary
Reminder: Do not forget to replace the suffix placeholder
###
with your choosen or assigned group ID in the exercise steps below.
A determination is an optional part of the business object behavior that modifies instances of business objects based on trigger conditions. A determination is implicitly invoked by the RAP framework if the trigger condition of the determination is fulfilled. Trigger conditions can be modify operations and modified fields.
Further reading: Determinations
The Entity Manipulation Language (EML) is an extension of the ABAP language which offers an API-based access to RAP business objects. EML is used to implement the transactional behavior of RAP BOs and also access existing RAP BOs from outside the RAP context.
PS: Some EML statements can be used in the so-called local mode - by using the addition
IN LOCAL MODE
- to exclude feature controls and authorization checks. This addition can only be used in the behavior implementation (aka behavior pool) of a particular RAP BO when accessing its own instances, i. e. not for accessing instances of other RAP BOs.The EML reference documentation is provided in the ABAP Keyword Documentation.
You can use the classic F1 Help to get detailed information on each statement by pressing F1 in the ABAP editors.Further reading: Entity Manipulation Language (EML) | ABAP for RAP Business Objects
Define the determination
setStatusToOpen
in the behavior definition of the Travel entity. This determination will be used to set the default value of the fieldOverallStatus
toopen
(O
) at the creation time new Travel instances.
🔵 Click to expand!
-
Go to the behavior definiton of the Travel BO entity
ZRAP100_R_TravelTP_###
and insert the following statement after the statementdelete;
as shown on the screenshot below:determination setStatusToOpen on modify { create; }
Short explanation:
The statement specifies the name of the new determination,setStatusToOpen
andon modify
as the determination time when creating new travel instance ({ create }
). -
Now, declare the required method in behavior implementation class with ADT Quick Fix.
Set the cursor on the determination name
setStatusToOpen
and press Ctrl+1 to open the Quick Assist view and select the entryAdd method for determination setstatustoopen of entity zrap100_r_travel_### ...
in the view.As result, the
FOR DETERMINE
methodsetStatusToOpen
will be added to the local handler classlcl_handler
of the behavior pool of the Travel BO entityZRAP100_BP_TRAVELTP_###
.
You are through with the definition of the determination.
You will now implement the logic of the defined determination in the behavior pool.
🔵 Click to expand!
-
First check the interface of the method
setStatusToOpen
in the declaration part of the local handler classlcl_handler
.For that, set the cursor on the method name,
setStatusToOpen
, press F2 to open the ABAP Element Info view, and examine the full method interface.Short explanation:
- The addition
FOR DETERMINE
indicates that the method provides the implementation of a determination and the additionON MODIFY
indicates the specified trigger time. IMPORTING
parameterkeys
- an internal table containing the keys of the instances the determination will be executed on all entities for which keys must be assigned- Implicit
CHANGING
parameterreported
- used to return messages in case of failure
Now go ahead and implement the method in the implementation part of the local handler class.
- The addition
-
Define the local constant
travel_status
to store the allowed value of the overall status of a Travel instance.Insert the following code snippet in the definition part of the local handler class
lcl_handler
as shown on the screenshot below.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.
-
Now implement the method
setStatusToOpen
in the implementation part of the class.The logic consists of the following steps:
- Read the travel instance(s) of the transferred keys (
keys
) using the EML statementREAD ENTITIES
- The addition
IN LOCAL MODE
is used to exclude feature controls and authorization checks - Removed all Travel instances where the overall status is already set
- Set the overall status to
open
(O
) for the remaining entries using the EML statementMODIFY ENTITIES
- Set the changing parameter
reported
Insert the following code snippet in the method and replace all occurrences of the placeholder
###
with your group ID.
You can use the F1 help to get detailed information on each EML statement.Format your source code with the ABAP Pretty Printer (Shift+F1).
"Read travel instances of the transferred keys READ ENTITIES OF ZRAP100_R_TravelTP_### 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. "else set overall travel status to open ('O') MODIFY ENTITIES OF ZRAP100_R_TravelTP_### 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 ).
Your source code should look like this:
- Read the travel instance(s) of the transferred keys (
You can now preview and test the changes by creating a new travel instance in the Travel app.
🔵 Click to expand!
-
Refresh your application in the browser using F5 if the browser is still open
or go to your service bindingZRAP100_UI_TRAVEL_O4_###
and start the Fiori elements App preview for theTravel
entity set. -
Create a new Travel instance. The overal status should now be set automatically by the logic you just implemented.
The initial overall status of the created should now be set toopen
(O
).
Now that you've...
- defined a determination in the behavior definition,
- implement it in the behavior implementation, and
- preview and test the enhanced Fiori elements app,
you can continue with the next exercise – Exercise 5: Enhance the BO Behavior – Validations