Skip to Content
Author's profile photo Ajaya Kumar

How to control empty mandatory field error messages

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
      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.
  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 ).
  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 ).


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! 

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Greetings Ajay,

      Thanks for the share and am trying to implement this kind, but still it showing the empty mandatory field error messages when after i tried for search help of CONTACT field.



      Author's profile photo Ajaya Kumar
      Ajaya Kumar
      Blog Post Author

      Hi Savaridasan,

      These are different error messages and not due to mandatory field check in view configuration, whereas the above document only talks about handling mandatory field check error messages.

      These error messages( as per your screen shot) generally come, when we define at least one value for partner function (i.e Sold to party) in partner determination procedure.



      Author's profile photo Former Member
      Former Member

      Greetings Ajay,

      Thank you so much to make understood 🙂 Good Day 🙂



      Author's profile photo Kavindra Joshi
      Kavindra Joshi

      Hi Ajaya ,

      Very few times , I have come across a code snippet which when put to the respective method compiles without syntax error and works. This reflects the quality of the effort you have put in.

      Take a bow.

      Also the coding has to be done in the view where the fields are marked mandatory.(Normally the Header ).



      Author's profile photo Former Member
      Former Member

      Very Nicely Documented Ajaya Kumar

      Thanks and Regards,

      Nikhil Kulkarni