Skip to end of metadata
Go to start of metadata

Author: David Pietroniro
Submitted: 08/12/2008
Related Links:


In this I will explain how to use complex select-options components like groups, parameters and select-options with default values and more. This assumes that you have a basic acknowledge of the Web Dynpro ABAP and have created a web dynpro component via Object Navigator (transaction SE80).

Defining the used components

Go to the web dynpro component and add a WDR_SELECT_OPTIONS component like follows:


Create a view by right clicking on the web dynpro component and choose Create->View. Define the view name as VI_MAIN.

Used Components

Now in tab Properties add the Used Components like follows:


Now in the Context tab create a new node with name T_SBOOK, cardinality 0..n and defines the Dictionary Structure SBOOK. Click on the button Add Attribute from Structure and add the fields like follows, the structure of the node must be the following:


Go to the Layout tab and insert a View Container UI Element with id VC_SEL_OPT. Finally add a table to the view layout, name it as TBL_SBOOK, right click the table and select the Create Binding option and bind the table to the T_SBOOK context. Defines the Cell Editor as TextView and bound the attributes to the property text:

The Layout structure now is:


In the Attributes tab add the attributes like follows:



This method is responsible to create the select-options, add the group, fields and set its default values.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
METHOD build_select_options .
    ty_r_date TYPE RANGE OF s_date,
    ty_s_date TYPE LINE OF ty_r_date.
* Reference variable used instantiate the select-options component
    lr_cmp_usage TYPE REF TO if_wd_component_usage.
* Variables used to create the select-options fields and
* define its initial values
    lr_field TYPE REF TO data,
    ls_date  TYPE ty_s_date.
    <fs_field> TYPE ANY,
    <fs_range> TYPE INDEX TABLE.

* Instantiate the select-options component
  lr_cmp_usage = wd_this->wd_cpuse_cmp_sel_opt( ).
  IF lr_cmp_usage->has_active_component( ) IS INITIAL.
    lr_cmp_usage->create_component( ).

* Sets the helper reference
  wd_this->m_sel_opt = wd_this->wd_cpifc_cmp_sel_opt( ).
  wd_this->m_helper  = wd_this->m_sel_opt->init_selection_screen( ).

* Hide the standard select-options components.
    i_display_btn_cancel = abap_false
    i_display_btn_check  = abap_false
    i_display_btn_reset  = abap_false ).

* Adding a block (type Tray) to the select-options
    i_id         = `BL01`
    i_block_type = if_wd_select_options=>mc_block_type_tray
    i_title      = `Flight Booking` ).

* Adding a parameter field to the created block
* Create a reference to the type of airline code
  CREATE DATA lr_field TYPE s_carr_id.
* Sets the airline code initial value
  ASSIGN lr_field->* TO <fs_field>.
  <fs_field> = 'AA '.
* Add the parameter to the group
    i_id           = `CARRID`
    i_within_block = `BL01`
    i_value        = lr_field ).
  FREE lr_field.
  UNASSIGN <fs_field>.

* Adding a select-options field to the created block
* Create a reference to the connection number range table
  lr_field = wd_this->m_helper->create_range_table( `S_CONN_ID` ).
* Add the select-option to the group
    i_id           = `CONNID`
    i_within_block = `BL01`
    it_result      = lr_field ).
  FREE lr_field.

* Adding a select-options field to the created block
* Create a reference to the flight date range table
  lr_field = wd_this->m_helper->create_range_table( `S_DATE` ).
  ASSIGN lr_field->* TO <fs_range>.
  ls_date-sign   = 'I'.
  ls_date-option = 'EQ'.
  ls_date-low    = sy-datum - 7.
  ls_date-high   = sy-datum.
  APPEND ls_date TO <fs_range>.
* Add the select-option to the group
    i_id           = `FLDATE`
    i_within_block = `BL01`
    it_result      = lr_field ).

 This method is an Event Handler for the event ON_EXECUTE of the component CMP_SEL_OPT and will retrieve the data from the select-options and the database and then bind it to the context node S_BOOK.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
 METHOD execute_search .
    lty_r_connid TYPE RANGE OF s_conn_id,
    lty_r_fldate TYPE RANGE OF s_date.
    lr_sbook    TYPE REF TO if_wd_context_node.
* Variables used to retrieve the values of select-options fields
    lt_sel_item TYPE if_wd_select_options=>tt_selection_screen_item.
    <fs_sel_item> LIKE LINE OF lt_sel_item,
    <fs_carrid>   TYPE s_carr_id,
    <fs_connid>   TYPE lty_r_connid,
    <fs_fldate>   TYPE lty_r_fldate.

* Get the selection-screen items
    IMPORTING et_selection_screen_items = lt_sel_item ).

* Retrieve the values from the select-options items
  LOOP AT lt_sel_item ASSIGNING <fs_sel_item>.
    CASE <fs_sel_item>-m_id.
      WHEN `CARRID`.
        ASSIGN <fs_sel_item>-m_value->* TO <fs_carrid>.
      WHEN `CONNID`.
        ASSIGN <fs_sel_item>-mt_range_table->* TO <fs_connid>.
      WHEN `FLDATE`.
        ASSIGN <fs_sel_item>-mt_range_table->* TO <fs_fldate>.

* Retrieve the data from the database, for simplicity, the
* SELECT statement has been implemented here.
  SELECT * FROM sbook
    INTO TABLE wd_this->t_sbook
    WHERE carrid = <fs_carrid>
      AND connid IN <fs_connid>
      AND fldate IN <fs_fldate>.

* Bind the data to the context
  lr_sbook = wd_context->get_child_node( name = `T_SBOOK`).
  lr_sbook->bind_table( wd_this->t_sbook ).


Include a call to the method responsible by create the select-options.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
method WDDOINIT .
  wd_this->build_select_options( ).


Now in the window right click on the VC_SEL_OPT view and embed a view like follows:


Now create a web dynpro application and test it, the result must be like follows:

And after click the button Copy:

If you would like more information about select-options see the web dynpro component WDR_TEST_SELECT_OPTIONS in your SAP system.