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

Catch validation errors in ABAP

Former Member
0 Likes
2,760

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

View Entire Topic
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,