Skip to Content

Create Behavior Definition for Managed Scenario

test
0 %
Create Behavior Definition for Managed Scenario
Details
// Explore More Tutorials

Create Behavior Definition for Managed Scenario

Requires Customer/Partner License

10/15/2019

Create behavior definition and implementation for managed scenario.

You will learn

  • How to create behavior definition
  • How to create behavior implementation
  • How to create behavior definition for projection view

In this tutorial, wherever XXX appears, use a number (e.g. 000).


Step 1: Create behavior definition
  1. Right-click on your data definition ZI_TRAVEL_M_XXX and select New Behavior Definition

    Create behavior definition

  2. Check your behavior definition. Your implementation type is managed.

    Click Next >.

    Create behavior definition

  3. Click Finish.

    Create behavior definition

  4. Replace your code with following.

    managed implementation in class ZCL_BP_I_TRAVEL_M_XXX unique;
    
    define behavior for ZI_Travel_M_XXX alias Travel
    persistent table ztravel_xxx
    etag last_changed_at
    lock master
    {
    // administrative fields (read only)
    field ( readonly ) last_changed_at, last_changed_by, created_at, created_by;
    
    // mandatory fields that are required to create a travel
    field ( mandatory ) agency_id, overall_status, booking_fee, currency_code;
    
    // dynamic field control
    field (features : instance ) travel_id;
    
    // standard operations for travel entity
    create;
    update;
    delete;
    }
    
  5. Save and activate.

    save and activate

    Now the behavior definition is created and determines the create, update and delete functionality for travel booking.

Log on to answer question
Step 2: Create behavior implementation
  1. Right-click on your behavior definition ZI_TRAVEL_M_XXX and select New Behavior Implementation.

    Create behavior implementation

  2. Create a new behavior implementation:

    • Name: ZCL_BP_I_TRAVEL_M_XXX

    Click Next >.

    Create behavior implementation

  3. Click Finish.

    Create behavior implementation

  4. In your global class replace your code with following:

    CLASS zcl_bp_i_travel_m_xxx DEFINITION
    PUBLIC
    ABSTRACT
    FINAL
    FOR BEHAVIOR OF ZI_Travel_M_XXX.
    
    ENDCLASS.
    
    CLASS zcl_bp_i_travel_m_xxx IMPLEMENTATION.
    ENDCLASS.
    
  5. In your local types replace your code with following:

    *"* use this source file for the definition and implementation of
    *"* local helper classes, interface definitions and type
    *"* declarations
    CLASS lhc_travel DEFINITION INHERITING FROM cl_abap_behavior_handler.
    
      PRIVATE SECTION.
    
        TYPES tt_travel_update TYPE TABLE FOR UPDATE zi_travel_m_xxx.
    
        METHODS get_features               FOR FEATURES IMPORTING keys REQUEST    requested_features FOR travel    RESULT result.
    
    ENDCLASS.
    
    CLASS lhc_travel IMPLEMENTATION.
    
      METHOD get_features.
      ENDMETHOD.
    
    ENDCLASS.
    
  6. Save and activate.

    save and activate

    The behavior implementation is created for travel booking. By using the managed approach, the implementation of create, update and delete is done automatically.

Log on to answer question
Step 3: Create behavior definition for projection view
  1. Right-click on your data definition ZC_TRAVEL_M_XXX and select New Behavior Definition.

    Create behavior definition for projection view

  2. Check your behavior definition. Your implementation type is projection.

    Click Next >.

    Create behavior definition for projection view

  3. Click Finish.

    Create behavior definition for projection view

  4. Replace your code with following:

    projection;
    
    define behavior for ZC_TRAVEL_M_XXX alias TravelProcessor
    use etag
    {
    // scenario specific field control
    field ( mandatory ) BeginDate, EndDate, CustomerID;
    
    use create;
    use update;
    use delete;
    }
    
    
  5. Save and activate.

    save and activate

  6. Now switch to your service binding and double click on TravelProcessor.

    Create behavior definition for projection view

  7. Check your result.

    The create and delete button appears on the UI because of the managed scenario.
    You can create and edit travel bookings or you’ re able to delete existing ones.

    Create behavior definition for projection view

Log on to answer question
Step 4: Test yourself
How do you recognize the behavior definition for your projection view?
×

Next Steps

Prerequisites

  • You have created an SAP Cloud Platform ABAP environment trial user or
  • You have created a developer user in an SAP Cloud Platform ABAP Environment system.
  • You have downloaded Eclipse Photon or Oxygen and installed ABAP Development Tools (ADT). See https://tools.hana.ondemand.com/#abap.
Back to top