Practical Use of OOPs ABAP – Model View Controller (MVC). Part II


In Part I of MVC, we showed a practical example of ABAP program following the Model View Controller concept. Today, we would see how we can beautify and add more feature to the User Interface, i.e. in the View section of MVC.

Let’s work more with our User Interface today.

Scenario 2

Display Sales report with Layout  and Toolbar Icons (filter Icon, Sort, Save layout icon etc )

Display Layouts means our User Interface, so we will be working with layout today i.e. our class CL_ALV (view).

In this case, we will NOT touch the data class CL_FETCH and selection class CL_SEL. We will only modify our class CL_ALV (View).

One of the most common requirements we get from our user is setting the layout, so we give parameter selection for user specific layout.


To meet this new requirement, we will create one more class (4th class for the report, 3 already created in the previous article) for this layout selection. As this is a very common requirement it is recommended to use a global class which will give us default layout and F4 help on layout and this global class can be reused across multiple developments. But here, I am using local class just to explain the concept.

4. Class for Layout Variant –  CL_VARIANT:

Class CL_VARIANT will have two methods, F4_VARIANT and GET_DEFAULT.

Practical OOPs ABAP

F4_VARIANT:  will return the list of layout present in this report.

GET_DEFAULT: will return the default layout which is a static method.

OOPs for ABAPers

3. Class for Display – CL_ALV:

Our class CL_ALV definition has two References. One for CL_FETCH and other is for CL_VARIANT.

Needless to say, class CL_FETCH will provide the Business logic here and CL_VARIANT will provide us the layout to display.


CONSTRUCTOR: will hold the object of two classes CL_FETCH and CL_VARIANT.

GET_OBJECT: will return the object of the Factory method.

LAYOUT_DIS: will set Default layout and striped pattern.

DISPLAY: will display final result.

If you see method LAYOUT_DIS all layout functions are available here.

oops programming

Methods DISPLAY_ALV will simply display the report.

abap programming

Now we can call the methods in the events of Reports.

If you closely look at the report we are just modifying one class without disturbing the other class and this will give us the flexibility to modify the report view based on our requirement.

Full Program:

Final Results :

i. /PP is the default layout in our system. So, GET_DEFAULT method is working as expected.


ii. Here we have the Layout and Filter icons.

layout and toolbar icons in oops alv

iii. Now let’s see our F4 help is working or not?

f4 help in OOPs

iv. /MM is user specific layout and its working fine. We have only four fields in this layout. Look at below output, our code is showing only four columns. Isn’t MVC cool?

Despite everything, do you think this report is finished and our client will get satisfied? ….  An enormous NO… 🙁 They will demand the Specific Fields (columns) now and yes some additional data from different tables. They will raise a change request for it and you cannot oppose it. 🙂 Let’s say they want sold-to-party and ship-to-party in this report ….Oops!

So let’s move on to the next Part to modify our MODEL i.e. our Business Logic. In OOPs ABAP, if we get more changes after the developments are LIVE, we would see in next part, how easily we can handle it without much disruption. Please stay tuned.

Did you find this post Useful? Do you have any other practical example to share?

We want your genuine feedback. Whether you like or not, please write it in the Comment section.


OOPs ABAP series on MVC Concept

Part I – Model View Controller (MVC) in SAP ABAP – Introduction

Part II – Model View Controller (MVC) in SAP ABAP – Enhance the View

Part III – Model View Controller (MVC) in SAP ABAP – Enhance the Model

Please SUBSCRIBE, SHARE and LIKE our page.



  1. Hi ,
    I have one doubt.
    may i know use of above line.
    i think result will come that line is include or exclude…
    can u pls explain……..

    one more doubt…
    may i know the use of above 2 lines …..
    above 2lines are commented or uncommented , output will be same…
    can u pls explain….

  2. Hello Jyoti Patel,
    your series on Model View Controller is very helpfull but solution with global class have one problem regarding layout. Saved layouts are associated with class name not name of program so you can choose layout which is not relevant for the program. Do you have any solution for this?

Leave a Reply to Marcos Roberto de Andrade Cancel reply

Please enter your comment!
Please enter your name here