Friday, March 9, 2012
In the previous post Web Dynpro ABAP - Message handling, discussed about IF_WD_MESSAGE_MANAGER and its methods.  Here we use two methods to show Success and Error message.
Fundamental principle of displaying any message in Web Dynpro
  • We define MESSAGE_AREA Ui element on view.
  • Define reference to IF_WD_MESSGE_MANAGER
  • Call method REPORT_SUCCESS  and pass text to show success message.
  • Call method REPORT_ERROR_MESSAGE  and pass text to show error message. 
  • Message Manager will display the message on view in the Message area. 
Example program 
  • Create Web Dynpro component and Save as local object. 
  • Go to view  -> Context tab -> Create node N1 and ADDRESS_TYPE inside the node.

  • Go to layout --> Place Input field and bind with context attribute. 
  • ---------------> Place one button 
  • ---------------> Place Message Area where you want to display messages. 
  • Create OnAction event for Button write code as shown below. 
  • Code for SHOW_MESSAGE action event 


METHOD onactionshow_message .
* Context related declaration
  DATA:
        lo_nd_n1          TYPE REF TO if_wd_context_node,
        lo_el_n1          TYPE REF TO if_wd_context_element,
        ls_n1             TYPE wd_this->element_n1.
* get message manager
  DATA:
        lo_api_controller  TYPE REF TO if_wd_controller,
        lo_message_manager TYPE REF TO if_wd_message_manager.
* Structure and variables
  DATA:
        ls_t591s           TYPE t591s,
        lv_msg             TYPE string.

*   navigate from <context> to <n1> via lead selection
  lo_nd_n1 = wd_context->get_child_node( name = wd_this->wdctx_n1 ).

*   get element via lead selection
  lo_el_n1 = lo_nd_n1->get_element( ).

*   get all declared attributes
  lo_el_n1->get_static_attributes(
    IMPORTING
      static_attributes = ls_n1 ).
  SELECT SINGLE *
    FROM  t591s
    INTO ls_t591s
   WHERE sprsl = sy-langu
     AND infty  = '0006'
     AND  subty  = ls_n1-address_type.
  IF sy-subrc EQ 0.
    "Success message display
    lo_api_controller ?= wd_this->wd_get_api( ).
    CALL METHOD lo_api_controller->get_message_manager
      RECEIVING
        message_manager = lo_message_manager.
    CONCATENATE 'Selected addrees is:' ls_t591s-stext INTO lv_msg SEPARATED BY space.
* report message
    CALL METHOD lo_message_manager->report_success
      EXPORTING
        message_text = lv_msg.

  ELSE.
    "Error message display
    lo_api_controller ?= wd_this->wd_get_api( ).
    CALL METHOD lo_api_controller->get_message_manager
      RECEIVING
        message_manager = lo_message_manager.
* report message
    CALL METHOD lo_message_manager->report_error_message
      EXPORTING
        message_text = 'Please enter correct address type'.

  ENDIF.
ENDMETHOD.
  • Create Web Dynpro Application and save. 

  • Execute the Web Dynpro application.  



3 comments:

  1. Hi,

    You have a nice and very helpful blog...

    I am facing one issue.. Is it possible for you to helpme..

    Issue is: need to display error/warning message and it is showing in the top. But the user need to scroll up to see the message. I mean, when they click on a button, the warning message not showing up right away... user need to scroll the vertical scroll bar to top, to see the error message..

    can you guide me on this.

    Regards,
    Akila

    ReplyDelete
  2. Nice tutorial, easily understandable.

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.