Hi All,
This is my first tree ALV and I have the data displaying in the tree format but all lines are showing as PARENT Nodes?
I have tried to put in a sequence and to make sure they go in the right order but they only show in one line... no leaf nodes showing under what should be a 'parent' node...
What am I missing?
How tree is created:
** create alv_tree control
CREATE OBJECT gr_alv_tree_control
EXPORTING
parent = gr_control_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7
OTHERS = 8.
How the hierarchy is built:
LOOP AT gt_vip_display_sort INTO ls_vip_display_sort WHERE seqnr <> 0.
lv_tabix = sy-tabix.
* read parent node
READ TABLE lt_parents INTO ls_parent
WITH KEY lv_seqnr.
IF sy-subrc <> 0.
lv_parent_id = ' '.
ELSE.
lv_parent_id = ls_vip_display_sort-seqnr.
ENDIF.
lv_node_text = ls_vip_display_sort-org_txt.
MOVE-CORRESPONDING ls_vip_display_sort TO ls_vip_display.
IF lv_node_text IS INITIAL.
ls_node_layout-n_image = lv_icon.
ls_node_layout-style = '5'.
CLEAR ls_layout_item.
ls_layout_item-fieldname = 'TEXT4'.
ls_layout_item-t_image = lv_icon.
APPEND ls_layout_item TO lt_layout_item.
ELSE.
* read icon from it_table
CLEAR ls_icon.
READ TABLE lt_icon INTO ls_icon WITH KEY otype = lv_otype.
IF ls_icon-icon IS INITIAL.
CALL FUNCTION 'OM_GET_ICON_OF_OTYPE'
EXPORTING
otype = gc_otype_o
IMPORTING
icon = ls_icon-icon
EXCEPTIONS
no_icon_found = 1
otype_not_found = 2
OTHERS = 3.
IF sy-subrc > 1.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ls_icon-otype = lv_otype.
APPEND ls_icon TO lt_icon.
ENDIF.
ls_node_layout-n_image = ls_icon-icon.
ls_node_layout-exp_image = ls_icon-icon.
CLEAR ls_layout_item.
ls_layout_item-fieldname = 'TEXT4'.
ls_layout_item-t_image = ls_icon-icon.
APPEND ls_layout_item TO lt_layout_item.
ENDIF.
IF lv_parent_id IS INITIAL.
* add parent node
CALL METHOD gr_alv_tree_control->add_node
EXPORTING
i_relat_node_key = lv_parent_id
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = lv_node_text
is_outtab_line = ls_vip_display
it_item_layout = lt_layout_item
is_node_layout = ls_node_layout
IMPORTING
e_new_node_key = lv_new_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ELSE.
* add leaf node
CALL METHOD gr_alv_tree_control->add_node
EXPORTING
i_relat_node_key = lv_parent_id
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = lv_node_text
is_outtab_line = ls_vip_display
is_node_layout = ls_node_layout "it_item_layout = lt_layout_item
IMPORTING
e_new_node_key = lv_new_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
APPEND ls_vip_display_sort TO lt_parents.
lv_seqnr = ls_vip_display_sort-seqnr.
CLEAR:
ls_vip_display,
ls_layout_item,
ls_node_layout.
ENDLOOP.