Skip to Content

This post is part of a series on code snippets. The complete list of posts in the series is available in the document Code Snippets: A Blog Series.

Calling method CL_WD_DYNAMIC_TOOL=>CHECK_MANDATORY_ATTR_ON_VIEW during WDDOBEFOREACTION is a convenient way to check that a view’s required entry fields are filled prior to executing an action’s logic. Unfortunately, the method returns an identical message for each attribute not filled, resulting in duplicate messages.

With the advent of new ABAP language feature GROUP BY for internal tables introduced with ECC 740 SP08, developers have a new option to eliminate these duplicate messages while still highlighting multiple entry fields in error.

METHOD wddobeforeaction .

  DATA lt_attributes TYPE string_table.

* -- Check mandatory input fields

  cl_wd_dynamic_tool=>check_mandatory_attr_on_view(
    EXPORTING
      view_controller  = wd_this->wd_get_api( )
      display_messages = abap_false
    IMPORTING
      messages         = DATA(lt_messages)
  ).

  DATA(lo_controller) = CAST if_wd_controller( wd_this->wd_get_api( ) ).
  DATA(lo_msg_mgr) = lo_controller->get_message_manager( ).

* Eliminate duplication of message, "Fill all required entry fields".
  LOOP AT lt_messages ASSIGNING FIELD-SYMBOL(<msg>)
       GROUP BY ( key1 = <msg>-t100_message-msgid
                  key2 = <msg>-t100_message-msgno ).

    LOOP AT GROUP <msg> ASSIGNING FIELD-SYMBOL(<member>).
      APPEND <member>-attribute_name TO lt_attributes.
    ENDLOOP. " <member>

    lo_msg_mgr->report_element_t100_message(
      msg        = <msg>-t100_message
      element    = <msg>-context_element
      attributes = lt_attributes
    ).

  ENDLOOP. " <msg>

ENDMETHOD.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply