Show TOC

Calling (Sub) ControllersLocate this document in the navigation structure

Use

Subcontrollers can be instantiated and called by a subordinate controller (main controller) or by a view or a page.

Recommendation

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 an SAP Web AS 6.20 system.

  • You have crated at least one Controller for your BSP application, or at least a main and a subcontroller.

Procedure

Calling Controllers

  1. Create the controller instance. You have the following options:

    • data: l_ctrl type ref to cl_bsp_controller2.

      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.

    Note

    You can also specify each of the controller IDs.

  2. If necessary, set the request parameters:

    l_ctrl->do_initattributes( ).

  3. Set additional attributes:

    l_ctrl->set_attribute( name = name value = value ).

  4. Call the request:

    call_controller( l_ctrl ).

Calling (Sub) Controllers

  1. Instantiate your subcontroller. 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' ).

    Caution

    Ensure that the controller_id is specified.

  2. Call your subcontroller.

    • 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:

      1. data: l_ctrl type ref to cl_bsp_controller2.

        l_ctrl = create_controller( key = navigation_key ).

        or

      2. 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.

      1. <bsp:call comp_id = "…"/>

        Note that the instantiation using the controller_id must have already taken place.

      2. <bsp:call url = "…" comp_id = "…"/>

        A controller instance is generated if no controller is created under the comp_id.

      3. <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.

  3. 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 subcontroller if you know its class. Of course, you can also set the subcontroller's public attributes directly.

    • You can execute the parameter transfer from the view.

      <bsp:call>

      <bsp:parameter name = "…" value = "…" />

      </bsp:call>