Here below there are simple steps to go with controllers to design a BSP Page.
First of all go In transaction SE 80 and create a BSP application below:
Then in it create a controller and provide the description and then click on create button..This will create your controller.
And then assign a name to the controller as 'main.do'.
Now ,click on the controller here assign a class name in Y or Z namespace whose super class is assigned as cl_bsp_controller2 :
When we assign here the superclass as above all the methods and attributes of the super class are inherited by the subclass created here by us as controller.
Now here we need to redefine the methods we need to use:
The methods we need are DO_INIT , DO_REQUEST and DO_HANDLE_EVENT. To get to know the way these events are in comparison to the normal bsp pages that we create with follow logic, we can see here https://wiki.sdn.sap.com/wiki/x/1ASXB(Comparison For Event Handlers in BSP with Flow Logic and Methods of the Controller Class).
DO_INIT behaves in the similar manner as the initialization works so here we do all the data selections. - Create reference variable based on your own class (not created yet in Z or Y namespace) for the model class having the super class as CL_BSP_MODEL and here we create a method for data selection.
- You can create this class in the SE24
Inside this the select query is written.
And u can call it in the initialization.
Otherwise there is no necessity to call a model class these steps can be done in the same controller only.
Here below when model class is there we go as this:
In the controller in DO_INIT write the following process code.
(this is done if model class is there in DO_INIT )
* Create an instance of our Model class
data: r_model type ref to zcl_model_01.
* Use a widening cast to load your reference variable r_model
r_model ?= me->create_model(
class_name = 'ZCL_MODEL_01'
model_id = 'mod_main' ).
* Use the r_model to call the select details method from your Model class
* Load attributes in your class attributes to hold the variable - make it
* more 'global' so it can be seen by other methods.
me->r_model = r_model.
Write in a simple way like here in DO_INIT,
In DO_REQUEST we define how the pages are to be called and the attributes we need to set and move with set_attributes same as we do in the flow logic in set_parameters.
Now in the attributes define the attributes that we have used here,
Now create a view for creating the layout and remember to check the radiobutton for view when creating the page, in which we need to display the table that we have created,
After creating the view we need to design the page and display the table through table view.
it is done as here,
In the page attributes, we define the table here also,
Now activate the whole application with the controller and the view and then execute it from the controller.
You can see the output as :