Implementing value help Web Dynpro using component WDR_OVS

Before I start with example I should mention that you can find SAP standard demo in your SAP system DEMO_VALUE_HELP and WDR_TEST_OVS.

If standard search help does not fulfil your business requirement in web dynpro then you can implement OVS value help. OVS linked value help puts you in control of selection fields that search help will display, selection logic, and columns displayed in result and how to use value returned by user selection.

OVS value help is implemented using component WDR_OVS. The OVS value help is linked to the context attribute. Therefore, the value help is automatically available for each input field that is bound to this context attribute. WDR_OVS raises event OVS, this is where you will need to put all your coding. This event is triggered at four different times also known as phase, essentially when component expects data from used component or when selected data is available to consume. Instance attribute OVS_CALLBACK_OBJECT->PHASE_INDICATOR contains value for phase.

I will very briefly explain about what code should be included in each phase, more details about each phase is explained at link OVS Value Help .

IF_WD_OVS=>CO_PHASE_0

Here you set configuration. Window title, Group header, table header, labels if they are different from data element labels.

IF_WD_OVS=>CO_PHASE_1

Here you can specify any selection screen you want to issue before you display any result. Make sense if your result set is large as this will help user to narrow down selection. This is however optional, if you ignore this phase, PHASE_3 will be invoked. From user point of view they will get list when they take value help.

IF_WD_OVS=>CO_PHASE_2

In this phase we write logic to create list. This can be a complex logic to a normal select. In case you have implemented phase 1 you will also get selection values entered by user which you can include in you logic.

IF_WD_OVS=>CO_PHASE_3

This triggers when user has made selection from list. Typically used to fill returned value in input where user took value help.

OVS Phase model webdynpro ovs

I am going to create a simple Web Dynpro with input based on field SCARR-CARRID. Automatic search help on this field is based on search help S_CARRIER_ID

webdynpro ovs

Using WDR_OVS component I will implement search to display values based on plane type. I will do this in steps to explain one thing at a time

Let gets started.

Create Web Dynpro ZPW_OVSDEMO1 with Window ZPW_DEMOOVS1 and view MAIN.

Web Dynpro OVS webdynpro ovs

Now go to view context and create Node based on dictionary structure SCARR and ‘Add Attribute from Structure’ CARRID to screen.

Web Dynpro OVS Context Mapping webdynpro ovs

We have context attribute, let add this to screen as input. Go to layout tab and right click on ROOTUIELEMENTCONTAINER and choose ‘Create Container Form’ option. On next screen press ‘Context’ button and choose node FLIGHT and press OK.

Web Dynpro OVS ViewUI webdynpro ovs

You should now have Airline input on screen. At this point create web dynro application and activate all objects. If you test web Dynpro and take value help on input Airline you will get SAP standard value help based on search help S_CARRIER_ID .

To implement OVS search help first step is to add component WDR_OVS to web Dynpro.

OVS Web Dynpro webdynpro ovs

Navigate to view MAIN and define component usage for WDR_OVS using new button.

OVS Web Dynpro webdynpro ovs

Next go to context of view and navigate to attribute CARRID. In property tab change ‘Input Help Mode’ to ‘Object Value Selector’ and in input ‘OVS Component Usage’ enter name of WDR_OVS component which is OVS in this case.

OVS Web Dynpro webdynpro ovs

Finally go to methods tab and defined event handler method for event OVS of component used.

OVS Web Dynpro webdynpro ovs

If you double click on method ON_OVS to open it code you will see system automatically put most of the code there including a CASE statement on OVS_CALLBACK_OBJECT->PHASE_INDICATOR. We just need to put code under right WHEN block. However I am going to delete this code and put just what I need to implement a simple value help without any selection screen. Little steps at a time.

In this simplest example I have defined structure lty_stru_list which is like report structure. An internal table lt_select_list of line type lty_stru_list will hold data that will be displayed to user. In phase 2 we have code which selects data from table sflight. Note that I have defined range type for planetype which I am using in select statement. In this case it blank but in coming example I will create selection screen and fill this range with what user has entered. In phase 3 based we assigned selected CARRID value to context element.

METHOD on_ovs .

  TYPES: BEGIN OF lty_stru_list,
          carrid    TYPE sflight-carrid ,
          planetype TYPE sflight-planetype ,
         END OF lty_stru_list.


  DATA: lt_select_list   TYPE STANDARD TABLE OF lty_stru_list.

  FIELD-SYMBOLS: <ls_selection>    TYPE lty_stru_list .

  CASE ovs_callback_object->phase_indicator.

    WHEN if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted


    WHEN if_wd_ovs=>co_phase_1.  "set search structure and defaults


    WHEN if_wd_ovs=>co_phase_2.

      TYPES : tr_planetype TYPE RANGE OF sflight-planetype .
      DATA : lt_planetype TYPE tr_planetype .

      SELECT carrid
             planetype
        INTO TABLE lt_select_list
        FROM sflight
       WHERE planetype IN lt_planetype .

      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  = 'CARRID'
                               value = <ls_selection>-carrid ).

      ENDIF.
  ENDCASE.
ENDMETHOD.

Hope this piece of code is clear to you. At this point you can activate the web dynpro and test it. What we demonstrated here is you have total control over column and rows.

Lets build on this and introduce selection screen to before displaying values. To display select screen first thing we need is a structure definition for fields being displayed as part of selection screen. We have defined type lty_stru_input and structure ls_search_input of this type. In plase 1 we will pass ls_search_input to ovs which will automatically build selection screen. In phase 2 we will extract value entered by user in selection screen and fill that in range. With these extra logic code look like this.

METHOD on_ovs .

  TYPES: BEGIN OF lty_stru_list,
          carrid    TYPE sflight-carrid ,
          planetype TYPE sflight-planetype ,
         END OF lty_stru_list.

  TYPES: BEGIN OF lty_stru_input,
            planetype TYPE sflight-planetype ,
         END OF lty_stru_input.

  DATA: lt_select_list   TYPE STANDARD TABLE OF lty_stru_list,
        ls_search_input  TYPE lty_stru_input .

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

  CASE ovs_callback_object->phase_indicator.

    WHEN if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted

    WHEN if_wd_ovs=>co_phase_1.  "set search structure and defaults

      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
      ELSE.

        TYPES : tr_planetype TYPE RANGE OF sflight-planetype ,
                ty_planetype TYPE LINE  OF tr_planetype      .

        DATA : lt_planetype TYPE tr_planetype ,
               ls_planetype TYPE ty_planetype .

        IF <ls_query_params>-planetype IS NOT INITIAL .
          ls_planetype-sign = 'I' .
          ls_planetype-option = 'EQ' .
          ls_planetype-low = <ls_query_params>-planetype .
          APPEND ls_planetype TO lt_planetype .
        ENDIF.

      ENDIF.

      SELECT carrid
             planetype
        INTO TABLE lt_select_list
        FROM sflight
       WHERE planetype IN lt_planetype .

      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  = 'CARRID'
                               value = <ls_selection>-carrid ).

      ENDIF.
  ENDCASE.

ENDMETHOD.

This is screen shot of value help with selection screen.

OVS with selection screen

Finally, I am going to add code under phase 0 to set various text.

    WHEN if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted

      DATA :  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.


      ls_text-name = 'PLANETYPE'.
      ls_text-value = 'Enter plane type'.
      INSERT ls_text INTO TABLE lt_label_texts.

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

      lv_window_title = 'Window title' .
      lv_group_header = 'Group Header' .
      lv_table_header = 'Table Header' .

      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 ).

WEBDYN2

Leave a Reply