How to check if fields are required in ABAP
Hello everyone,
in my first post I would like to present a way to check if required fields are filled. Below you will find data declaration, that will be used:
DATA: l_node TYPE REF TO if_wd_context_node,
l_attr_list TYPE cl_wd_dynamic_tool=>t_check_mandattr_tab,
l_attr TYPE cl_wd_dynamic_tool=>t_check_mandattr_struct,
l_has_errors TYPE wdy_boolean.
Reference to node (l_node) which attributes will be checked, list of attributes (l_attr_list) and a flag (l_has_errors) to indicate if check was with errors.
The next step is to fill list with attribute name(s):
l_attr-node_path = wd_this->wdctx_pmb_md_edit.
l_attr–element_index = –1.
l_attr–attribute_name = ‘KTEXT’.
APPEND l_attr TO l_attr_list.
*here more attributes can be filled if needed
*check for required fields
l_has_errors = cl_wd_dynamic_tool=>check_mandatory_attributes(
attribute_list = l_attr_list
display_messages = abap_true
context_root = wd_context ).
IF l_has_errors EQ ‘X’.
EXIT.
ENDIF.
I hope you will find it useful.
Best regards,
Paul
This required field check we can do directly also right ?, without doing so many things.. just read the node and check the field if it's initial then show an error message.
Hi,
yes, we can do it manually, but when check is preformed via cl_wd_dynamic_tool=>check_mandatory_attributes message will pop up automatically and empty fields will be highlighted.
BR
Paul