Skip to content

Latest commit

 

History

History
163 lines (113 loc) · 6.92 KB

README.md

File metadata and controls

163 lines (113 loc) · 6.92 KB

Home - RAP110

Exercise 10: Implement the Base BO Behavior - Functions

Introduction

In the previous exercise, you've defined side effects for the Travel BO (see Exercise 9).

In this exercise, you will implement the function getDaysToFlight that you've defined in Exercise 3. This function will be used to determine all the day to flight related virtual elements defined in the booking BO projection view (see Exercise 4).

Exercises:

Reminder: Do not forget to replace the suffix placeholder ### with your choosen or assigned assigned suffix in the exercise steps below.

About Functions

Click to expand!

A function in RAP is a custom read-operation that is part of the business logic.

Functions perform calculations or reads on business objects without causing any side effects. Functions don't issue any locks on database tables and you can't modify or persist any data computed in a function implementation.

Further reading: Functions

Exercise 10.1: Implement the Functions of the Booking BO Entity

^Top of page

Implement the only one function that was defined in Exercise 3.6: getDaysToFlight.

🔵 Click to expand!

Exercise 10.1.1: Implement the Function getDaysToFlight of the Booking BO Entity

Implement the the Function getDaysToFlight for the booking entity in the behavior implementation class ABAP classZRAP110_BP_BookingTP_###. This function can be used to determine the values of the virtual elements of the Booking BO projection view: BookingStatusIndicator, InitialDaysToFlight, RemainingDaysToFlight, and DaysToFlightIndicator.

This function can, for example, be used at runtime to calculate the virtual elements via direct EML calls.

🟣 Click to expand!
  1. Open the behavior implementation class of the Travel entity ABAP classZRAP110_BP_BOOKINGTP_### and navigate to the method getDaysToFlight of the local handler class lhc_booking

  2. Implement the function method getDaysToFlight.

    For that, replace the empty method implementation of getDaysToFlight with the source code provided below and replace all occurences of the placeholder ### with your assigned suffix using Ctrl+F.

    **************************************************************************
    * Instance-bound function for calculating virtual elements via EML calls
    **************************************************************************
      METHOD getDaysToFlight. 
        DATA:
          c_booking_entity TYPE ZRAP110_C_BookingTP_###,
          bookings_result  TYPE TABLE FOR FUNCTION RESULT zrap110_r_traveltp_###\\booking~getdaystoflight,
          booking_result   LIKE LINE OF bookings_result.
    
        "read relevant data
        READ ENTITIES OF ZRAP110_R_TravelTP_### IN LOCAL MODE
           ENTITY booking
             FIELDS ( TravelID BookingStatus BookingID FlightDate BookingDate )
    *         ALL FIELDS
             WITH CORRESPONDING #( keys )
           RESULT DATA(bookings).
    
        LOOP AT bookings ASSIGNING FIELD-SYMBOL(<booking>).
          c_booking_entity = CORRESPONDING #( <booking> ).
          "set relevant transfered data
          booking_result   = CORRESPONDING #( <booking> ).
          "calculate virtual elements
          booking_result-%param
            = CORRESPONDING #( zrap110_calc_book_elem_###=>calculate_days_to_flight( c_booking_entity )
                               MAPPING booking_status_indicator = BookingStatusIndicator
                                       days_to_flight_indicator = DaysToFlightIndicator
                                       initial_days_to_flight   = InitialDaysToFlight
                                       remaining_days_to_flight = RemainingDaysToFlight ).
          "append
          APPEND booking_result TO bookings_result.
        ENDLOOP.
    
        result = bookings_result.
    
      ENDMETHOD.         
  3. Save save icon and activate activate icon the changes.

Exercise 10.2: Test Function using EML

^Top of page

Implement a READ FUNCTION in an ABAP class to test the implemented function.

🔵 Click to expand!
  1. Open the class ZRAP110_EML_PLAYGROUND_### and uncomment following coding:

      "execute function getDaysToFlight
     READ ENTITIES OF ZRAP110_R_TravelTP_###
       ENTITY Booking
         EXECUTE getDaysToFlight
           FROM VALUE #( FOR link IN travels_to_bookings ( %tky = link-target-%tky ) )
     RESULT DATA(days_to_flight).
    
     "output result structure
     LOOP AT days_to_flight ASSIGNING FIELD-SYMBOL(<days_to_flight>).
       out->write( | TravelID = { <days_to_flight>-%tky-TravelID } |  ).
       out->write( | BookingID = { <days_to_flight>-%tky-BookingID } | ).
       out->write( | RemainingDaysToFlight  = { <days_to_flight>-%param-remaining_days_to_flight } | ).
       out->write( | InitialDaysToFlight = { <days_to_flight>-%param-initial_days_to_flight } | ).
       out->write( | ---------------           | ).
     ENDLOOP.
    BO Behavior Definition
  2. Start your Travel App and copy a Travel ID from a former created entry of your choice.

    BO Behavior Definition
  3. Go back to your class ZRAP110_EML_PLAYGROUND_### and paste your Travel ID on the corresponding space.

    BO Behavior Definition
  4. Save save icon and activate activate icon the changes.

  5. Right-click your class, select Run As > ABAP Application (Console) (or press F9).

    BO Behavior Definition
  6. Check your result.

    BO Behavior Definition

Summary

^Top of page

Now that you've...

  • implemented a function with a return structure as output parameter, and
  • determined the values of virtual elements via an EML call using a function,

you can continue with the next exercise – Exercise 11: Enhance the BO Behavior with Business Events