Skip to Content
0
Former Member
Jan 21, 2011 at 05:01 PM

ALV Tree will not display as Hierarchy?

206 Views

Hi Forums,

I am scratching my head to my ALV tree issue. I want to build an org structure as similar to FM RHPH_STRUCTURE_READ.

I apply the same parent id, levels etc. to my structure but my output only display's a deep structure of levels just one after the other to the end.

I build my Hierarchy with the below code. How can get it to display in the appropriate level structure as in the above function module.

For those who want to know I am calculating budget info on a person by person basis which why I cannot use a whole org structure and must build it myself.

  LOOP AT gt_vip_display_sort INTO ls_vip_display_sort WHERE id <> 0.

* read parent node
    READ TABLE lt_parents INTO ls_parent
         WITH KEY id = lv_seqnr.
    IF sy-subrc <> 0.
      lv_parent_id = ' '.
    ELSE.
      lv_parent_id = ls_parent-tree_id.
    ENDIF.
    lv_node_text = ls_vip_display_sort-org_txt.

    ls_vip_display-id            = ls_vip_display_sort-id.
    ls_vip_display-parent        = ls_vip_display_sort-level.
    ls_vip_display-tree_id       = ls_vip_display_sort-tree_id.
    ls_vip_display-org_chief_txt = ls_vip_display_sort-org_chief_txt.
    ls_vip_display-vip_amount    = ls_vip_display_sort-vip_amount.
    ls_vip_display-vip_payout    = ls_vip_display_sort-vip_payout.
    ls_vip_display-vip_diff      = ls_vip_display_sort-vip_diff.

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

    "this will add the Top Node of the tree.
    IF lv_parent_id IS INITIAL.
      CALL METHOD gr_alv_tree_control->add_node
        EXPORTING
          i_relat_node_key     = ''
          i_relationship       = cl_gui_column_tree=>relat_last_child
          i_node_text          = lv_node_text
          is_outtab_line       = ls_vip_display
        IMPORTING
          e_new_node_key       = lv_top_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.

      ls_vip_display_sort-tree_id = lv_top_key.
      APPEND ls_vip_display_sort TO lt_parents.
      lv_seqnr = ls_vip_display_sort-id.
    ELSE.
*   add leaf nodes
      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.
      ls_vip_display_sort-tree_id = lv_new_key.
      APPEND ls_vip_display_sort TO lt_parents.
      lv_seqnr = ls_vip_display_sort-id.

    ENDIF.
    CLEAR:
         ls_vip_display,
         ls_layout_item,
         ls_node_layout.

  ENDLOOP.