Skip to Content

Purpose:

Reporting attribute error messages or standard / T100 messages on OVS window.

Scenario:

I would like to explain the scenario of validating the fields on OVS window and reporting error messages as below

  • Report Standard / T100 Messages
    • Based on our requirement we can report standard / T100 messages by using method SET_MESSAGES of interface IF_WD_OVS
    • We can also report messages by using methods of interface IF_WD_MESSAGE_MANAGER
  • Report Attribute Error Message
    • Get the reference of context element of OVS component by using component usage context
    • Report the attribute error message by using method REPORT_ATTRIBUTE_ERROR_MESSAGE of interface IF_WD_MESSAGE_MANAGER

          Key logic: Getting the reference of context element of context node “INPUT” of component WDR_OVS

  1.         DATA lo_ovs             TYPE REF TO iwci_wdr_ovs. 
  2.         DATA lo_context         TYPE REF TO if_wd_context. 
  3.         DATA lo_context_node    TYPE REF TO if_wd_context_node. 
  4.         DATA lo_el              TYPE REF TO if_wd_context_element. 
  5.        ” get reference of ovs component usage 
  6.        lo_ovs = wd_this->wd_cpifc_test_ovs( ). 
  7.        ” get the context of ovs component 
  8.         lo_context = lo_ovs->wd_get_api( )->get_context( ). 
  9.        ” get input node reference 
  10.         lo_context_node = lo_context->root_node->get_child_node( ‘INPUT’). 
  11.        ” get reference to the context element by using lead index 
  12.         lo_el = lo_context_node->get_element( ).

Pre-requisite:

Basic knowledge of Webdynpro ABAP, OVS concept & OO ABAP


Step by step process:


Here, I am going to create a simple web dynpro application with input fields CARRID & CARRNAME and attaching OVS help on field CARRID.


Step 1:


Create a WDA component with a view as below

1.PNG

Step 2:


Create component usage of component WDR_OVS as below


/wp-content/uploads/2013/12/2_352512.png


Step 3:


Add the used controller of TEST_OVS in view V_MAIN as below


2_1.PNG

Step 4:


Create context node SCARR with attributes CARRID & CARRNAME. Attach the ovs component to attribute CARRID as below


3.PNG

Step 5:


Create input fields for context node SCARR  in view layout as below


4.PNG

Step 6:


Create an event handler method ON_OVS as below

5.PNG

Add the below code in ON_OVS event handler method


METHOD on_ovs .
TYPES:
    BEGIN OF lty_stru_input,
      carrid TYPE scarr-carrid,
    END OF lty_stru_input.
TYPES:
    BEGIN OF lty_stru_output,
      carrid TYPE scarr-carrid,
      carrname   TYPE scarr-carrname,
    END OF lty_stru_output.
DATA: ls_search_input  TYPE lty_stru_input,
        lt_select_list   TYPE STANDARD TABLE OF lty_stru_output,
        ls_text          TYPE wdr_name_value,
        lt_label_texts   TYPE wdr_name_value_list,
        lt_column_texts  TYPE wdr_name_value_list,
        lv_window_title  TYPE string,
        lv_table_header  TYPE string.
FIELD-SYMBOLS: <ls_query_params> TYPE lty_stru_input,
                 <ls_selection>    TYPE lty_stru_output.
CASE ovs_callback_object->phase_indicator.
   WHEN if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted
     ls_text-name = `CARRNAME`.  "must match a field name of search
      ls_text-value = `Airline Name`. "wd_assist->get_text( `001` ).
      INSERT ls_text INTO TABLE lt_label_texts.
      INSERT ls_text INTO TABLE lt_column_texts.
     ovs_callback_object->set_configuration(
                label_texts  = lt_label_texts
                column_texts = lt_column_texts
                window_title = lv_window_title
                table_header = lv_table_header ).
   WHEN if_wd_ovs=>co_phase_1.  "set search structure and defaults
     ovs_callback_object->context_element->get_static_attributes(
          IMPORTING static_attributes = ls_search_input ).
     "pass the values to the OVS component
      ovs_callback_object->set_input_structure(
          input = ls_search_input ).
    WHEN if_wd_ovs=>co_phase_2.
      IF ovs_callback_object->query_parameters IS NOT BOUND.
******** TODO exception handling
      ENDIF.
      ASSIGN ovs_callback_object->query_parameters->*
                              TO <ls_query_params>.
      IF NOT <ls_query_params> IS ASSIGNED.
******** TODO exception handling
      ENDIF.
     "==========================================
      " Report query parameter table
      "==========================================
      DATA ls_so_carrid TYPE selopt.
      DATA lt_so_carrid TYPE TABLE OF selopt.
     CLEAR ls_so_carrid.
      CLEAR lt_so_carrid.
   IF <ls_query_params>-carrid IS NOT INITIAL.
        ls_so_carrid-sign = 'I'.
        ls_so_carrid-option = 'EQ'.
        ls_so_carrid-low = <ls_query_params>-carrid.
        FIND '*' IN ls_so_carrid-low.
        IF sy-subrc IS INITIAL .
          ls_so_carrid-option = 'CP'.
        ENDIF.
        APPEND ls_so_carrid TO lt_so_carrid.
      ENDIF.
     "=================================================
      "Note: Do not query database directy inside view, instead
      " call a method/function module to get data
      " call business logic for a table of possible values
      "=================================================
      SELECT carrid
             carrname
        FROM scarr
        INTO TABLE lt_select_list
        WHERE carrid IN lt_so_carrid.
      IF lt_select_list[] IS INITIAL.
       "==========================================
        " Report attribute error message here
        "==========================================
        DATA lo_ovs             TYPE REF TO iwci_wdr_ovs.
        DATA lo_context         TYPE REF TO if_wd_context.
        DATA lo_context_node    TYPE REF TO if_wd_context_node.
        DATA lo_el              TYPE REF TO if_wd_context_element.
        DATA lo_ovs_listener    TYPE REF TO if_wdr_ovs_listener.
        DATA lo_message_manager TYPE REF TO if_wd_message_manager.
       " get reference of ovs component usage
        lo_ovs = wd_this->wd_cpifc_test_ovs( ).
       " get the context of ovs component
        lo_context = lo_ovs->wd_get_api( )->get_context( ).
       " get input node reference
        lo_context_node = lo_context->root_node->get_child_node( 'INPUT').
       " get reference to the context element by using lead index
        lo_el = lo_context_node->get_element( ).
       " get reference to message manager
        lo_message_manager = wd_this->wd_get_api( )->get_message_manager( ).
*         report message
        CALL METHOD lo_message_manager->report_attribute_error_message
          EXPORTING
            message_text   = 'Invalid entry - ( Attribute error message )'
            element        = lo_el
            attribute_name = 'CARRID'.  " Attribute Name
       "==========================================
        " Report standard error message here
        "==========================================
        DATA lt_messages TYPE if_wd_ovs=>ty_t_messages.
        DATA ls_messages LIKE LINE OF lt_messages.
       CLEAR ls_messages.
        CLEAR lt_messages.
       ls_messages-standard_message-text = 'Invalid entry ( Standard message )' .
        ls_messages-standard_message-type = if_wd_message_manager=>co_type_error.
        APPEND ls_messages TO lt_messages.
       ovs_callback_object->set_messages( messages = lt_messages ).
      ENDIF.
      ovs_callback_object->set_output_table( output = lt_select_list ).
   WHEN if_wd_ovs=>co_phase_3.
*   apply result
      IF ovs_callback_object->selection IS NOT BOUND.
******** TODO exception handling
      ENDIF.
      ASSIGN ovs_callback_object->selection->* TO <ls_selection>.
      IF <ls_selection> IS ASSIGNED.
        ovs_callback_object->context_element->set_static_attributes(
                               static_attributes = <ls_selection> ).
      ENDIF.
  ENDCASE.
ENDMETHOD.


Now, save and activate the WDA component.

Step 7:

Create a web dynpro application as below

6.PNG

Output: ( Initial OVS window )

O1.PNG

Output: ( Initial search result list )

o2.PNG

Output: ( Invalid entry in the field CARRID )

o3.PNG

Hope this document is helpful for those looking for validation on OVS input fields.

Comments / Suggestions are always welcome

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply