cancel
Showing results for 
Search instead for 
Did you mean: 

How to Display Error Messages

Former Member
0 Kudos

Hi,

I have a view1 which has select-options. When the user enters some value in the select-options and clicks on the submit button, I want to validate the data entered by the user and if it is wrong, want to give an error message in a popup. To do this,

1) where should I code the validation and the popup with the error message? Is WDDOBEFOREACTION the right event?

2) How can I stop, in case of error, the code of the event handler, ONACTIONGET_DATA to be executed, so that view2 is not displayed along with the popup? I have written the following code in WDDOBEFOREACTION

Select * from vbak into table i_vbak where vbeln in <LT_RANGE_TABLE>.

If sy-subrc NE 0.

l_api_main = wd_this->wd_get_api( ).

l_cmp_api = wd_comp_controller->wd_get_api( ).

  • get configuration context

l_node = wd_context->get_child_node( 'POPUP_DATA' ).

l_node_info = l_node->get_node_info( ).

l_attributes = l_node_info->get_attributes( ).

read table l_attributes assigning <attribute> with key name = `BUTTON_KIND`.

if sy-subrc = 0.

loop at <attribute>-value_set assigning <value_set>.

wa_value_set = <value_set>.

condense wa_value_set-key.

insert wa_value_set into table l_value_set.

endloop.

l_node_info->set_attribute_value_set( name = `BUTTON_KIND`

value_set = l_value_set ).

endif.

read table l_attributes assigning <attribute> with key name = `MESSAGE_TYPE`.

if sy-subrc = 0.

clear l_value_set.

loop at <attribute>-value_set assigning <value_set>.

wa_value_set = <value_set>.

condense wa_value_set-key.

insert wa_value_set into table l_value_set.

endloop.

l_node_info->set_attribute_value_set( name = `MESSAGE_TYPE`

value_set = l_value_set ).

endif.

l_node->get_static_attributes( importing static_attributes = l_conf_context ).

split l_conf_context-text at '#' into table l_text_table.

l_window_manager = l_cmp_api->get_window_manager( ).

wd_this->popup = l_window_manager->create_popup_to_confirm(

text = l_text_table

button_kind = l_conf_context-button_kind

message_type = l_conf_context-message_type

close_button = l_conf_context-close_button

window_title = l_conf_context-window_title

window_left_position = l_conf_context-window_left_position

window_top_position = l_conf_context-window_top_position

window_position = l_conf_context-window_position

window_width = l_conf_context-window_width

window_height = l_conf_context-window_height ).

wd_this->popup->set_remove_on_close( abap_true ).

wd_this->popup->open( ).

After the call to the popup->open( ) method, the code goes on to the event handler ONACTIONGET_DATA, executes the code there and dispalys the next view with the pop up.

Thanks,

Mick

Accepted Solutions (1)

Accepted Solutions (1)

arjun_thakur
Active Contributor
0 Kudos

Hi Mick,

Every time you click on submit buttom, WDDOBEFOREACTION method is called. So wriiting the validation code in this method will not be a problem. Or can can also write the validation code in the ONACTION method of the submit buttom.

To stop the execution in case of an error: You can use a globe flag variable. Assign it some value (say 0). In case of error, just change its value (to say 1).

Now in the ONACTIONSUBMIT method, before you call GET_DATA method, write this line:

Check lv_flag EQ '0'.

this code will stop the execution in the case of error.

I hope it helps

Regards

Arjun

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Mick,

If the submit button is the main view create a method check_input in that do the necessary validations.

refer to the standard webdynpro component:

package : SWDP_DEMO

--> DEMO_MESSAGES check this webdynpro component.

Regards,

Sravanthi

Former Member
0 Kudos

Hi,

You have to write your code for validation at method which calling under Button event.I mean to say when you click the button the Method which are going to trigger.

-Rick