Skip to Content
avatar image
Former Member

How to copy data from one node to another or fromone table to another table

Hi,

I have a two tables.I am populating data in first table and on the click of first table ,selected row data should be copied to the second table.

How do i achieve this requirement and what should be the cardinality of the second table

Thanks

Bala Duvvuri

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Nov 19, 2008 at 08:53 AM

    Hello Bala,

    I have 2 table UI elements. The user makes use of SELECTION to select desired row(s) & then presses on a "Copy" button in the tables toolbar. This would then copy the selected row(s) to the 2nd table ui element. Below is the coding for the same:

    METHOD onactioncopy_selected_rows .
      DATA:  wd_node TYPE REF TO if_wd_context_node,
             ls_node1 TYPE ig_componentcontroller=>element_node1,
             lt_node1 TYPE ig_componentcontroller=>elements_node1,
             lt_node2 TYPE ig_componentcontroller=>elements_node2,
             wa_temp  TYPE REF TO if_wd_context_element,
             lt_temp  TYPE wdr_context_element_set.
    
    
      wd_node = wd_context->get_child_node( name = 'NODE1' ).
    
      CALL METHOD wd_node->get_selected_elements
        RECEIVING
          set = lt_temp.
    
      wd_node = wd_context->get_child_node( name = 'NODE2' ).
    
      LOOP AT lt_temp INTO wa_temp.
        CALL METHOD wa_temp->get_static_attributes
          IMPORTING
            static_attributes = ls_node1.
        APPEND ls_node1 TO lt_node1.
        CLEAR ls_node1.
      ENDLOOP.
    
      wd_node->bind_table( new_items = lt_node1 ).
    ENDMETHOD.

    NODE1:

    Cardinality : 0..n

    Selection : 0..n

    Dictionary Structure: VBAK

    Initialization Lead Selection is unchecked

    NODE2:

    Cardinality : 0..n

    Selection : 0..n

    Dictionary Structure: VBAK

    Initialization Lead Selection is checked

    Hope that this helps.

    Regards,

    Uday

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 19, 2008 at 06:39 AM

    Hi,

    For this u have to fetch the selected row.

    For fetching the selected row go to the events of first table and select "OnLeadselect".

    Create a new method for this.

    Now in this method read the value of the selected row with method get_static_attributes.

    with this u will have the selected row in the element.

    not just bind this elemnt with the second table.

    Second node will also have the cardinality 0:n, because this is also binded with the table.

    Coding part for this is as below:

    method ONACTIONSELECT .

    DATA lo_nd_cn_mara TYPE REF TO if_wd_context_node.

    DATA lo_el_cn_mara TYPE REF TO if_wd_context_element.

    DATA ls_cn_mara TYPE wd_this->element_cn_mara.

    DATA ls_cn_mara1 TYPE wd_this->elements_cn_mara.

    • navigate from <CONTEXT> to <CN_MARA> via lead selection

    lo_nd_cn_mara = wd_context->get_child_node( name = wd_this->wdctx_cn_mara ).

    • @TODO handle not set lead selection

    IF lo_nd_cn_mara IS INITIAL.

    ENDIF.

    • get element via lead selection

    lo_el_cn_mara = lo_nd_cn_mara->get_element( ).

    • @TODO handle not set lead selection

    IF lo_el_cn_mara IS INITIAL.

    ENDIF.

    • alternative access via index

    • lo_el_cn_mara = lo_nd_cn_mara->get_element( index = 1 ).

    • @TODO handle non existant child

    • IF lo_el_cn_mara IS INITIAL.

    • ENDIF.

    • get all declared attributes

    lo_el_cn_mara->get_static_attributes(

    IMPORTING

    static_attributes = ls_cn_mara ). " here u are getting the selected row of the table.

    APPEND ls_cn_mara to ls_cn_mara1. " append the row in the table so that can be binded with the second node

    DATA lo_nd_cn_maraout TYPE REF TO if_wd_context_node.

    DATA lo_el_cn_maraout TYPE REF TO if_wd_context_element.

    DATA ls_cn_maraout TYPE wd_this->element_cn_maraout.

    • navigate from <CONTEXT> to <CN_MARAOUT> via lead selection

    lo_nd_cn_maraout = wd_context->get_child_node( name = wd_this->wdctx_cn_maraout ).

    • Bind the table with the second node

    lo_nd_cn_maraout->bind_table( ls_cn_mara1 ).

    endmethod.

    ->cn_mara is the first node.

    ->cn_mara1 is the second node

    Thanks,

    Pankaj Aggarwal

    Edited by: Pankaj Aggarwal on Nov 19, 2008 7:40 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Pankaj,

      I tried your code and the problem is at any time second table will have only one row because it is getting overwritten everytime we select a row in first table

      Thanks

      Bala Duvvuri

  • avatar image
    Former Member
    Nov 19, 2008 at 06:46 AM

    hi,

    Using the shuttle UI element , u can copy the data from one table to another table .

    follow this blog :

    [https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/8793] [original link is broken] [original link is broken] [original link is broken];

    Thanks and Regards

    Add comment
    10|10000 characters needed characters exceeded