CLASS lcl_handler_name DEFINITION
INHERITING FROM cl_abap_behavior_handler
METHODS method_name FOR MODIFY
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
METHODS method_name FOR LOCK
lock_import_parameter FOR LOCK entity_name.
METHODS method_name FOR READ
read_import_parameter FOR READ entity_name
CLASS lcl_handler_name IMPLEMENTATION.
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.
- FOR READ
Exceptions cannot be raised in handler methods. The statement RAISE EXCEPTION produces a runtime error.
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
INHERITING FROM cl_abap_behavior_handler.
METHODS modify_create FOR MODIFY
it_travel_create FOR CREATE travel.
METHODS modify_update FOR MODIFY
it_travel_update FOR UPDATE travel.
METHODS modify_delete FOR MODIFY
it_travel_delete FOR DELETE travel.
METHODS set_status FOR MODIFY
FOR ACTION travel~set_status_booked
METHODS lock_travel FOR LOCK
it_travel_key FOR LOCK travel.
METHODS read_travel FOR READ
it_travel_read FOR READ travel