Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
ajaya_kumar
Active Participant

When there are some empty mandatory fields on web UI then system displays error messages saying 'Make an entry in field XXXX'. Here system doesn't wait for the user to provide values to empty mandatory fields just display the message on a round trip, which is kind of annoying to user.

In this scenario, some customer raise a request that these empty mandatory fields error messages should be displayed on web UI only when user performs certain action like click on save button or navigate away from the current view and should not be displayed if user just press the ENTER key or select some value from search-help etc.

To address this requirement we can make use of DO_FINISH_INPUT() method of the view controller. The code for the same would be similar to:

  

METHOD do_finish_input.
  DATA : lt_mandatory_fields TYPE bsp_dlct_fieldname,
         lv_element_id       TYPE bsp_dlc_element_id,
         lv_cnode_name       TYPE string,
         lv_attr             TYPE string,
         lv_label            TYPE string,
         lv_event            TYPE string,
         lr_cnode            TYPE REF TO cl_bsp_wd_context_node,
         lr_view_descriptor  TYPE REF TO if_bsp_dlc_view_descriptor.
  CALL METHOD super->do_finish_input
    EXPORTING
      global_event    = global_event
      global_messages = global_messages.
  lt_mandatory_fields = get_empty_mandatory_fields( ).
  lv_event = global_event.
  SPLIT lv_event AT '.' INTO lv_event lv_event.
  TRANSLATE lv_event TO UPPER CASE.
  IF   lv_event = 'SUBMITONENTER' OR lv_event = 'BACK'. " dont display empty mandatory fields error messages for ENTER event or Back event.
    global_messages->delete_message( condition = cl_bsp_wd_view_controller=>co_mandatory_field_empty ).
  ENDIF.
  IF   lv_event = 'SAVE' .    " Display empty mandatory field error messages only for save event
    IF me->configuration_descr IS BOUND .
      lr_view_descriptor = me->configuration_descr->get_property_descriptor( ).
      LOOP AT lt_mandatory_fields INTO lv_element_id.
        CLEAR : lv_cnode_name, lv_attr, lv_label.
        SPLIT lv_element_id+2(*) AT '/' INTO lv_cnode_name lv_attr.
        lr_cnode ?= me->get_model( lv_cnode_name ).
        lv_label = lr_view_descriptor->get_field_label( iv_element_id   = lv_element_id
                                                        iv_context_node = lr_cnode ).
        IF global_messages IS BOUND.
          global_messages->add_message( condition = cl_bsp_wd_view_controller=>co_mandatory_field_empty
                                       message   = text-010
                                       severity  = cl_bsp_messages=>co_severity_error
                                       p1        = lv_label
                                       dummy     = me->component_id ).
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDMETHOD.

  

We can make use of global_event variable which holds the current event and put conditions for all such events for which we do want to see empty mandatory field error messages and want to see the error messages.

And you're done! 

5 Comments
Labels in this area