Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  ABAP RESTful Programming Model →  Behavior Implementations 

Handler Class

Other versions: 7.31 | 7.40 | 7.54

Syntax


CLASS lcl_handler_name DEFINITION 
       INHERITING FROM cl_abap_behavior_handler
       [ABSTRACT] [FINAL].
  PRIVATE SECTION.
    TYPES ...
    DATA ...
    CONSTANTS ...

    METHODS method_name FOR MODIFY
      [IMPORTING]
        create_import_parameter FOR CREATE entity_name
        create_import_parameter FOR CREATE entity_name\association
        update_import_parameter FOR UPDATE entity_name
        delete_import_parameter FOR DELETE entity_name
        action_import_parameter FOR ACTION entity_name~action_name
                                [RESULT action_export_parameter].
    METHODS method_name FOR LOCK
      [IMPORTING]
        lock_import_parameter FOR LOCK entity_name.
    METHODS method_name FOR READ
      [IMPORTING]
        read_import_parameter FOR READ entity_name
                              [RESULT read_export_parameter].
ENDCLASS.

CLASS lcl_handler_name IMPLEMENTATION.
  METHOD modify_method_name.
   ...
  ENDMETHOD.
  METHOD lock_method_name.
   ...
  ENDMETHOD.
  METHOD read_method_name.
   ...
  ENDMETHOD.
ENDCLASS.

Effect

Within the behavior pool, one or more local handler classes for handling the behavior of the business object are defined. In this interaction phase of the behavior implementation of a business object, the application performs writes and reads that need to be evaluated and whose effects (if without errors) need to be saved to a transactional buffer. Here, it is defined for which operations a method is responsible. In extreme cases, this is the full set of all write (MODIFY) or read (READ) operations permitted by the behavior definition.

A handler class is defined implicitly as ABSTRACT and FINAL and derived from the basis class CL_ABAP_BEHAVIOR_HANDLER. There are no special rules for the name lcl_handler_name of the handler classes.

To make a reference to the entities entity_name, the alias granted in the behavior definition (if available) is used.

The method name method_name can be specified freely in handler classes. The category of the method is specified for the FOR clause (FOR MODIFY|LOCK|READ).

Here, a single operation (also known as a trigger) consists of the combination of an operation (CREATE, UPDATE, DELETE, LOCK, READ, orACTION) with an entity of an entity part (namely an action or association), for example update SalesOrderItem or read SalesOrderItem_Product.

The trigger is associated with a freely specified parameter name (for example, update_import_parameter). The trigger is also associated with one or more further parameter names, if the trigger is associated with output data (for example, with the parameter action_export_parameter for an action with the addition RESULT or read_export_parameter for the operation READ).

The following transactional methods can be implemented in the handler class:

  • FOR MODIFY
    Covers all change operations (CREATE, UPDATE, DELETE, and certain actions specified in the behavior definition) of an entity.


Note

Exceptions cannot be raised in handler methods. The statement RAISE EXCEPTION produces a runtime error.


Example

In the following example, the data from the ABAP flight data reference scenario (or flight data scenario for short) is used. It represents a legacy business logic that can be used to create and edit flight bookings. The root entity Travel represents the business object for managing flight trips. The underlying data model and the behavior of the root entity Travel are described in ABAP BDL - Example.

The following example shows the definition and the schema of the implementation of the handler class of the business object. The handler class implements the handler that processes:

  • Standard operations create, update, and delete (methods modify_create, modify_update, and modify_delete)
  • Read requests for the entity Travel (method read_travel)
  • Lock method lock_travel
  • Application-specific action set_status_booked
CLASS lcl_travel_handler DEFINITION
      INHERITING FROM cl_abap_behavior_handler.

  PRIVATE SECTION.
    METHODS modify_create  FOR MODIFY
      IMPORTING
        it_travel_create       FOR CREATE travel.

    METHODS modify_update  FOR MODIFY
      IMPORTING
        it_travel_update       FOR UPDATE travel.

    METHODS modify_delete  FOR MODIFY
      IMPORTING
        it_travel_delete       FOR DELETE travel.

    METHODS set_status     FOR MODIFY
      IMPORTING
        it_travel_set_status_booked
                               FOR ACTION travel~set_status_booked
      RESULT
        et_travel_set_status_booked.

    METHODS lock_travel    FOR LOCK
      IMPORTING
        it_travel_key          FOR LOCK travel.

    METHODS read_travel    FOR READ
      IMPORTING
        it_travel_read         FOR READ travel
      RESULT
        et_travel.

ENDCLASS.
CLASS lcl_travel_handler IMPLEMENTATION.

  METHOD modify_create.
    ...
  ENDMETHOD.

  METHOD modify_update.
    ...
  ENDMETHOD.

  METHOD modify_delete.
    ...
  ENDMETHOD.

  METHOD set_status.
    ...
  ENDMETHOD.

  METHOD read_travel.
    ...
  ENDMETHOD.

  METHOD lock_travel.
    ...
  ENDMETHOD.

ENDCLASS.

Continue

FOR MODIFY

FOR READ

FOR LOCK

Example - Handling of Messages