placeholder concept in web dynpro ABAP – display dynamic text in web dynpro messages
Many times in Web dynpro application it is required to display some error mesaage along with the user entered value.
For example , if there is a field on the application screen “Material number” and we need to do a validation whether the user entered material number exist in the mara table or not, if not then a message “material number 1245632 is not present in the material master” should be displaed in the message area.
For achieving this we will be using the concept of placeholder. i.e we will create the message like
“material number &X1 is not present in the material master” —- > &X1 is the place holder.
and will pass the value of this place holder at run time to the method which will display the error message.
We will place our logic inside “WDDOBEFOREACTION” of the corresponding view as all the validations should be done here only.
data : lo_el_matnr type REF TO if_wd_context_element.
data : lo_nd_matnr type REF TO if_wd_context_node.
data : lo_api_controller TYPE REF TO if_wd_controller.
data : lo_message_manager TYPE REF TO if_wd_message_manager.
data : it_parm type WDR_NAME_VALUE_LIST,
is_parm TYPE WDR_NAME_VALUE.
lo_nd_matnr = wd_context->get_child_node( name = ‘MARA’ ).
lo_el_matnr = lo_nd_matnr->get_element( ).
lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager.
is_parm-name = ‘X1’. ” PLACE HOLDER value
is_parm-value = g_v_materno ” g_v_materno …contain the value entered by the user
APPEND is_parm TO it_parm.
* report message
CALL METHOD lo_message_manager->report_attribute_message
EXPORTING
message_text = “material number &X1 is not present in the material master”
element = lo_el_matnr
params = iT_parm.
.
Note : you can also use multiple placeholder in the message in that case you have to pass the value of all the placeholder used.
like ….
is_parm-name = ‘X1’. ” PLACE HOLDER value
is_parm-value = g_v_materno ” g_v_materno …contain the value entered by the user
APPEND is_parm TO it_parm.
is_parm-name = ‘X2’. ” PLACE HOLDER value
is_parm-value = g_v_materdes ” g_v_materno …contain the value entered by the user
APPEND is_parm TO it_parm.
Hope this was usefull for you.
Thanks,
Gejo john