Wednesday, March 21, 2012
Steps to achieve the functionality:
We use event ON_OVS of Component WDR_SELECT_OPTIONS.
  • Create Web Dynpro Component with View and Window(Automatically View is embedded into Window) and Save it as local object. 
  • Define Component Use SELECT_OPT for the Used component WDR_SELECT_OPTIONS under Used Components tab of Web Dynpro Component.
  • Go to View OVS_SEARCH_V->Properties tab->Define or Include Used Controllers/ Components of Select Options.
  •  Go to view  OVS_SEARCH_V  ->Context tab->Create node TAB_P0002 with cardinality 0..n and attributes inside.
  • Go to view  OVS_SEARCH_V ->Layout tab->Create ViewContainerUIElement to hold Select-Option field.
    • Create ViewContainerUIElement to hold Select-Option field.
 
    • Create button->Create OnAction event to get the values entered in Select-Option field and Display related records in the table.
 
    • Create Table UI element->Bind the Context node  TAB_P0002 with table UI element.
  • Go to view  OVS_SEARCH_V ->Methods tab->Write the following code in WDDOINIT hook method.
    • Instantiate Used Component  WDR_SELECT_OPTIONS.
    • Instantiate Used Component Controller IWCI_WDR_SELECT_OPTIONS and and Call method INIT_SELECTION_SCREEN.
    • Create Range Table using IF_WD_SELECT_OPTIONS->CREATE_RANGE_TABLE.
    • Add Selection field by passing Range table and Field to IF_WD_SELECT_OPTIONS-> ADD_SELECTION_FIELD .
    • code
    • METHOD wddoinit .
        "Instantiate Used Component
        DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
        lo_cmp_usage =   wd_this->wd_cpuse_select_opt( ).
        IF lo_cmp_usage->has_active_component( ) IS INITIAL.
          lo_cmp_usage->create_component( ).
        ENDIF.
       "Instantiate Used Controller and Call Init_selection_screen method.
        DATA lo_interfacecontroller TYPE REF TO iwci_wdr_select_options .
        lo_interfacecontroller =   wd_this->wd_cpifc_select_opt( ).
        DATA lv_r_helper_class TYPE REF TO if_wd_select_options.
      lv_r_helper_class = lo_interfacecontroller->init_selection_screen( ).
        "Create Range table
        DATA:rt_table TYPE REF TO  data.
        CALL METHOD lv_r_helper_class->create_range_table
          EXPORTING
            i_typename     = 'PERSNO'
          RECEIVING
            rt_range_table = rt_table.
        "Disable CANCEL, CHECK, RESET and COPY buttons
        CALL METHOD lv_r_helper_class->set_global_options
          EXPORTING
            i_display_btn_cancel  = abap_false
            i_display_btn_check   = abap_false
            i_display_btn_reset   = abap_false
            i_display_btn_execute = abap_false.
        "Add range field to Selection screen
        CALL METHOD lv_r_helper_class->add_selection_field
          EXPORTING
            i_id              = 'PERSNO'
            it_result         = rt_table
            i_value_help_type = if_wd_value_help_handler=>co_prefix_ovs.
      
      ENDMETHOD.
      
  • Go to view  OVS_SEARCH_V ->Methods tab->Write the below code for ONACTIONSEARCH_EMP event handler method for button. 
    • code
    • METHOD onactionsearch_emp .
        "Instantiate Used Component
        DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
        lo_cmp_usage =   wd_this->wd_cpuse_select_opt( ).
        IF lo_cmp_usage->has_active_component( ) IS INITIAL.
          lo_cmp_usage->create_component( ).
        ENDIF.
        "Instantiate Used Controller and Call Init_selection_screen method.
        DATA lo_interfacecontroller TYPE REF TO iwci_wdr_select_options .
        lo_interfacecontroller =   wd_this->wd_cpifc_select_opt( ).
        DATA lv_r_helper_class TYPE REF TO if_wd_select_options.
      lv_r_helper_class = lo_interfacecontroller->init_selection_screen( ).
        "Read Select option
        DATA:rt_table TYPE REF TO data.
        CALL METHOD lv_r_helper_class->get_range_table_of_sel_field
          EXPORTING
            i_id           = 'PERSNO'
          RECEIVING
            rt_range_table = rt_table.
        "Populate EMP_ADD table
        DATA lo_nd_tab_p0002 TYPE REF TO if_wd_context_node.
        DATA lt_tab_p0002 TYPE wd_this->elements_tab_p0002.
        FIELD-SYMBOLS: TYPE table.
      
        ASSIGN rt_table->* TO <emp>.
        SELECT *
          FROM pa0002
          INTO TABLE lt_tab_p0002
          WHERE pernr IN <emp>.
        "navigate from <context> to <tab_p0002> via lead selection
        lo_nd_tab_p0002 = wd_context->get_child_node( name = wd_this->wdctx_tab_p0002 ).
        lo_nd_tab_p0002->bind_table( new_items = lt_tab_p0002 set_initial_elements = abap_true ).
      
      ENDMETHOD.
      
      
  • Go to view  OVS_SEARCH_V ->Methods tab-> Create one Event Handler method OVS_ON_SO ->Select the event ON_OVS of component WDR_SELECT_OPTIONS using F4 help for Event field.
  • Double click on OVS_ON_SO method->Write the below code. 
  • METHOD ovs_on_so .
      TYPES:
            BEGIN OF ty_p0002,
              pernr TYPE pa0002-pernr,
              endda TYPE pa0002-endda,
              begda TYPE pa0002-begda,
              nachn TYPE pa0002-nachn,
              vorna TYPE pa0002-vorna,
              titel TYPE pa0002-titel,
            END OF ty_p0002.
      DATA:
            ls_p0002 TYPE ty_p0002,
            lt_p0002 TYPE STANDARD TABLE OF ty_p0002.
    
      FIELD-SYMBOLS:
            <lt_ovs_result>     LIKE lt_p0002,
            <p0002>             LIKE LINE OF <lt_ovs_result>,
            <lt_sel_opt_result> TYPE STANDARD TABLE.
    
      CASE i_ovs_data-m_ovs_callback_object->phase_indicator.
          "Set Configuration
        WHEN if_wd_ovs=>co_phase_0.
          "Preassign Entry Values
        WHEN if_wd_ovs=>co_phase_1.
          "Fill Value List
        WHEN if_wd_ovs=>co_phase_2.
          SELECT pernr
                 nachn
                 vorna
            FROM pa0002
            INTO CORRESPONDING FIELDS OF TABLE lt_p0002
            UP TO 200 ROWS.
          i_ovs_data-m_ovs_callback_object->set_output_table( output = lt_p0002 ).
          "Value Return
        WHEN if_wd_ovs=>co_phase_3.
          ASSIGN i_ovs_data-m_ovs_callback_object->selection->* TO <p0002>.
          ASSIGN i_ovs_data-mt_selected_values->* TO <lt_sel_opt_result>.
          INSERT <p0002>-pernr INTO TABLE <lt_sel_opt_result>.
        WHEN OTHERS.
      ENDCASE.
    ENDMETHOD.
    
    
  • Go to Window OVS_SEARCH_W->Open view  OVS_SEARCH_V ->Right click on VCE ViewContainerUIElement->Embed view WND_SELECTION_SCREEN of WDR_SELECT_OPTIONS component.
  • Activate Web Dynpro component.
  • Create Web Dynpro Application and Save it as local object. 

1 comment:

  1. OVS Help is very simple explained in the below article

    http://theabap.blogspot.in/2012/02/ovs-search-help-in-web-dynpro.html

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.