Currently Being Moderated

I was searching for an option to highlight select option fields when displaying the error using the method REPORT_ELEMENT_ERROR_MESSAGE / REPORT_ATTRIBUTE_MESSAGE of the message manager. I tried searching for a solution on the net but to no avail.

So after a lot of hit and trials and with my limited knowledge of OOPS I was finally able to get the reference to the runtime element associated with the select option fields by using the ROOT_NODE attribute of the select option interface controller.

Below is a walk through for an example component:

 

1. Create a component in SE80.

 

2. Declare usage of Select Options component.

 

3. Create the Select Options usage in the view.

 

4. In the main view insert a View Container element and a button.

 

5. Code the following in the WDDOINIT method of the view.

METHOD wddoinit.

   DATA:
         lo_ref_cmp_usage  TYPE REF TO  if_wd_component_usage,
         lo_select_options TYPE REF TO  iwci_wdr_select_options,
         lo_helper         TYPE REF TO  if_wd_select_options,

         li_range          TYPE REF TO  data.

   lo_ref_cmp_usage = wd_this->wd_cpuse_sel_opt( ).
   IF lo_ref_cmp_usage->has_active_component( ) IS INITIAL.
     lo_ref_cmp_usage->create_component( ).
   ENDIF.

   lo_select_options = wd_this->wd_cpifc_sel_opt( ).
   "call the interface controller method init_selection_screen to get the helper class
   lo_helper = lo_select_options->init_selection_screen( ).

   "Use the helper class to create a range table for the data element
   li_range = lo_helper->create_range_table( 'S_CARR_ID' ).

   "generate select option for the field
   lo_helper->add_selection_field(
           i_id                         = 'CARRID'
           i_description                = 'Airline Code'
           it_result                    = li_range ).

ENDMETHOD.

 

6. Create an action for the button and code the below lines in its handler method.

METHOD onactionon_click.

   DATA lo_controller  TYPE REF TO  if_wd_controller.
   DATA lo_element     TYPE REF TO  if_wd_context_element.
   DATA lo_child_node  TYPE REF TO  if_wd_context_node.
   DATA lo_context     TYPE REF TO  if_wd_context.
   DATA lo_mes         TYPE REF TO  if_wd_message_manager.
   DATA lv_id          TYPE        string.                  "#EC NEEDED
   DATA lo_select_options TYPE REF TO  iwci_wdr_select_options.

   lo_select_options = wd_this->wd_cpifc_sel_opt( ).
   lo_controller = lo_select_options->wd_get_api( ).
   lo_context = lo_controller->get_context( ).
   lo_child_node = lo_context->root_node->get_child_node( 'CARRID' ).

   lo_element = lo_child_node->get_element( ).

   lo_mes = lo_controller->get_message_manager( ).

* report message
   lo_mes->report_attribute_message(
     EXPORTING
       message_text   = 'Custom message'
       element        = lo_element
       attribute_name = 'LOW'          "'HIGH' too may be passed, passing nothing will highlight both low and high cells
     RECEIVING
       message_id   = lv_id ).

ENDMETHOD.

 

7. Embed the select option component view in the view container element.

 

 

8. Activate everything.

 

9. Create an application and execute.

 

10. Press Highlight button and you'll see the select option 'low' fields highlighted in red with your message.

Comments

Actions

Filter Blog

By author:
By date:
By tag: