Creating a BSP using the Model View Controller ( MVC ) technique
This is Tutorial 2 in this mini series of BSP applications using MVC techniques and shows you how to create
a model class. The model class is used to perform functionality such as processing and retrieving data. If you have not created an MVC BSP before
you will need to do Tutorial 1 first which will only take a few minutes.
The steps below then adds functionality to the application created in tutorial 1.
METHOD select_details .
SELECT ebeln
UP TO 1 ROWS
INTO retvalue
FROM ekko.
ENDSELECT.
ENDMETHOD.
method DO_INIT.
*CALL METHOD SUPER->DO_INIT
* .
* Create refernece variable based on your own class (not created yet)
data: r_model TYPE REF TO zcl_model_01.
* Create an instance of our Model class and 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
r_model->select_details( ).
* 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.
endmethod.
<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<htmlb:content design="design2003">
<htmlb:page title = " ">
<htmlb:form>
<htmlb:textView text = "Purchase order"
design = "EMPHASIZED" />
<htmlb:inputField id = "ID1"
invalid = "false"
value = "<%=p_ord->retvalue%>"
required = "true"/><BR>
<htmlb:button text = "Press Me"
onClick = "myClickHandler" />
</htmlb:form>
</htmlb:page>
</htmlb:content>
METHOD do_request .
*CALL METHOD SUPER->DO_REQUEST
* .
DATA: r_view TYPE REF TO if_bsp_page.
r_view = create_view( view_name = 'main1.htm' ).
r_view->set_attribute( name = 'p_ord'
value = me->r_model ).
call_view( r_view ).
ENDMETHOD.
|
||||||||