cancel
Showing results for 
Search instead for 
Did you mean: 

Error message display in web dynpro application?

Former Member
0 Kudos

Hi All,

In my web dynpro application I am displaying error messages but the focus does not go to the field where error occured and also if I click on the error message it does not lead to the place of error.

And also when I navigate to another view the error message does not go.

Below is my code:

*    report message
      DATA err1_text TYPE syst-msgv1.
      err1_text = wd_assist->if_wd_component_assistance~get_text( key = '002' ).
      CALL METHOD lo_message_manager->report_t100_message
        EXPORTING
          msgid      = 'ZAA'
          msgno      = '005'
          msgty      = 'E'
          p1         = err1_text
        RECEIVING
          message_id = lo_text.

Please suggest me the way to do it.

Thanks & Regards

Archana

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can use the method REPORT_ATTRIBUTE_T100_MESSAGE from the message manager interface IF_WD_MESSAGE_MANAGER. In this method you can specify the context attribute in the parameter ATTRIBUTE_NAME. Therefore it will highlight the input field.

For restricting the message to a view you need pass the view name in the parameter VIEW.

Former Member
0 Kudos

Hi Pooja,

The method suggested by you has a mandatory parameter called ELEMENT but the message which I am generating is on the condition of the element being null and this method is not accepting the null element. Please let me know what do you suggest for this.

Thanks & Regards

Archana

uday_gubbala2
Active Contributor
0 Kudos

Hi Archana,

Try using the report_attribute_error_message for throwing your error. Using this method the system would display all the error messages with a LinkToAction in the MessageArea. When the user clicks on the link the system would shift the focus to that particular element. Also all the elements where the error occured are highlighted in red coloured boxes. Refer the code snippet below:

For example in the code snippet below am looping through the records changed in an ALV and throwing an error message whenever the value entered is greater than or equal to 5.

Regards,

Uday

METHOD check_data.
  DATA: lr_node TYPE REF TO if_wd_context_node,
        lr_element TYPE REF TO if_wd_context_element,
        ls_modified_cells TYPE salv_wd_s_table_mod_cell.

  FIELD-SYMBOLS <temp> TYPE data.

* get message manager
  DATA lo_api_controller     TYPE REF TO if_wd_controller.
  DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

  lo_api_controller ?= wd_this->wd_get_api( ).

  CALL METHOD lo_api_controller->get_message_manager
    RECEIVING
      message_manager = lo_message_manager.

  lr_node = wd_context->get_child_node( name = 'NODE' ).

  LOOP AT r_param->t_modified_cells INTO ls_modified_cells.
    lr_element = lr_node->get_element( index = ls_modified_cells-index ).

    IF ls_modified_cells-attribute = 'TEMP_NEW'.
      ASSIGN ls_modified_cells-r_value->* TO <temp>.
      IF  <temp> GE 5.
* report message
        CALL METHOD lo_message_manager->report_attribute_error_message
          EXPORTING
            message_text   = 'You can only enter values which are less than 5!'
            element        = lr_element
            attribute_name = ls_modified_cells-attribute.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDMETHOD.

Former Member
0 Kudos

How do you have context element as null? The input field where the error occured must be bound to some context attribute right?

When initialize lead selection is set to true you get a element by default. You have to pass the element where the input field is bound to the context attribute.

Former Member
0 Kudos

Hi Pooja,

Have a look at the code

lo_nd_year_list = wd_context->get_child_node( name = wd_this->wdctx_year_list ).

*     get element via lead selection
    lo_el_year_list = lo_nd_year_list->get_element( ).

*    CHECK lo_el_year_list IS NOT INITIAL.

*     get single attribute
    lo_el_year_list->get_attribute(
      EXPORTING
        name =  `YEAR`
      IMPORTING
        value = lv_year ).

*     @TODO handle not set lead selection
    IF  lv_year  IS INITIAL.
      DATA lo_text TYPE string.
*    get message manager
      DATA lo_api_controller     TYPE REF TO if_wd_controller.
      DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

      lo_api_controller ?= wd_this->wd_get_api( ).

      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.

*    report message

      DATA ls_err TYPE symsg.
      DATA err1_text TYPE symsgv.
      err1_text = wd_assist->if_wd_component_assistance~get_text( key = '002' ).
      ls_err-msgty = 'E'.
      ls_err-msgid = 'ZAA'.
      ls_err-msgno = '005'.
      ls_err-msgv1 = err1_text.

      CALL METHOD lo_message_manager->report_attribute_t100_message
        EXPORTING
          msg            = ls_err
          element        = lo_el_year_list
          attribute_name = `YEAR`
          view           = 'V_SEL_OPT'
        RECEIVING
          message_id     = lo_text.

    ENDIF.

After executing it gives following error:

"Access via 'NULL' object reference not possible."

Former Member
0 Kudos

Please go to ST22 and find out exactly which line is giving this error.

Former Member
0 Kudos

I have seen in debug mode. The element lo_el_year_list remains initial.

Thats why its givin runtime error. when I do not fill the corresponding field, element remains initial only.

Former Member
0 Kudos

HI,

What is the cardinality for that node.

If it is 0:N or 1:N then use the get the element at index then use the meesage.

case 1 * get element via lead selection

lo_el_year_list = lo_nd_year_list->get_element( index = lv_index ).

  • get element via lead selection

lo_el_year_list = lo_nd_year_list->get_element( ). -


Error as NULL reference

If it 1:1 cardinalty there is no need of index.

  • get element via lead selection

lo_el_year_list = lo_nd_year_list->get_element( ).

This works fine.

Regards,

Lekha.

Former Member
0 Kudos

Yes, its cardinality is 0:n.

I have done that index thing.

See here the element is refering to the drop down box, when I do indexing it automatically takes the 1st entry of that. and I dont want this automatic picking to be done as I want only user to enter and in case its blank it should display error.

In this scenario there would always be a value. I guess I am stuck in a cyclic problem.

Anyways thanks for your time.

If you have any solution for this please let me know.

Thanks & Regards

Archana

Former Member
0 Kudos

Hi,

One query...

This is a year drop down and you want to get the selected value from the dorpdown where user selects right.

Where have you written that code.

Have you written it in the drop down(onselection)event or any other event.

Have you used the get_lead_selection_index to get that index value.

Before you use any reference variable alwyas try to chekc if the element is initial or not.

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha,

I have coded for this in one of the componentcontroller methods .

Please see the code below:

DATA lt_year_list TYPE wd_this->elements_year_list.
  DATA ls_year_list LIKE LINE OF lt_year_list .
  DATA: year1 TYPE char4,
        year2 TYPE char4,
        year3 TYPE char4,
        year TYPE sy-datum,
        n TYPE char4,
        z TYPE char4,
        year_main TYPE char9.
  year = sy-datum.
  year1 = 1997.
  year2 = 1998.
  year3 = year+0(4).
  n = year3 - year2.
  z = n + 1.

  DO z TIMES.
    year1 = year1 + 1.
    year2 = year2 + 1.
*  ls_year_list-SLNO = 1.  
    ls_year_list-key1 = year1.  
    ls_year_list-key2 = year2.  
    CONCATENATE year1 '-' year2 INTO year_main.
    ls_year_list-year = year_main.   
    APPEND ls_year_list TO lt_year_list.
  ENDDO.
* bind a single element
  node->bind_table(
    new_items             =  lt_year_list
    set_initial_elements = abap_true ).

Former Member
0 Kudos

Hi,

In the table entries there is an option for balnk value also. Is that right.

I was asking you about your previous code where you have handled the messages.

where have you wrriten that code in the dropdown(onselection event) or any where else..

lo_nd_year_list = wd_context->get_child_node( name = wd_this->wdctx_year_list ).
 
*     get element via lead selection
    lo_el_year_list = lo_nd_year_list->get_element( ).
 
*   IF lo_el_year_list IS NOT INITIAL.
 
*     get single attribute
    lo_el_year_list->get_attribute(
      EXPORTING
        name =  `YEAR`
      IMPORTING
        value = lv_year ).
 
*     @TODO handle not set lead selection
    IF  lv_year  IS INITIAL.
      DATA lo_text TYPE string.
*    get message manager
      DATA lo_api_controller     TYPE REF TO if_wd_controller.
      DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
 
      lo_api_controller ?= wd_this->wd_get_api( ).
 
      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.
 
*    report message
 
      DATA ls_err TYPE symsg.
      DATA err1_text TYPE symsgv.
      err1_text = wd_assist->if_wd_component_assistance~get_text( key = '002' ).
      ls_err-msgty = 'E'.
      ls_err-msgid = 'ZAA'.
      ls_err-msgno = '005'.
      ls_err-msgv1 = err1_text.
 
      CALL METHOD lo_message_manager->report_attribute_t100_message
        EXPORTING
          msg            = ls_err
          element        = lo_el_year_list
          attribute_name = `YEAR`
          view           = 'V_SEL_OPT'
        RECEIVING
          message_id     = lo_text.
 
    ENDIF.

endif.         " lo_el_year_list not intial. 

Regards,

Lekha.

Former Member
0 Kudos

Hi

There is no blank entry in the drop down. The drop down code and the message generation are in different methods.

The method is generated on onaction event which occurs after clicking button in the UI .

Former Member
0 Kudos

>

> Hi

> There is no blank entry in the drop down. The drop down code and the message generation are in different methods.

>

> The method is generated on onaction event which occurs after clicking button in the UI .

The correction is :

The 'message' is generated on onaction event which occurs after clicking button in the UI.

Former Member
0 Kudos

Hi,

You are raising the error in the Button handler right.

How can you get to know what the user has selected from the dropdown.

This can be handled only by getting the index right.

If there are no entries in the table with blank record then why you want to test the user has selected none from dropdown.

IS there any entry as <<SELECTED NONE>>/<<SELECT ONE>> or such entry where you want to test the element is initial so that you can throw the eror meesgae that Nothg is selected.

You can handle the code in the Button handler only by getting the element at that index as 0:N caridnality is there.

Regards,

Lekha.

Former Member
0 Kudos

No I am not using index to access the value. I am just fetching the current value of the attribute. And also when the drop down appears it does not have any default value, it is first initial only then when any value is selected from drop down a value is assigned to the element attribute.

Former Member
0 Kudos

Hi,

I got your point.. in the BIND_TABLE( set_intiail_elemts = abap_true) change this to ABAP_FALSE.

Because of this you are gettng the intiial values. Eventhough your table has no BALNK/space records.

  • bind a single element

node->bind_table(

new_items = lt_year_list

set_initial_elements = abap_true ).

change as

  • bind a single element

node->bind_table(

new_items = lt_year_list

set_initial_elements = abap_false ).

You can use this code - I have tjhe dropdwon for projects event I'm doing the same.

  • navigate from <CONTEXT> to <PROJECT> via lead selection

lo_nd_project = wd_context->get_child_node( 'PROJECT' ).

***Gets the selected project id from drop down

if lo_nd_project is not initial.

CALL METHOD lo_nd_project->GET_LEAD_SELECTION

RECEIVING

ELEMENT = lo_el_project.

  • get all declared attributes

if lo_el_project is not initial.

lo_el_project->get_static_attributes(

IMPORTING

static_attributes = ls_project ).

change your code to

lo_nd_year_list = wd_context->get_child_node( name = wd_this->wdctx_year_list ).

***Gets the selected project id from drop down

if lo_nd_year_list is not initial.

CALL METHOD lo_nd_year_list->GET_LEAD_SELECTION

RECEIVING

ELEMENT = lo_el_year_list .

  • IF lo_el_year_list IS NOT INITIAL.

  • get single attribute

lo_el_year_list->get_attribute(

EXPORTING

name = `YEAR`

IMPORTING

value = lv_year ).

Regards,

Lekha.

Former Member
0 Kudos

Hi Lekha

I think I am almost nearing the solution.

I have changed as you said to abap_false. But there is no effect on that.

Please let me know if I need to change something else somewhere.

Former Member
0 Kudos

Hi,

Use the GET_LEAD_SELECTION method as mentioned earlier. Here by there is no index being passed but what ever user selects that is given.

This will not throw any error.

Regards,

Lekha.

Former Member
0 Kudos

Yes I have tried this also. But I am sorry that is still throwing the run time error.

Former Member
0 Kudos

Hi,

If it is stil throwing errror. Please post teh ST22 code here. I think it is going dump for somewhere else.

Is the mapping of nodes correct.

GET_LEAD_SELECTION should work. The dump might be some where else.

Regards,

Lekha.

Answers (2)

Answers (2)

uday_gubbala2
Active Contributor
0 Kudos

So you can accordingly use the same logic to check for when your element has a NULL value & throw an error message using report_attribute_error_message.

Also regarding the problem that you had with the messages still being on shown after navigating to another view. Try specifying even your views name in the parameter VIEW while calling REPORT_T100_MESSAGE. But you wouldn't be able to realize the functionality of shifting focus to the desired element by using REPORT_T100_MESSAGE. You need to make use REPORT_ATTRIBUTE_ERROR_MESSAGE for achieving that functionality. The ELEMENT & ATTRIBUTE_NAME are the important one's while using this method.

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

The element which I am passing to this message is only null and thus I am getting run time error.

Actually I have to check this element only whether this is null or not and I cannot pass a null element to the ELEMENT parameter.How I get this now?

Former Member
0 Kudos

If lr_element is the reference to the element you can use the following code to check if its null or not.

IF lr_element IS NOT INITIAL.

write code to display error messge.

ENDIF.

arjun_thakur
Active Contributor
0 Kudos

Hi,

Refer the following thread: https://forums.sdn.sap.com/click.jspa?searchID=26746792&messageID=7407704

I hope it helps.

Regards

Arjun

Edited by: Arjun Thakur on May 29, 2009 12:19 PM