Skip to Content
avatar image
Former Member

2 ALV Tree1 and Tree2 with drag and drop and button

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 29, 2017 at 12:08 PM

    Hi!

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

    Evgeny

    Add comment
    10|10000 characters needed characters exceeded

  • May 29, 2017 at 12:16 PM

    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).

    Add comment
    10|10000 characters needed characters exceeded