Sunday, March 18, 2012
Steps to create 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 SELOPT_V->Properties tab->Define or Include Used Controllers/ Components of Select Options.
  •  Go to view SELOPT_V->Context tab->Create node EMP_ADR with cardinality 0..n and attributes inside. 
  • Go to view SELOPT_V->Layout tab
    • 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 EMP_ADR with table UI element.
  • Go to view SELOPT_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 .
        1. code
        2. 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     = 'PERNR_D'
              RECEIVING
                rt_range_table = rt_table.
          
            "Add range field to Selection screen
            CALL METHOD lv_r_helper_class->add_selection_field
              EXPORTING
                i_id                   = 'PERNR_D'
                it_result              = rt_table
                i_value_help_structure = 'PA0003'.
          
          ENDMETHOD.
          
        3. Go to view SELOPT_V->Write the below code for ONACTIONGET_ADDRESS_DET event handler method for button. 
        4. METHOD onactionget_address_det .
            "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           = 'PERNR_D'
              RECEIVING
                rt_range_table = rt_table.
            "Populate EMP_ADD table
            DATA lo_nd_emp_adr TYPE REF TO if_wd_context_node.
            DATA lt_emp_adr    TYPE wd_this->elements_emp_adr.
          
            FIELD-SYMBOLS  TYPE table.
            ASSIGN rt_table->* to <emp>.
          
            select *
              FROM pa0006
              into CORRESPONDING FIELDS OF TABLE lt_emp_adr
            WHERE pernr in <emp>.
           "Navigate from <context> to <emp_adr> via lead selection
            lo_nd_emp_adr = wd_context->get_child_node( name = wd_this->wdctx_emp_adr ).
            lo_nd_emp_adr->bind_table( new_items = lt_emp_adr set_initial_elements = abap_true ).
          
          ENDMETHOD.
          
          
          
        • Go to Window SELOPT_W->Open view SELOPT_V->Right click on VCE_SELECT_OPTIONS 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. 
        • Run Web Dynpro Application.
        Disable CANCEL, CHECK, RESET and COPY buttons
        • Call SET_GLOBAL_OPTIONS of Interface IF_WD_SELECT_OPTIONS. 
        •   "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.
          
          
          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     = 'PERNR_D'
              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                   = 'PERNR_D'
                it_result              = rt_table
                i_value_help_structure = 'PA0003'.
          
          ENDMETHOD.
          
        • Output 

        1 comment:

        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.