The following is a validation, using method check_mandatory_attr_on_view.
The common validation message is 'please fill in required field'.
However, if there are 5 mandatory fields, the same message comes out 5 times.
The code below has changed that, which has a customized message for each mandatory field.
It utilizes the both the 'report_attribute_t100_message' and check_mandatory_attr_on_view method.
An error message will come at the top of the screen, with the mandatory input fields highlighted in red.
method CHECK_REQUIRED .
* Data declaration
DATA:
lo_view_controller TYPE REF TO if_wd_view_controller,
lo_dyn TYPE REF TO cl_wd_dynamic_tool.
* Create Object
CREATE OBJECT lo_dyn.
DATA lt_messages TYPE lo_dyn->t_check_result_message_tab.
DATA ls_messages TYPE lo_dyn->t_check_result_message.
* Get view controller reference
lo_view_controller = wd_this->wd_get_api( ).
CALL METHOD cl_wd_dynamic_tool=>check_mandatory_attr_on_view
EXPORTING
view_controller = lo_view_controller
display_messages = abap_false
IMPORTING
messages = lt_messages.
*-------------------------------------------------------------
DATA: lo_node TYPE REF TO if_wd_context_node.
DATA: lo_node_info TYPE REF TO if_wd_context_node_info.
DATA: lw_attr_info TYPE wdr_context_attribute_info.
DATA: lw_x030l TYPE x030l.
DATA: l_reptext TYPE reptext.
DATA: l_msg TYPE string.
DATA: l_msgv1 TYPE symsgv.
DATA: lt_msg TYPE cl_wd_dynamic_tool=>t_check_result_message_tab.
FIELD-SYMBOLS:
LIKE LINE OF lt_msg.
DATA: lo_componentcontroller TYPE REF TO ig_componentcontroller
, lo_current_controller TYPE REF TO if_wd_controller
, lo_view_controllerz TYPE REF TO if_wd_view_controller
, lo_message_manager TYPE REF TO if_wd_message_manager
.
lo_current_controller ?= wd_this->wd_get_api( ).
lo_message_manager = lo_current_controller->get_message_manager( ).
lo_view_controllerz = wd_this->wd_get_api( ).
wd_assist->CHG_MANDATORY_MSG( exporting it_msg = lt_messages
io_msg_manager = lo_message_manager
i_msgid = 'ZNAN_VISIBLE'
i_msgno = '001' ).
endmethod.
method CHG_MANDATORY_MSG.
* The following are the parameters
* IT_MSG TYPE CL_WD_DYNAMIC_TOOL=>T_CHECK_RESULT_MESSAGE_TAB.
* IO_MSG_MANAGER TYPE REF TO IF_WD_MESSAGE_MANAGER.
* I_MSGID TYPE SYMSGID
* I_MSGNO TYPE SYMSGNO
method CHG_MANDATORY_MSG.
DATA: lo_node TYPE REF TO if_wd_context_node.
DATA: lo_node_info TYPE REF TO if_wd_context_node_info.
DATA: lw_attr_info TYPE wdr_context_attribute_info.
DATA: lw_x030l TYPE x030l.
DATA: l_reptext TYPE reptext.
DATA: l_msg TYPE string.
DATA: l_msgv1 TYPE symsgv.
DATA: l_message TYPE t_check_result_message.
FIELD-SYMBOLS:
LIKE LINE OF it_msg.
LOOP AT it_msg ASSIGNING
.
CALL METHOD
-context_element->get_node
RECEIVING
node = lo_node.
CALL METHOD lo_node->get_node_info
RECEIVING
node_info = lo_node_info.
CALL METHOD lo_node_info->get_attribute
EXPORTING
name =
-attribute_name
RECEIVING
attribute_info = lw_attr_info.
CALL METHOD lw_attr_info-rtti->get_ddic_header
RECEIVING
p_header = lw_x030l.
SELECT SINGLE scrtext_l FROM dd04t
INTO l_msgv1 WHERE
rollname = lw_x030l-tabname AND
ddlanguage = sy-langu AND
as4local = 'A'.
MESSAGE
ID
i_msgid
TYPE
-t100_message-msgty
NUMBER
i_msgno
WITH
l_msgv1
INTO l_msg.
CLEAR: l_message.
l_message-context_element =
-context_element.
l_message-attribute_name =
-attribute_name.
l_message-t100_message-msgty = 'E'.
l_message-t100_message-msgid = i_msgid.
l_message-t100_message-msgno = i_msgno.
l_message-t100_message-MSGV1 = l_msgv1.
CALL METHOD io_msg_manager->report_attribute_t100_message(
EXPORTING
msg = l_message-t100_message
element =
-context_element
attribute_name =
-attribute_name ).
* CALL METHOD io_msg_manager->report_error_message
* EXPORTING
* message_text = l_msg
* ENABLE_MESSAGE_NAVIGATION = abap_true.
ENDLOOP.
endmethod.