cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Catch validation errors in ABAP

Former Member
0 Likes
2,751

Hi,

Description: When we enter data other then what is defined for a UI element, we get an error and are not allowed to proceed ahead till we correct it.

e.g. When we define a context attribute as type Date and suppose enter alphabets we get an error message u201CXYS is not a date format u201C.

In my requirement I have a time field. When time is less than 3 hours 30 mis I display a popup with input field. This popup window has OK and Cancel Button.

Now when I enter a wrong time format say 03:2:00 instead of 03:20:00 .Popup window comes and displays a error message time format invalid.

Problem: The problem is user is not allowed to go back to main screen because of error.

OK and cancel button are not working. I think the reason is these standard error messages had cancel navigation as TRUE.

This is the problem at all places when popup comes and user has enters a wrong data in the screen.

Please guide how to avoid same.

Regards,

Madhvika

Edited by: Madhvika Joshi on May 23, 2011 1:15 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hi Madhvika,

I am not sure if i got the requirement properly, however if you want to catch validation errors generated data type checks for example date and time.

if you can do that by using interface if_wd_validation, this interface has methods like set_attribute_valid which suppresses those messages and then you can raise your own messages!!

Former Member
0 Likes

I would like to mention again that problem is not only for time field but with all any fields. If data entered by user is not in correct format or not valid SAP validation error comes in my popup or any validation messages that I have done also comes in popup .Reason being my code to open a popup is written in wdbeforeaction method.

Here are the complete details with code

Front Screen:

There is a table with Flight details In that there are user can select business class, first class, economy class via a radio button option. There is a column where user enters total travel duration.

CODE:

In Wdbeforeaction this is the code for policy deviation check

Policy Deviation Check For Flight Travel Class, if total travel duration is less than 3:30 Hours and employee has selected Business class or first class a popup window should be displayed to capture the deviation reason 

        IF lwa_flight_info-cabin EQ 'B' OR  lwa_flight_info-cabin EQ 'F' .
          IF lwa_flight_info-yym_trav_time <= '033000'  .


              wd_this->open_popup( EXPORTING lv_type = 'F' ).

              EXIT.

          ENDIF
ENDIF.

In view this is the method for opening popup window.This is called from wdbeforeaction

Code for popup window

DATA lo_view_controller type ref to if_wd_view_controller.
DATA lo_window_manager TYPE REF TO if_wd_window_manager.
DATA lo_api_component  TYPE REF TO if_wd_component.
DATA lo_window         TYPE REF TO if_wd_window.

lo_api_component  = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
lo_window         = lo_window_manager->create_window(
                   window_name            = 'POPUP_WINDOW'
*                  title                  =
                   close_in_any_case      = abap_false
*                  message_display_mode   = if_wd_window=>CO_MSG_DISPLAY_MODE_ALL
                   close_button           = abap_false
                   button_kind            = if_wd_window=>co_buttons_okcancel
*                  message_type           = if_wd_window=>co_msg_type_warning
                   default_button         = if_wd_window=>co_button_ok
                   ).

  DATA lo_nd_popup TYPE REF TO if_wd_context_node.
  DATA lo_el_popup TYPE REF TO if_wd_context_element.
  DATA ls_popup TYPE wd_this->element_popup.
  DATA lv_popup_win LIKE ls_popup-popup_win.
* navigate from <CONTEXT> to <POPUP> via lead selection
  lo_nd_popup = wd_context->get_child_node( name = wd_this->wdctx_popup ).

* get element via lead selection
  lo_el_popup = lo_nd_popup->get_element(  ).

lv_popup_win = lo_window.

* get single attribute
  lo_el_popup->set_attribute(
    EXPORTING
      name =  `POPUP_WIN`
      value = lv_popup_win ).

lo_view_controller = wd_this->wd_get_api( ).


	lo_window->subscribe_to_button_event(
	button = if_wd_window=>co_button_ok
	button_text = 'OK'
	action_name = 'OK'
	action_view = lo_view_controller ).

      lo_window->subscribe_to_button_event(
	button = if_wd_window=>co_button_cancel
	button_text = 'Cancel'
	action_name = 'CANCEL'
	action_view = lo_view_controller ).





lo_window->open( ).

Former Member
0 Likes

Hi Joshi,

I think problem is because of code in wdbeforeaction. why don't write your code in on_select event of table or dropdown(if you are using ), i think you are selecting first or business class, so i am suggesting this. Try this it might helps you.

Cheers,

Kris.

Former Member
0 Likes

Hi Kris,

i think SAP validations are checked after wdbeforeaction so i am writting code in afteraction method . i think that should solve the problem.

Will update post once done .

Thanks again for all ur valuable time. Rewarding points for same

Regards,

Madhvika

vineetrrakesh
Explorer
0 Likes

Hi Madhvika

Sorry for holding you little longer on the issue but Just wanted to check whether are you going to change the standard code?

I would like to suggest you to do not change SAP standard code, You should write custom coding in any Enhancement Implementation, You can write Exit methods to hadle your issue.

That's why earlier I suggested you to write an Overwrite Exit of the same method where the po-up is thrown and you want to stop the Pop-up.

In case if any upgrade haapens and SAP gives you some code in AfterAction method your changes will be overwritten again.

The best way to get the changes done in SAP coding is from SAP only, and you should create a ticket to SAP so that they fix it. In that case they will take care of the fixes while providing higher versions.

Regards

Vineet

Former Member
0 Likes

Hi Madhvika,

SAP standard data type validations will be done well before 'wddobeforeaction' for that matter, they are checked before transporting the data to context which is first step in phase model so you don't even see values in context if it has got validation error, however having said that you can use if_wd_validation interface in wddobeforeaction to see what went wrong with validation errors and suppress it.

what i would think is if there is any validation errors donot open the pop up as it anyways going to displays those validation errors, as messages are always displayed in next view assembly.

Former Member
0 Likes

Hi All,

Thanks for your time and efforts.

Special thanks to Kranti Kumar. His solution solved my problem.

Here is the solution:

At the start of the wdbeforeaction I am checking if context is valid or not.

If itu2019s valid, code ahead is executed else exit the wdbeforeaction.

In this way when there is a validation error that sap performs, code below this check is not executed. Thus sap validations errors are not coming in popup.

Below is the code that I wrote at the start of wdbeforeaction

DATA lo_api_controller     TYPE REF TO if_wd_controller.
      DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
      DATA  lr_context TYPE REF TO if_wd_context.
      DATA lo_new  TYPE REF TO if_wd_validation .
      DATA lo_boolean TYPE boolean.

      lo_api_controller ?= wd_this->wd_get_api( ).

      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.


      lr_context = lo_api_controller->get_context( ).
      lo_new ?= lo_message_manager .
      
      lo_new->is_context_valid(
                        EXPORTING
                        context =  lr_context
                      RECEIVING
                        is_valid = lo_boolean ).

              IF lo_boolean = abap_false.
              exit.
              ENDIF.

Regards,

Answers (2)

Answers (2)

former_member199125
Active Contributor
0 Likes

hi madhavika,

In your example , if you set the date field as mandatory field( requried property ) then you cannot go back.

If you set the above parameter, then uncheck that parameter.

And let me know your scenario, so that we can approach in better way

Regards

Srinivas

Former Member
0 Likes

Hi Srinivas,

I am performing Validation like if total travel time is less than 3 hours 30 mins and user has selected business class, I have to display a popup with input field where user enters reason for deviation in policy. This popup has ok and cancel button. Ok button only works when user has entered reason. If user doesnu2019t want to enter reason he can click cancel.

Total travel time field is a time field with format HH:MM: SS. If user enter wrong format like 03:2:00 and then click on business class radio button, in wdbefore action method where I have written validation code is executed . As desired popup comes but with an error that time format is invalid.

And user is stuck to that window as OK and Cancel button are not working.

My question: How can I stop displaying the popup when user has entered invalid time?

Or to catch this validation which is performed by SAP internally.

Former Member
0 Likes

Hi Madhvika,

Popup view is Modal view, so without closing model veiw you can't access main veiw. I Think this is the problem.

Cheers,

Kris.

Former Member
0 Likes

Hi Kris ,

Thanks for your response.

Can youi please guide on solution .

Regards,

Former Member
0 Likes

Hi Madhvika,

As i am right, You are entering time in main view and displaying error message in popup window,

dont display in popup, display error message in main veiw if time goes wrong, if time is correct then only go to popup view.

Cheers,

Kris.

Former Member
0 Likes

Hi Kris,

the check for Time if its a valid format or not is performed by SAP . I have not written that code.

My problem wud be solved if i can catch this error before displaying the popup. Like if time entered in not valid then exit dont proceed with the next code to display popup .

Former Member
0 Likes

HI Madhvika,

You say in one of your posts that you perform the validation in WDDOBEFOREACTION action and raise the pop-up and now you want to skip that part?

Please let us know, what validation you are doing in WDDOBEFOREACTION action?

What validation are you trying to block?..

Thanks,

Aditya.

Former Member
0 Likes

Hi,

Use Message are in your veiw not popup, and check your date format and write your own code,

if condition not satisfy, display error message.

Cheers,

Kris.

Former Member
0 Likes

Hi Kris,

Sorry cudnt understand your message . Can you please help again .

Regards,

Madhvika

Former Member
0 Likes

Hi Aditya,

Popup comes when there is a validation failure that total time is less than 3 hours 30 mins and travel class selected as Business. On any first action code in wdbeforeaction is executed and popup is displayed.

Now problem is user has entered wrong time format and selected business class. Check for entered data if itu2019s valid or not is done by SAP.

Both action display of popup and sap check for invalid data happens at the same tine and thus error message is displayed on popup window.

So no navigation is possible with ok and cancel button that is the problem.

Hope itu2019s clear now

Regards,

Madhvika

Former Member
0 Likes

Hi Madvika,

I am saying that, create your own code to validate your dates, and in condition display your message.

If condition true then only display popup.

Cheers,

Kris.

Former Member
0 Likes

HI Madhvika,

Can you please post the validation code and pop-up raising code?

I tried to replicate a similar sceanrio and it works fine for me..

When the time is in wrong format, SAP error comes in the original view and on top of that pop-up comes,and 'OK' and 'Cancel'

seem to work fine...

Thanks,

Aditya.

gill367
Active Contributor
0 Likes

What kind of pop up you are showing.

wt kind of window is it .

is it a confirmation window or you have created a new window.

and how r you passing the error messg to pop up window.

i tried to generate the same kind of scenario ..

but for me it is not navigating to the pop up window

it is not going anywhere. because as per the webdynpro phase model .

validation of these standard types happens in the second step itself before any other thing.

so it is coming for me.

if you want to suppress that error of standard validation.

you dont want it to come. it can be achieved by making the action validation- independent.

in that case that error itself wont come.

in the action list just select that messg and make it validation independent.

thanks

sarbjeet singh

vineetrrakesh
Explorer
0 Likes

Hi Madhvika,

Your problem is that you can't change SAP code, right? Why don't you write an Overwrite Exit for the standard SAP Method . You can copy the complete code and of SAP and modify the check accordingly.

Regards

Vineet