Tuesday, June 30, 2009

WebDynpro: Issue message with reference to an attribute

In normal ABAP reporting we can check the selection screen and do some checks on a field. If there is a problem an error relevant to the selection field is issued. e.g.

AT SELECTION-SCREEN ON p_carrid.
  IF p_carrid IS INITIAL.
    MESSAGE 'Please enter a value' TYPE 'E'.
  ENDIF. 

I am going to list out the process of doing the same in case of a WebDynpro. I have got a simple WD component, the layout of which is:

image

So just 2 input fields called VALUE1 and VALUE2 attached to this context:

image

We want to issue message on the field VALUE1 when the user presses the button GO. For that we will make use of the method WDDOBEFOREACTION, which gets triggered on user action. Double click on that method and go into the code section. Using the code wizard, 1) choose the option of “Read Context –> Node/Attribute” and select VALUE1 (take any actually). You should get code as below:

  DATA:
    node_node                           TYPE REF TO if_wd_context_node,
    elem_node                           TYPE REF TO if_wd_context_element,
    stru_node                           TYPE if_main=>element_node ,
    item_value1                         LIKE stru_node-value1.
* navigate from <CONTEXT> to <NODE> via lead selection
  node_node = wd_context->get_child_node( name = if_main=>wdctx_node ).
* get element via lead selection
  elem_node = node_node->get_element(  ).

I have deleted the extra code beyond “elem_node = node_node->get_element( )” as that is not needed. This will give us a handle to the element of the node. Now for the step 2) click on the code wizard and choose “Generate Message” and in the method take REPORT_ATTRIBUTE_ERROR_MESSAGE. This will generated the code for issuing message and highlighting the relevant field in the process: The code generated is:

* get message manager
  DATA: l_current_controller TYPE REF TO if_wd_controller,
        l_message_manager    TYPE REF TO if_wd_message_manager.
  l_current_controller ?= wd_this->wd_get_api( ).
  CALL METHOD l_current_controller->get_message_manager
    RECEIVING
      message_manager = l_message_manager.
* report message
  CALL METHOD l_message_manager->report_attribute_error_message
    EXPORTING
      message_text        = 'Enter some value'
      element             = elem_node
      attribute_name      = 'VALUE1'
*    PARAMS              =
*    MSG_USER_DATA       =
*    IS_PERMANENT        =
*    SCOPE_PERMANENT_MSG = CO_MSG_SCOPE_CTXT_ELEMENT
*    MSG_INDEX           =
      .

The method REPORT_ATTRIBUTE_ERROR_MESSAGE needs the message text, element reference (elem_node in our case) and the field to highlight (VALUE1 for this example). So lets how it comes out.

Initial screen is:

image

On pressing Go we get:

image

One can also try the other methods in the code wizard for issuing messages.

2 comments:

itdocs said...

Hi,
could you please drop me an email please ?
this is eddai from http://sapdocs.info

sirisha said...
This comment has been removed by the author.