Object Oriented Programming in ABAP – MVC – Part IV

0
51
SAP ABAP Objects

In the last three parts of MVC series, we have seen the Practical Use of OOPs ABAP. In this concluding part, we will try to clarify a little more and try to learn this approach of MVC.

What exactly MVC says?

In MVC, User Interface acts as the View; Business logic acts as the Model and the link which provides the connection between the View and Model is known as the Controller.

The controller provides another layer of abstraction where we can just pass our Object to the controller and the controller would provide the data to our View.

ABAP Objects

Step1: Design our selection screen.

Step2: Create CL_SEL class to get selection screen parameters.

Method GET_SCREEN is used to get the selection screen parameters.

oops abap

Step3: Class CL_FETCH to get the business logic (our MODEL) we have two methods here.

GET_SEL:  This method will create the object of CL_SEL class so that we can access the attributes of the CL_SEL class.

FETCH_DATA: This method will fetch the business logic once we have selection parameter.

programming in Object Oriented ABAP

Do you Know? How to convert an existing ABAP Report to OOPs ABAP?

Step4:  Class Cl_CONTROLLER  which will handle the flow of data between the MODEL and VIEW through which we can achieve one more layer of abstraction.

We have one Method here GET_OBEJCT to get the object of the MODEL class. When you closely look at this approach we are just passing our object of class CL_FETCH at runtime (if we have the requirement to change the model we can simply pass our other model name and it will create the object of another model).

MVC model

Step5: Class CL_ALV is our VIEW to display the report we have only one method DISPLAY_ALV here to display the desired Output.

mvc model explained

Now let’s call all the methods in our program.

abap developer

O_CON –> here we have the object of the controller.

Also ReadJust 4 Versions of the same program to understand OOPs ABAP

We have no object for model class?? Why??

The answer is, the controller will return the object of the model class. Once we have the object of model class we are good to go to fetch our data.

Now we have data in our controller class, let’s pass it to display our report.

Now if you see here we are passing our data through one more abstraction layer which is our controller and controller is passing our data to view.

OOPs Example Program for reference is below. Copy this into your system and debug to see the flow. You need to make your hands dirty to have the better understanding of the concept.

Also Check SAP ABAP on HANA, OData, SAP Fiori and SAPUI5 Tutorials.

The destination is as important as the journey itself (no matter what others say). 🙂 Check the test outputs below for our exercise today.

Practical Object Oriented Programming in ABAP

Hope, we were successful in demonstrating the practical use of MVC in real ABAP Report. If you still have doubts, please feel free to shout out to us. We will try to explain to the best of our knowledge.

Do you have any other OO ABAP Programming concept to share? Please feel free to write in the comment section.

Please Subscribe, Like and Share our Page.

OOPs ABAP series on MVC Concept at SAPYard
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
Part IV – Object-Oriented Programming in ABAP – MVC – Part IV

LEAVE A REPLY

Please enter your comment!
Please enter your name here