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.
Let’s see, How to achieve MVC pattern in ABAP program:
Below is our model class:
- We have all our declarations in Public section (which means they are available outside class)
- retrieve_data( ) method is defined as Instance Public method (class-methods declaration defines a static method)
- 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.
Below is controller class:
method instantiate_model( ) will create instance to model class.
Let’s consume model in our program:
- Airline ID is given as input on selection screen
- Controller class is instantiated and it’s method instantiate_model( ) is called to create instance to model class
- Data is retrieved by calling retrieve_data( ) of model by passing the airline id from selection screen
- cl_salv_table=>factory method is called to display the data as ALV output
Execute the program: