Skip to Content

Introduction

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.
Model View Controller design pattern
There are several solutions build in ABAP to use the MVC design pattern for example:
• The BUS Screen framework
SAPMVC
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.

The concept

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.
MVC simple view

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.

MVC full concept

How to call a screen

Or

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.

Subscreens

The subscreen controller is set in the method SET_DISPLAY of the local controller

Setup

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.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Mark Teichmann
    Hi Robin,

    I already made some tests with the SAPmvc framework but I also think it is a bit too much of overhead for my applications. Therefore I can’t wait to see your next parts of this blog. I hope your solution will be easier to implement than SAPmvc.

    Regards,

    Mark

    (0) 
  2. Martin English
    Hi Robin,
      When I first started hearing about the MVC pattern (on the oreilly network and elsewhere), I was playing BSP pages…. 
    So I tried implementing the pattern in BSP, and quite quickly found that the secret is to working out what code goes in what class (or the equivalent for old skool ABAP and BSP).

    This is definitely another case of where a few minutes of scribbling on paper before you start coding can make development AND maintenance much simpler 🙂

    (0) 
    1. Robin Vleeschhouwer Post author
      Hi Martin,

      Thanks for your comment. You are right, when I begin with a project the first thing I do is making UML class diagrams. This is the most difficult part, but you first always have to think before you start coding 🙂
      This step is also important to know what code will be reused and you have good documentation.

      regards Robin

      (0) 
  3. Mark Pinto

    hi robin,

         very nice concept I’m started developing my 1st own application using your mvc concept. at the start it takes 2 weeks for me to understand the whole process but later on i already cope up your mvc framework and understand each classes.

    regards,

    Ryl

    (0) 

Leave a Reply