|
Blogs
IntroductionThe 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 • SAPMVC • Classes created for the ALV - 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 blogsThere 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 application1. Start of the application2. 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. The conceptAt 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 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. How to call a screen
Or
Template for the local controller classThe PBO and the PAIThe code for the PBO and the PAI is always the same.
SubscreensThe subscreen controller is set in the method SET_DISPLAY of the local controllerSetupYou can add the classes for the MVC concept with the program SAPLINKYou need the plugin for a CLASS and INTERFACE. The link to the nugget is: RV_ABAP_MVC The next partWhat 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. Robin Vleeschhouwer
| |||||||||||||||||||||||