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

OOPs ABAP
Share on Facebook0Share on LinkedIn6Tweet about this on TwitterShare on Google+0
Please Share!!

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.

OOPs in ABAP

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.

CL_ALV class has three methods GET_OBJECT, LAYOUT_DIS, DISPLAY_ALV and CONSTRUCTOR.

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.

OOPs in ABAP

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.

 

Share on Facebook0Share on LinkedIn6Tweet about this on TwitterShare on Google+0
Please Share!!

About the Author

Jyoti Patel
Jyoti Patel
Jyoti is an experienced SAP Technical Consultant, currently stationed at Muscat, Oman providing her valuable expertise to Al Turki Enterprises LLC. She is fond of Object Oriented Programming with a soft corner for Adobe and Smartforms too.She loves exploring and experimenting different programming techniques. Presently, she is especially fascinated by APIs.Whenever she is not in front of the SAP screen, you would find her in her car heading for a long unplanned drive or listening to random music. Find more about Jyoti on LinkedIn.

1 Comment on "Practical Use of OOPs ABAP – Model View Controller (MVC). Part II"

  1. Marcos Roberto de Andrade | September 22, 2017 at 8:37 am | Reply

    Hello, I am from Brazil.
    Thanks you, very good .. the education Use of OOPs ABAP.

    Bye,
    Marcos R. de Andrade

Leave a comment

Your email address will not be published.


*