Skip to Content

Enhance the Business Object Behavior With Determinations

Enhance the business object behavior using determination with SAP BTP ABAP environment.
You will learn
  • How to define determinations
  • How to implement determinations
  • How to preview and test enhanced travel app
mervey45Merve TemelMarch 3, 2023
Created by
mervey45
February 10, 2023
Contributors
mervey45

Prerequisites

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.

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.

Reminder: Do not forget to replace the suffix placeholder ### with your chosen or assigned group ID in the exercise steps below.
About: Determinations

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

About: Entity Manipulation Language (EML)

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 business objects and also access existing RAP business objects 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 currently only be used in RAP business object implementations for the particular RAP business object itself, i. e. not for other RAP business objects.

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: ABAP for RAP Business Objects

  • Step 1

    Define the determination setStatusToOpen in the behavior definition of the Travel entity. This determination will be used to set the default value of the field OverallStatus to open (O) at the creation time new Travel instances.

    1. Go to the behavior definition of the Travel BO entity

      bdef icon
      ZRAP100_R_TravelTP_### and insert the following statement after the statement delete; as shown on the screenshot below:

      ABAP
      Copy
      determination setStatusToOpen on modify { create; }
      
      Travel BO Definition

      Short explanation:
      The statement specifies the name of the new determination, setStatusToOpen and on modify as the determination time when creating new travel instance ({ create }).

    2. Save

      save icon
      and activate
      activate icon
      the changes.

    3. 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 entry Add method for determination setStatusToOpen of entity zrap100_i_travel_### in the view.

      As result, the FOR DETERMINE method setStatusToOpen will be added to the local handler class lcl_handler of the behavior pool of the Travel BO entity

      class icon
      ZRAP100_BP_TRAVEL_###.

      Travel BO Behavior Pool
    4. Save

      save icon
      and activate
      activate icon
      the changes.

    You are through with the definition of the determination.

    Log in to complete tutorial
  • Step 2

    You will now implement the logic of the defined determination in the behavior pool.

    1. First check the interface of the method setStatusToOpen in the declaration part of the local handler class lcl_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.

      Travel BO Behavior Pool

      Short explanation:

      • The addition FOR DETERMINE indicates that the method provides the implementation of a determination and the addition ON MODIFY indicates the specified trigger time.

      • IMPORTING parameter keys - an internal table containing the keys of the instances the determination will be executed on
        includes all entities for which keys must be assigned

      • Implicit CHANGING parameter reported - used to return messages in case of failure

      Now go ahead and implement the method in the implementation part of the local handler class.

    2. 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.

      ABAP
      Copy
      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.    
      
      Travel BO Behavior Pool
    3. Now implement the method setStatusToOpen in the implementation part of the class.

      The logic consists of the following steps:

      1. Read the travel instance(s) of the transferred keys (keys) using the EML statement READ ENTITIES

      2. The addition IN LOCAL MODE is used to exclude feature controls and authorization checks

      3. Removed all Travel instances where the overall status is already set

      4. Set the overall status to open (O) for the remaining entries using the EML statement MODIFY ENTITIES

      5. 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.

      ABAP
      Copy
      "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 SET FIELDS
          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:

      Travel BO Behavior Pool
    4. Save

      save icon
      and activate
      activate icon
      the changes.

    Log in to complete tutorial
  • Step 3

    You can now preview and test the changes by creating a new travel instance in the Travel app.

    1. Refresh your application in the browser using F5 if the browser is still open, or go to your service binding ZRAP100_UI_TRAVEL_O4_### and start the Fiori elements App preview for the Travel entity set.

    2. Create a new Travel instance. The overall status should now be set automatically by the logic you just implemented.
      The initial overall status of the created should now be set to open (O).

      Travel App Preview
    Log in to complete tutorial
  • Step 4

    Where do you define the constants of travel_status?

    Log in to complete tutorial
Back to top