Creating a BSP using the Model View Controller ( MVC ) technique
Tutorial 1 - Creating the View & the controller (htm page & events)
Step 1 - Create new BSP Application
Using SE80 create BSP Application (I.e. Zbsp_usingmvc).
Step 2 - Create new Controller (main.do)
Right click on BSP application name and select create->controller. Enter name main.do or your own
name + description. Press the green tick to continue
Step 3 – Populate controller class (zcl_controller_01)
Enter the name of your controller class i.e. zcl_controller_01. We also need to create this class
so double click on the name. Yes.
Step 4 – Creating controller class
Once you have double clicked on the controller class name and pressed yes you will need to check the
properties tab and ensure its super class is CL_BSP_CONTROLLER2
Step 5 – Redefine Methods
You will have inherited a number of methods from the superclass. As these methods work in much the
same way as events do within classic BSPs and ABAP you will now need to redefine a number of these
methods. These are DO_INIT and DO_REQUEST
Step 6 – Redefine DO_INIT
Ensure you have this method available for change by pressing the pencil button. Place your cursor
on the method called DO_INIT and press the redefine button.
For this current example you dont have to do anything in this method but for a follow on exercise
you will be creating the MODEL instance in the DO_INIT method.
Step 7 – Redefine DO_REQUEST(call a layout of type VIEW)
Ensure you have this method available for change (done in previous step). Place your cursor
on the method called DO_REQUEST and press the redefine button. In the DO_request we will
call a layout(View). We create a reference variable referencing the page and then call the method
create_view and pass it the actual view (not yet created). We then call the view. Enter the
following code:
* Create reference variable from the interface if_bsp_page
DATA: r_view TYPE REF TO if_bsp_page.
* Create object r_view with view_name main1.htm
* Layout is provided by view main1.htm
r_view = create_view( view_name = 'main1.htm' ).
* Process view-> response is set accordingly
call_view( r_view ).
Step 8 – Create BSP Page (View)
Right click the BSP Application and create a new page called main1.htm. When this is done
make sure you save and activate it.
Step 9 – Activate whole BSP Application
Step 10 – Execute
Go to the controller main.do and double click. Use the test(execute) button to view the results.
Tutorial 1 Tutorial 2 Tutorial 3
|