Tuesday, April 10, 2012

 

Program steps

  • Create Web Dynpro Component with Window and View(Automatically View is embedded into Window). 
  • Go to Component Controller COMPONENTCONTROLLER.
    • Context tab->Create COUNTRY node with cardinality 0..n  and attributes(refer to T005T structure).
    • Methods tab->Write the code in WDDOINIT to populate data to show countries as list. 
    • WDDOINIT code
    • METHOD wddoinit .
        wd_this->get_listbox_data(  ).
      ENDMETHOD.
      
    • GET_LISTBOX_DATA code
    • METHOD get_listbox_data .
        DATA lo_nd_country TYPE REF TO if_wd_context_node.
      
        DATA lt_country TYPE wd_this->elements_country.
      
      * navigate from <CONTEXT> to <COUNTRY> via lead selection
        lo_nd_country = wd_context->get_child_node( name = wd_this->wdctx_country ).
        SELECT land1 landx
          FROM t005t
          INTO CORRESPONDING FIELDS OF TABLE lt_country
          WHERE spras = sy-langu.
        lo_nd_country->bind_table( new_items = lt_country set_initial_elements = abap_true ).
      ENDMETHOD.
    • GET_SELECTED_RECS code
    • METHOD get_selected_recs .
      *   "Get selected Elements
        DATA lo_nd_country TYPE REF TO if_wd_context_node.
        DATA lt_country TYPE wd_this->elements_country.
        data: ls_country TYPE wd_this->element_country.
        data: lt_ctry    TYPE wd_this->elements_country.
        DATA lt_elements TYPE wdr_context_element_set.
        DATA ls_elements TYPE REF TO if_wd_context_element.
        "Navigate from <CONTEXT> to <COUNTRY> via lead selection
        lo_nd_country = wd_context->get_child_node( name = wd_this->wdctx_country ).
        lt_elements = lo_nd_country->get_selected_elements(  ).
        LOOP AT lt_elements INTO ls_elements.
         ls_elements->get_static_attributes( IMPORTING static_attributes = ls_country ).
          APPEND ls_country TO lt_ctry.
        ENDLOOP.
       "Display selected Elements
          DATA lo_nd_dsp_coutries TYPE REF TO if_wd_context_node.
          DATA lt_dsp_coutries TYPE wd_this->elements_dsp_coutries.
      
      *   navigate from <CONTEXT> to <DSP_COUTRIES> via lead selection
          lo_nd_dsp_coutries = wd_context->get_child_node( name = wd_this->wdctx_dsp_coutries ).
          LOOP AT lt_ctry INTO ls_country.
           SELECT *
             FROM t005t
            APPENDING CORRESPONDING FIELDS OF TABLE lt_dsp_coutries
             WHERE spras = sy-langu
               AND land1 = ls_country-land1.
          ENDLOOP.
          lo_nd_dsp_coutries->bind_table( new_items = lt_dsp_coutries set_initial_elements = abap_true ).
      
      ENDMETHOD.
      
  • Go to View ITEMLISTBOX_V
    • Context tab->Map context of Component controller to context of view. 
    • Layout tab->define UI elements 1). ItemListBox 2). Button and OnAction event 3). Table as shown below. 
    • Methods tab->call GET_SELECTED_RECS method from ONACTIONDISPLAY_SELECTED event handler method.
    • METHOD onactiondisplay_selected .
        DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
        lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
      
        lo_componentcontroller->get_selected_recs(  ).
      
      ENDMETHOD.
      
  • Activate Web dynpro component 
  • Create Web Dynpro application and Save it as local object 
  • Run application. 

0 comments:

Post a 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.