!--a11y-->
Calling (Sub) Controllers
Use
Sub-controllers can be instantiated and called by a subordinate controller (main controller) or by a view or a page.
We recommend that a subordinate controller in method
DO_INIT creates a sub-controller, sets the parameters accordingly and then calls the sub-controller from the appropriate view.
Prerequisites
You are in a system from SAP Web AS 6.20.
You have crated at least one controller for your BSP application, or at least a main and a sub-controller.
Calling a Controller
Create the controller instance. You have the following options:
data: l_ctrl type ref to cl_bsp_controller.
l_ctrl = create_controller( key = navigation_key ).
or
l_ctrl = create_controller( application_namespace = 'fred'
application_name = 'hugo' controller_name = 'do_something.do' ).
application_namespace
and application_name are optional. Unless you specify otherwise, the system uses the current values.
You can also specify each of the controller IDs.
- If necessary, set the request parameters:
l_ctrl->do_initattributes( ).
Set additional attributes:
l_ctrl->set_attribute( name = name value = value ).
Call the request:
call_controller( l_ctrl ).
Calling (Sub) Controllers
Instantiate your sub-controller.
Create your sub-controller in method DO_INIT:
subcontroller = create_controller (controller_name = ‚name.do‘
controller_id = 'id' ).
Example:
flightdetails ?= create_controller( controller_name = 'flightdetails.do'
controller_id = 'fld' ).
Ensure that the controller_id is specified.
Call your sub-controller.
- You can execute the call from the controller.
This makes sense in particular if the calling controller does not control a layout. There are two call options here:
data: l_ctrl type ref to cl_bsp_controller.
l_ctrl = create_controller( key = navigation_key ).
or
l_ctrl = create_controller( application_namespace = 'fred'
application_name = 'hugo' controller_name = 'do_something.do' ).
application_namespace and application_name are optional. Unless you specify otherwise, the system uses the current values.
- You can execute the call from the view. There are three call options here, which are all implemented using the
<bsp:call> BSP element. The comp_id used here corresponds to the controller_id from create_controller.
<bsp:call comp_id = "…"/>
Note that the instantiation using the controller_id must have already taken place.
<bsp:call url = "…" comp_id = "…"/>
A controller instance is generated if no controller is created under the comp_id.
<bsp:call key = "…" comp_id = "…"/>
A controller instance is generated if no controller is created under the comp_id. The key is taken from the navigation table.
- Determine the parameter transfer.
- You can execute the parameter transfer from the controller.
sub_controller -> set_attribute (name value)
To do this, use any public method of the sub-controller if you know its class. Of course, you can also set the sub-controller’s public attributes directly.
- You can execute the parameter transfer from the view.
<bsp:call>
<bsp:parameter name = "…" value = "…" />
</bsp:call>