We all know that, the mandatory checks on a view can be done by using method CHECK_MANDATORY_ATTR_ON_VIEW( ) of class CL_WD_DYNAMIC_TOOL.
Yes, it works great, but it displays an error message "Fill all required entry fields" for every attribute. i.e. if we have 100 attributes, we get 100 error messages displayed.
Initial output:
Error messages from mandatory checks... it shows a message per attribute
A huge scroll bar appears for all messages and its very tedious job to navigate to each and every message. Also, it occupies lot of place on the top of view.
Okay, then what to do ?
if we want to display only one message for all required/mandatory fields of the given context element.
The solution:
The solution looks cool is n't it?
Write the below code in WDDOBEFOREACTION( ) method of view.
Note: here the messages are shown per context element i.e. if we have a view with many context node's attributes, we get one message per context element.
WDDOBEFOREACTION( ) |
---|
METHOD wddobeforeaction . DATA lo_api_controller TYPE REF TO if_wd_view_controller. DATA lo_action TYPE REF TO if_wd_action. DATA lo_message_manager TYPE REF TO if_wd_message_manager. DATA lt_attributes TYPE string_table. DATA lt_messages TYPE cl_wd_dynamic_tool=>t_check_result_message_tab. DATA ls_messages LIKE LINE OF lt_messages. lo_api_controller = wd_this->wd_get_api( ). lo_action = lo_api_controller->get_current_action( ). CALL METHOD lo_api_controller->get_message_manager RECEIVING message_manager = lo_message_manager. IF lo_action IS BOUND. CASE lo_action->name. WHEN 'CHECK_DATA'. cl_wd_dynamic_tool=>check_mandatory_attr_on_view( EXPORTING view_controller = lo_api_controller display_messages = abap_false IMPORTING messages = lt_messages ). CLEAR lt_attributes. "sort by context element, SORT lt_messages BY context_element. LOOP AT lt_messages INTO ls_messages. APPEND ls_messages-attribute_name TO lt_attributes. AT END OF context_element. " if no attributes found for errors, skip error message IF lt_attributes[] IS INITIAL. CONTINUE. ENDIF. " report message CALL METHOD lo_message_manager->report_element_error_message EXPORTING message_text = 'Please fill all required fields' element = ls_messages-context_element attributes = lt_attributes.
"Clear attributes list, for next context element CLEAR lt_attributes. ENDAT. ENDLOOP. ENDCASE. ENDIF. ENDMETHOD. |
Displaying Only one error message per context element
User fills all the required fields in section 1 and presses the check_data button,
-------------------------------------
Hope this helps for those have requirement for displaying single message per section ( context element )
Also, check the below document for reporting single message for all attributes of a context node in WDA
------------------------------------
Your valuable feedback / suggestions / comments are always welcome
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |