Entering content frame

Procedure documentation Calling Components Locate the document in its SAP Library structure

Use

You can call a main controller, sub-controller in two ways:

  1. By creating the sub-controller in a method of the main controller
  2. By creating the sub-controller from a view

Note

Option A is more flexible than Option B, especially if the sub-controller should be initialized once only in method DO_INIT.

Procedure

Option A

  1. In method DO_INIT or DO_REQUEST, for example, add the following coding:
  2. ...

        data: addresscontroller type ref to CL_C_MYPROJ_ADDRESS.

    * create the controller

      addresscontroller ?= create_controller(

                              controller_name = 'address.do'

                              component_id = 'ad'

                               ).

    * set some attributes with a self defined method

      addresscontroller->Init_data( ... ).

    ...

     

    or

    ...

        data: subcontroller type ref to CL_BSP_CONTROLLER2.

    * create the controller

      subcontroller ?= create_controller(

                              controller_name = 'address.do'

                              controller_id = 'ad'

                               ).

    * set some attributes with standard method

      subcontroller->set_attributes( name = 'address'

                                     value = ship_address ).

      ...

     

  3. Call the controller in the view.
    Two components are called in the above example: the address component (
    address.do) and the flight component (flights.do).

COMPONENT_ID identifies the controller. In method CREATE_CONTROLLER this is the parameter COMPONENT_ID, and in <bsp:call>-element this is the attribute COMP_ID:

<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<%@extension name="bsp" prefix="bsp"%>

<htmlb:content id="ComponentTest" >
  <htmlb:page title = "Component Test">
    <H1>Component Test</H1>
    <htmlb:form id="myFormId" method="post">

       <htmlb:tray id    = "tray1"
              title       = "Address"
              design      = "form"
              width       = "350"
              isCollapsed = "false" >
           <bsp:call url="address.do" comp_id="ad">
           </bsp:call>
       </htmlb:tray>

       <htmlb:tray id     = "tray2"
              title       = "Flights"
              design      = "form"
              width       = "350"
              isCollapsed = "false" >
          <bsp:call url="flights.do" comp_id="fl">
          </bsp:call>
       </htmlb:tray>
      <p>
      <htmlb:button id="SAVE" text="SAVE DATA" onClick="SAVE" />
      <htmlb:button id="CANCEL" text="CANCEL" onClick="CANCEL" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

 

Option B

In this option, you do not need to create the sub-controller in the coding of the main controller. Instead you should only add the parameters to the view call, which then creates and calls the controller. In the following example, ship_address is an attribute of the view and is set by the controller:

<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<%@extension name="bsp" prefix="bsp"%>

<htmlb:content id="ComponentTest" >
  <htmlb:page title = "Component Test">
    <H1>Component Test</H1>
    <htmlb:form id="myFormId" method="post">

       <htmlb:tray id    = "tray1"
              title       = "Address"
              design      = "form"
              width       = "350"
              isCollapsed = "false" >
           <bsp:call url="address.do" comp_id="ad">
             <bsp:parameter name="address" value="<%=ship_address%>"/>
           </bsp:call>
       </htmlb:tray>

       <htmlb:tray id     = "tray2"
              title       = "Flights"
              design      = "form"
              width       = "350"
              isCollapsed = "false" >
          <bsp:call url="flights.do" comp_id="fl">
          </bsp:call>
       </htmlb:tray>
      <p>
      <htmlb:button id="SAVE" text="SAVE DATA" onClick="SAVE" />
      <htmlb:button id="CANCEL" text="CANCEL" onClick="CANCEL" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

 

Continue by Determining Input Processing.

Leaving content frame