May 24

MVC Pattern – OOABAP

MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application’s concerns.

  • Model – Model represents an object which deals with business logic.
  • View – View represents the visualization of the data that model contains.
  • Controller – Controller acts on both model and view. It controls the data flow into model object and updates the view whenever data changes. It keeps view and model separate.

2017-05-25 10_10_32-Microsoft PowerPoint - [Test]

Let’s see, How to achieve MVC pattern in ABAP program:

Below is our model class:

  1. We have all our declarations in Public section (which means they are available outside class)
  2. retrieve_data( ) method is defined as Instance Public method (class-methods declaration defines a static method)
  3. gt_sbook is instance public attribute (class-data declarations defines a static attribute)

Data from “sbook” table is retrieved and stored in global attribute gt_sbook.

2017-05-25 10_11_51- - Remote Desktop Connection

Below is controller class:

method instantiate_model( ) will create instance to model class.

2017-05-25 10_13_08- - Remote Desktop Connection

Let’s consume model in our program:

  1. Airline ID is given as input on selection screen
  2. Controller class is instantiated and it’s method instantiate_model( ) is called to create instance to model class
  3. Data is retrieved by calling retrieve_data( ) of model by passing the airline id from selection screen
  4. cl_salv_table=>factory method is called to display the data as ALV output

2017-05-25 10_14_55- - Remote Desktop Connection

Execute the program:

2017-05-25 10_25_45- - Remote Desktop Connection

2017-05-25 10_26_00- - Remote Desktop Connection