Web Dynpro – Select-Options – writing the code

Home / SAP / ABAP Coding / Web Dynpro – Select-Options – writing the code

Here’s the code to do  SELECT-OPTIONS in ABAP Web Dynpro:

* Adding a block (type Tray) to the select-options
i_id         = `COM2`
i_block_type = if_wd_select_options=>mc_block_type_tray
i_title      = `Sales Selection` ).

As promised, I’ll talk about what I leaned in doing the actual method to put the select-options together for a full screen.  Everything I talk about deals with the add_selection_fields (notice the plural).  I had a bunch of fields, so I chose to do them all at once.

Here’s the basics, based on the name of the usage component.  I don’t know all the details on this portion…  but trust me, it works.  it came from SAP.  =)

* reference to the item table for multiple lines.
* reference to the select option usage controller
lo_ref_cmp_usage TYPE REF TO if_wd_component_usage.

* instantiate the usage component, if necessary
lo_ref_cmp_usage = wd_this->wd_cpuse_usage_so_comm( ).
IF lo_ref_cmp_usage->has_active_component( ) is INITIAL.
lo_ref_cmp_usage->create_component( ).

* determine referece to the interface controller
wd_this->go_ic_so_com = wd_this->wd_cpifc_usage_so_comm( ).
* initialize selection screen
wd_this->go_so_com = wd_this->go_ic_so_com->init_selection_screen( ).

If you want to turn off the default buttons that show up for select options.  I wasn’t a fan, but I may change my mind in the future.  Either way, you can turn it off with the following code:

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

If you want to add a block, here’s the code to do so.  One of the things to note, be sure to capitalize all the letters.  I also found that it worked better being 4 digits.  I tried comsel_1, and it failed, then comsel1, and it also failed.

* Adding a block (type Tray) to the select-options
i_id         = `COM2`
i_block_type = if_wd_select_options=>mc_block_type_tray
i_title      = `Sales Selection` ).

This little code snippet shows you the basics of adding a field.

*** begin building selection screen
*This is the field name
wa_fields-m_id = ‘SRV_MAT’.
* generate range table for data element.  Be sure to make this equal to the data element.
wa_fields-mt_range_table = wd_this->go_so_com->create_range_table(
i_typename = ‘MATSV’ ).
* if you choose to embed the field inside of a context block (box) you can add it here.
wa_fields-m_within_block = ‘COM1’.
* use this line to turn on the drop down for the field
wa_fields-m_value_help_type = if_wd_value_help_handler=>co_prefix_searchhelp.
* here is the search help to use for the field
wa_fields-m_value_help_id = ‘MAT1’.
append wa_fields to lt_fields.
CLEAR wa_fields.

Finally, once you have all of your fields entered, you can call the method.  If you followed all of the steps in my previous post, you should be able to see your select options showing up on the screen.

* generate field in selection screen
it_fields = lt_fields ).

Next up, I’ll talk about adding multiple Select-Options onto the same screen (if you have multiple tabs, this could come in handy).

Thanks for reading,


As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,

Leave a Reply

Your email address will not be published. Required fields are marked *