Skip to Content
0

2 ALV Tree1 and Tree2 with drag and drop and button

May 29, 2017 at 12:00 AM

85

avatar image
Former Member

Hello Everyone,

I have implemented 2 ALV tree's with Tree1 on left window and Tree2 on right window. I am dragging item from left window to right window and this functionality is working fine. Now I have added a button on Tree2(right window) to delete the node. When I try to delete the node, I am getting dump saying "object reference is not possible". In debug mode Tree2 reference is not created which is causing dump. I have added small code to understand the issue better. Please help me how to assign object reference to Tree2 to delete the node.

CLASS lcl_main DEFINITION.
PUBLIC SECTION.

DATA:

splitter TYPE REF TO cl_gui_splitter_container,
container TYPE REF TO cl_gui_custom_container,
container_1 TYPE REF TO cl_gui_container,
container_2 TYPE REF TO cl_gui_container,
tree1 TYPE REF TO cl_gui_alv_tree,
tree2 TYPE REF TO cl_gui_alv_tree,
g_drag TYPE REF TO cl_dragdrop,
g_drop TYPE REF TO cl_dragdrop,
g_toolbar2 TYPE REF TO cl_gui_toolbar.

METHODS:
fill_storage_section,
display_only_storage_section,
get_data, " Data Fatch
build_display, " Display Container
display_output1, " display output1 (left window)
display_output2, " display output2 (right window)
add_node_output1 "
IMPORTING table TYPE zZHU_COCKPIT

key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
add_node_output2 " Add node to vbap
IMPORTING table TYPE ZHU_COCKPIT

key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,

change_toolbar2,
register_events_tree2,
dnd_behaviour, " Drag and drop behavour
register_events_output1, " Register Events Ekpo
register_events_output2, " Register events vbap
handle_drag_multiple " Drag Multiple Values
FOR EVENT on_drag_multiple
OF cl_gui_alv_tree
IMPORTING sender node_key_table fieldname drag_drop_object,
handle_drop " Drop the values
FOR EVENT on_drop
OF cl_gui_alv_tree
IMPORTING sender node_key drag_drop_object,
add_node_drop " Add node to Drop Node
IMPORTING table TYPE ZHU_COCKPIT
key TYPE lvc_nkey
text TYPE lvc_value
CHANGING i_key TYPE lvc_nkey,

on_function_selected
FOR EVENT function_selected OF cl_gui_toolbar
IMPORTING fcode,
remove_hu,
create_to.

METHOD on_function_selected.

CASE fcode.
WHEN 'REMOVE'.
CALL METHOD remove_item
ENDCASE.

METHOD remove_item.

DATA obj_tree_event_receiver TYPE REF TO lcl_tree_event_receiver.
DATA: lt_selected_node TYPE lvc_t_nkey.
DATA l_selected_node TYPE lvc_nkey.

CALL METHOD add_node_drop.

CALL METHOD tree2->get_selected_nodes
CHANGING
ct_selected_nodes = lt_selected_node.
CALL METHOD cl_gui_cfw=>flush.

READ TABLE lt_selected_node INTO l_selected_node INDEX 1.

CALL METHOD tree2->delete_subtree
EXPORTING
i_node_key = l_selected_node
i_update_parents_expander = ''
i_update_parents_folder = space
EXCEPTIONS
node_key_not_in_model = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here

ENDIF.
ENDMETHOD.

FYI, Logic to display ALV tree, drag and drop functionality is not added in this post.

Thanks,
Shreekant

10 |10000 characters needed characters left characters exceeded

wrong tag removed

SAP Forum is an SAP event, see here a blog from such an event: https://blogs.sap.com/?p=467172 , using this tag people can talk about this event. Your question is not related to this event.

Please use tags which reflect your working area.

Kindly post with the most relevant primary tag to get the attention of the right experts who can help. Posting with wrong tags adds just garbage to the activity stream of the people who follow this tag. Without the proper tag, the right people will not see your question and those that do see are not likely be able to provide a solution.

In order to find the correct tag, please visit the Browse the community page: https://www.sap.com/community/topic.all-content.html or select it from the the list of primary tags here: http://sapassets.edgesuite.net/tools/SAP-Community-Tags.xlsx

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Evgeny Gubenko May 29, 2017 at 12:08 PM
1

Hi!

Please refer to the test program BCALV_TREE_04, it has an example of subtree deletion.

Evgeny

Share
10 |10000 characters needed characters left characters exceeded
Sandra Rossi May 29, 2017 at 12:16 PM
0

Go into debug, set a watchpoint on tree2 to see when it's freed. Moreover, make sure that you keep the same lcl_main instance (that you don't reinstantiate it).

Share
10 |10000 characters needed characters left characters exceeded