Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
amy_king
Active Contributor

Overview

Object Value Selector (OVS) can be a useful tool for building a custom pick list or an ad-hoc search help for an input field when a dictionary search help is not available.

Scenario

You need to build an OVS for a Unit of Measurement field which presents a custom pick list of UoM values based on a user-specified dimension, e.g., volume, mass, temperature or time.

Procedure

1.0 Create a Web Dynpro Component

Create a web dynpro component, ZDEMO_OVS with a view, VIEW and window, WINDOW.

2.0 Create the Component Usage

On the Used Components tab of component ZDEMO_OVS, create a component usage for WDR_OVS.

Create the same component usage on view VIEW for both the WDR_OVS component and its interface controller.

3.0 Set Input Help Mode for Context Attribute UOM

Create a 1..1 context node named DATA and add to it the attribute, UOM of type MSEHI, for Unit of Measurement. For Input Help Mode, select Object Value Selector and use the search help on the OVS Component Usage field to select the UOM_OVS component usage created in Step 2.0.

4.0 Create the OVS Event Handler Method

Navigate to the Methods tab of view VIEW, and create a new method named ON_OVS. Select Method Type Event Handler and use the search help on the Event field to select event OVS from component usage UOM_OVS.

Navigate to the implementation of method ON_OVS. When the system generates method ON_OVS, it includes built-in skeleton code illustrating how the OVS event phase indicator should be handled. If you are familiar with writing search help exits, the OVS event phase indicator is similar in concept to the callcontrol-step in a search help exit. The four phases of the OVS event are:

  • Phase 0: The OVS dialog box is configured, e.g., with a title and the number of allowed return records.
  • Phase 1: If the OVS includes a selection-screen for restricting the search, it is defined here.
  • Phase 2: The search is executed and its results bound to the OVS output table.
  • Phase 3: Records selected by the user from the output table are set in the context for further processing.

The built-in skeleton code of the OVS event handler method is shown below.

METHOD on_ovs.
* declare data structures for the fields to be displayed and
* for the table columns of the selection list, if necessary
   TYPES: BEGIN OF lty_stru_input,
*          add fields for the display of your search input here
            field1 TYPE string,
          END OF lty_stru_input.

   TYPES: BEGIN OF lty_stru_list,
*          add fields for the selection list here
            column1 TYPE string,
          END OF lty_stru_list.

   DATA: ls_search_input  TYPE lty_stru_input,
         lt_select_list   TYPE STANDARD TABLE OF lty_stru_list,
         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_group_header  TYPE string,
         lv_table_header  TYPE string.

   FIELD-SYMBOLS: <ls_query_params> TYPE lty_stru_input,
                  <ls_selection>    TYPE lty_stru_list.

   CASE ovs_callback_object->phase_indicator.

     WHEN if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted
*   in this phase you have the possibility to define the texts,
*   if you do not want to use the defaults (DDIC-texts)

       ls_text-name = `FIELD1`.  "must match a field name of search
       ls_text-value = `MYTEXT`. "wd_assist->get_text( `001` ).
       INSERT ls_text INTO TABLE lt_label_texts.

       ls_text-name = `COLUMN1`.  "must match a field in list structure
       ls_text-value = `MYTEXT2`. "wd_assist->get_text( `002` ).
       INSERT ls_text INTO TABLE lt_column_texts.

*      lv_window_title = wd_assist->get_text( `003` ).
*      lv_group_header = wd_assist->get_text( `004` ).
*      lv_table_header = wd_assist->get_text( `005` ).

       ovs_callback_object->set_configuration(
                 label_texts  = lt_label_texts
                 column_texts = lt_column_texts
                 group_header = lv_group_header
                 window_title = lv_window_title
                 table_header = lv_table_header
                 col_count    = 2
                 row_count    = 20 ).

     WHEN if_wd_ovs=>co_phase_1.  "set search structure and defaults
*   In this phase you can set the structure and default values
*   of the search structure. If this phase is omitted, the search
*   fields will not be displayed, but the selection table is
*   displayed directly.
*   Read values of the original context (not necessary, but you
*   may set these as the defaults). A reference to the context
*   element is available in the callback object.

       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 phase 1 is implemented, use the field input for the
*   selection of the table.
*   If phase 1 is omitted, use values from your own context.

       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.

*     call business logic for a table of possible values
*     lt_select_list = ???

       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_attribute(
*                               name  = `COLUMN1`
*                               value = <ls_selection>-column1 ).
*      or
*        ovs_callback_object->context_element->set_static_attributes(
*                               static_attributes = <ls_selection> ).

       ENDIF.
   ENDCASE.

ENDMETHOD.

Modify method ON_OVS as follows for the Unit of Measurement search by dimension.

METHOD on_ovs.

* Search restriction fields
   TYPES: BEGIN OF lty_stru_input,
            dimid TYPE t006-dimid, " Dimension key
          END OF lty_stru_input.

* Hit list output columns
   TYPES: BEGIN OF lty_stru_list,
            msehi TYPE msehi, " UoM key
            msehl TYPE msehl, " UoM text
            txdim TYPE txdim, " Dimension text
          END OF lty_stru_list.

   DATA: ls_search_input  TYPE lty_stru_input,
         lt_select_list   TYPE STANDARD TABLE OF lty_stru_list,
         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_group_header  TYPE string,
         lv_table_header  TYPE string.

   FIELD-SYMBOLS: <ls_query_params> TYPE lty_stru_input,
                  <ls_selection>    TYPE lty_stru_list.

   CASE ovs_callback_object->phase_indicator.

     WHEN if_wd_ovs=>co_phase_0. " Set configuration options

*     Customize search restriction field labels
       ls_text-name  = 'DIMID'.  " Dimension key
       ls_text-value = 'Dimension'.
       INSERT ls_text INTO TABLE lt_label_texts.

*     Customize hit list output column labels
       ls_text-name  = 'MSEHI'.  " UoM key
       ls_text-value = 'UoM'.
       INSERT ls_text INTO TABLE lt_column_texts.
       ls_text-name  = 'MSEHL'.  " UoM text
       ls_text-value = 'Unit of Measurement'.
       INSERT ls_text INTO TABLE lt_column_texts.
       ls_text-name  = 'TXDIM'.  " Dimension text
       ls_text-value = 'Dimension'.
       INSERT ls_text INTO TABLE lt_column_texts.

*     Customize window title
       lv_window_title = 'Unit of Measurement'.

       ovs_callback_object->set_configuration(
                 label_texts  = lt_label_texts
                 column_texts = lt_column_texts
                 window_title = lv_window_title ).

     WHEN if_wd_ovs=>co_phase_1. " Set search restriction input structure

*     Pass the search restriction structure to OVS
       ovs_callback_object->context_element->get_static_attributes(
           IMPORTING static_attributes = ls_search_input ).

       ovs_callback_object->set_input_structure(
           input = ls_search_input ).

     WHEN if_wd_ovs=>co_phase_2. " Set hit list output table

*     Populate the hit list and pass it to OVS
       ASSIGN ovs_callback_object->query_parameters->*
                               TO <ls_query_params>.

       SELECT t006~msehi  " UoM key
              t006a~msehl " UoM text
              t006t~txdim " Dimension text
              FROM t006
              JOIN t006a ON t006a~msehi = t006~msehi
              JOIN t006t ON t006t~dimid = t006~dimid
              INTO TABLE lt_select_list
              WHERE t006t~dimid = <ls_query_params>-dimid
              AND   t006a~spras = sy-langu
              AND   t006t~spras = sy-langu.

       ovs_callback_object->set_output_table( output = lt_select_list ).

     WHEN if_wd_ovs=>co_phase_3. " Set user selection in the context

*     Apply result of user selection back to the context
       ASSIGN ovs_callback_object->selection->* TO <ls_selection>.

       IF <ls_selection> IS ASSIGNED.
         ovs_callback_object->context_element->set_attribute(
                                name  = 'UOM'
                                value = <ls_selection>-msehi ).
       ENDIF.
   ENDCASE.

ENDMETHOD.

5.0 Build the View's User Interface

Navigate to the Context tab of view VIEW, and map component controller node DATA to the view's context by drag-and-drop from the component controller context to the view context.

Next, navigate to the Layout tab of view VIEW, and use the Form Wizard to create an InputField UI element bound to context attribute DATA.UOM.

Result

Save, activate and run the web dynpro application. The Unit of Measurement field offers input help in the form of an OVS. After entering the desired dimension by which to restrict the search, the OVS presents a hit list of matching units of measurement. The user may make a selection to populate the view's Unit of Measurement field.

Labels in this area