Tuesday, 11 February 2014

Working with LEAD selection Event in Web Dynpro Component

Scenario: This post is about creating two tables in a single view . One is header table and one is item table. The header table displays the sales order details and when the user selects any line in the header table the corresponding line items are displayed in the item table. The line selection in the header table uses lead selection event which triggers an action and the action handler method fills the item details in the item table.

Step1. Go to Transaction - SE80 and create a web dynpro component.


















Step2. Provide the description, window name and view name. At last click  on Continue button.




















Step3. Activate the component. Expand the view and double click on it from the left hand tree hierarchy.


















Step4. Go to the Context tab and right click on the context to create a node.

















Step5. Provide the details and click on the button to select some fields from the structure.




















Step6. Select some fields and click on Yes button.































Step7. Un check the initial lead selection.
























Step8. In the same view, again click on the context node & create a node.

















Step9. provide the details and click on the button to select some fields from the structure vbap.





























Step10. Select some fields and click on continue button.

































Step11. Two nodes are created .























Step12. Go to the Layout tab to design the view. Select the layout as matrix layout.

















Step13. right click on the ROOTUIELEMENTCONTAINER and  click  on Insert Element option.















Step14. Provide below details and continue.














Step15. Click on the data source button .



















Step16. Select the Node 'SALES_HDR' .





















Step17. Right click on the element TAB and select Create Binding.















Step18. Select Cell editor as Text View and select all fields as binding and click  on Continue button.
















Step19. Double click on the caption under the TAB and provide some text.




















Step20. The first table is created in the view and mapped to the context node SALES_HDR.
Lets create another table in the same way.













Step21. Provide the details and click  on OK button.


















Step22. Change the layout data to MatrixHeader data .


















Step23. Click on the Binding button.



















Step24. Select  the Node 'SALES_ITEM.





















Step25. right click and select the option Create Binding.
















Step26. Select Cell Editor as text View and bind all elements and at last click on continue button.














Step27. Double click on the caption and provide some meaning full text.



















Step28. The user would be selecting particular a line on the Header table. so that he can get the item details in the Item Table. So we need a action in the header table. Select the Element TAB and click on the Create button for the EVENT 'ONLEADSELECTION'.

















Step29. Provide the EVENT name and description and click on the continue button.
















Step30. The event is created for the header table.
















Step31. Go to the methods tab and double click on the WDDOINIT method which will fill the header table.
















Step32. Provide the below code and activate the same.


















Step33. Click on the EVENTS tab. We have created on event for the header table for the ONLEADSELECTION. The system automatically creates an event handler method for the same.














Step34. Now go to the methods tab and double click on the event handler method.













Step35. Provide the below code in the event handler method.




















** this action handle method triggered when the user selects any row of the header table.
** here the primary focus is to read the particular line of the header table that user selects and
** then based on that reading the data from VBAP table and filling the internal table and binding
** view context node SALES_ITEM.
  DATA : lo_hdr_node TYPE REF TO if_wd_context_node,
         lo_hdr_elem  TYPE REF TO if_wd_context_element,
         lo_item_node TYPE REF TO if_wd_context_node,
         ls_vbak TYPE  wd_this->element_sales_hdr,
         lt_vbap TYPE  wd_this->elements_sales_item.
** READ THE HEADER NODE REFERENCE
  CALL METHOD wd_context->get_child_node
    EXPORTING
      name       = 'SALES_HDR'    " Name of Lower-Level Node
    RECEIVING
      child_node = lo_hdr_node.   " Lower-Level Node

** GET THE REFERENCE OF TEH SELECTED ROW
  CALL METHOD lo_hdr_node->get_lead_selection
    RECEIVING
      element = lo_hdr_elem.

** READ THE CONTENT OF THE SELECTED ROW AND STORE IT IN WORK AREA
  CALL METHOD lo_hdr_elem->get_static_attributes
    IMPORTING
      static_attributes = ls_vbak.

  IF ls_vbak IS NOT INITIAL.
    SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE  lt_vbap WHERE vbeln = ls_vbak-vbeln.
    CLEAR ls_vbak.
    CALL METHOD wd_context->get_child_node
      EXPORTING
        name       = 'SALES_ITEM'   " Name of Lower-Level Node
      RECEIVING
        child_node = lo_item_node.   " Lower-Level Node

    CALL METHOD lo_item_node->bind_table
      EXPORTING
        new_items = lt_vbap.  " List of Elements or Model Data
  ENDIF.

_____________________________________________________________

Step36. Activate the web dynpro component. Create an application.















Step37. Provide application name.









Step38. Save it and click on the TEST button.

















Step39. The details appears below. Select any line in the header table and the details are populated in the ITEMS table.















Step40.














___________________________________________________________________

1 comment:

Prashanth said...

One the Best self learning Site for Webdynapro.
In Step 32: Screen shot is not visible. Image has jumbled. can you please post the proper one.
Thanks,
Prashanth

Comments system

Disqus Shortname