The Model View Controller design pattern is not invented by SAP. It is a design pattern to separate the business logic from the view. For example the view could be a Dynpro, WDA or BSP. To connect the business logic to a view we have the controller. This makes it possible to use the same business logic for different views.
There are several solutions build in ABAP to use the MVC design pattern for example:
• The BUS Screen framework
• OO ABAP Dynpro Programming – noticed by Thomas Jung
These are really neat solutions, but I think they have overhead, are too much ABAP minded and the model isn’t flexible enough. Therefore I created my implementation of the MVC design pattern in ABAP for practical use. I understand that we can’t really compare it with the BUS Screen framework, because this is a complete framework as the name describes.
Content of the blogs
There will be two parts to explain the complete concept.
In this part I will present the concept of the view-controller with a screen manager.
In the next part the model-controller with a model manager will be presented.
Requirements of the concept
• Separation of business logic and output
• Reuse of screens
• Reuse the Module code of the PBO and PAI
• Compatible with Subscreens and Controls (Tabstrip, Tableview, etc.)
• Keep it simple!
Flow of an application
1. Start of the application
2. Call a screen
3. Request for data (the model)
4. Setup the screen
5. Handle actions of the screen or model events
Repeat point 2 till 5.
At runtime every screen is bound to exactly one controller. The controller is responsible for point 2 till 5 of the application flow. You can bind a controller to screen with the screen manager.
The image below shows the simple view of the concept.
The controller must be a local class that is inherited from a global class that implements the interface ZIF_SCREEN_CNTRL. The controller class must be created in the same program as the screen.
The image below shows the full view of the concept.
How to call a screen
Template for the local controller class
The PBO and the PAI
The code for the PBO and the PAI is always the same.
When we need to have a custom module for example a value help, then we create a new module.
The subscreen controller is set in the method SET_DISPLAY of the local controller
You can add the classes for the MVC concept with the program SAPLINK
You need the plugin for a CLASS and INTERFACE.
The link to the nugget is: RV_ABAP_MVC
The next part
What if the business logic is in a function group or in a business object. Or what if the business logic is SAP standard code. How can you attach your local view controller to handle events from that kind of model.
In the next part I will present the model-controller with a model manager. For that we will extend the controller class to handle a model event and I will explain how to use the same model instance in different views.