cancel
Showing results for 
Search instead for 
Did you mean: 

How to move data between two alv tables in a view

Former Member
0 Kudos

I have two alv table in a single view and i have enabled multiple line selections for both the tables. can some one tell me how to move selected data from one alv table to another alv table.

Thanks,

suri

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Suri,

I assume you have two ALV tables and a button in between them that says "Move" or something like that. If the button if in your ALV table itself, you need to include more code for adding the button. Still the moving functionality is the same.

To do this, have two context nodes, one for table1 and one for table2. When initializing both ALVs, you have to set_data as node1 for table1 and node2 for table2. After selecting the rows and clicking on the move button, in the event handler of the button, have the following code:

data: lr_node1 type ref to if_wd_context_node,

lr_node2 type ref to if_wd_context_node,

lt_selected_elements type wdr_context_element_set,

lr_element type ref to if_wd_context_element,

wa_node1 type if_main=>element_node1, "Replace this with your node structure

itab_node1 type if_main=>elements_node1.

lr_node1 = wd_context->get_child_node( 'Node1' ). "replace with actual node names

lr_node2 = wd_context->get_child_node( 'Node2' ).

lt_selected_elements = lr_node1->get_selected_elements( abap_true ).

loop at lt_selected_elements into lr_element.

lr_element->get_static_attributes(

importing static_attributes = wa_node1

).

append wa_node1 to itab_node1.

lr_node1->remove_element( lr_element ).

endloop.

lr_node2->bind_elements( itab_node1 ).

What you are doing in this code is getting the selected elements, getting the attributes of each of the selected element in the loop and appending them to the internal table. If you want a copy between the tables, the remove_element statement can be ignored. Include it if you want to move and not copy.

The selection property has to be set as 0..n in the first node. The selection_mode of the ALV also has to be set to multiple selection. You can find that in the table settings.

And this code assumes that both ALV tables have the same structure. If they are different, you should do a move-corresponding between structures and append to table. The code also assumes the node names to be node1 and node2. Use the code wizard to generate code for your node names.

Hope this helps. Award points if your problem is solved.

Regards,

Nithya

Former Member
0 Kudos

Nithya,

Iam getting a dump at the last statement

"lr_node2->bind_elements( itab_node1 )"

the dump reads "Dynamic type conflict when assigning reference"

Both the nodes has same structure type. do you have any idea about this?

Thanks,

suri

mohammed_anzys
Contributor
0 Kudos

hi

itab_node1 type table of if_main=>element_node1.

Check whether its working this way......

Thanks

Anzy

Former Member
0 Kudos

hey Nithya i got the problem it was just a typo error. it works great. Thank you very much.

Just have another issue when there is data in both the ALV tables and when i try to move data from table1 to table2 the date in table2 is overwritten which must not be the case in my requirement, it must append to the existing data in table2. any suggestions on this.

thanks,

shyam

mohammed_anzys
Contributor
0 Kudos

Hi,

CALL METHOD lr_node2->BIND_ELEMENTS

EXPORTING

NEW_ITEMS = itab_node1

SET_INITIAL_ELEMENTS = ABAP_FALSE

.

By default the set_initial_elements will be true ,which means it removes all the existing elements and add the new ones....If you set it as abap_false ..it will only append to the existing values.

This will solve your problem

Thanks

Anzy

Award points if this solves your problem

mohammed_anzys
Contributor
0 Kudos

Hi

Does it solve your problem?

Thanks

Anzy

Former Member
0 Kudos

awesome.. thank you very much Anzy that worked.

Thank you too Nithya..

mohammed_anzys
Contributor
0 Kudos

Hi Suri,

Good that it got solved.Have a nice day.

Thanks

Anzy

Former Member
0 Kudos

After selectig lines from one ALV table use this get_selected_elements() method of class IF_WD_CONTEXT_NODE .This way you can all selected rows.Bind this raw to the node.But mind well you ahev to register for the event on_function() of ALV control and you have to write the code there.

NIrad