Controller Overview – Custom Data Explorer

Controller is responsible for updating model data based on events received from views/abap screens. It does this by defining the events it will listen to (the abap screen will dispatch these) and by registering method listeners for each controller event type.

In ABAP events can only be dispatched from class methods and the events need to either be defined in the class itself or the class needs to implement an interface containing the events. Custom data explorer uses multiple classes located in each screen to handle all screen related events (controller and non-controller based). This means the events need to be defined in one controller interface (zif_de_ctrl_events) implemented by all dispatching classes.

Another viable approach is to implement a global event dispatcher that acts as a singleton. All views would make use of this class to dispatch controller events. One advantage of this approach is that each screen won’t have to create a local event handler class for sending events to controller, it can directly use this dispatcher class. In larger projects this is the way to go. In this small project, since each screen has to have a local event handling class anyway to handle events from screen elements like alv lists, I’ve decided to dispatch the controller events from each screen local event handler class.

Like the model class, controller is also a singleton. It gets initialized right in the begining of the abap report. After initialization the abap report registers controller methods to each possible controller event type coming from all screens.
set handler controller->update_tentry_handler for all instances.
set handler controller->update_tlist_handler for all instances.
set handler controller->update_flist_handler for all instances.

The logic behind controller methods is simple with this custom data explorer example. Controller updates model data using controller logic in possible combination with model own methods. Such an example is found in methods like controller->update_tentry_handler setting where the current table entry is set using both model attributes and methods, like:
model->current_table = model->get_table_by_index( im_index = tabindex ).

This post is part of Custom Data Explorer.

Leave a Reply

Your email address will not be published. Required fields are marked *