Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CL_GUI_ALV_TREE & grid lines

rainer_hbenthal
Active Contributor
0 Kudos

HI,

is it possible to have grid lines using the class CL_GUI_ALV_TREE? Remember this class does not have a layout structure in first_display call, but has a layoutstructure in the add_node method, which is bad documented. Any help about htis struture, espacially the style fields, are welcome.

thx

1 REPLY 1

former_member188685
Active Contributor
0 Kudos

Hi,

you need to loop the data and set the layout, and add the nodes to alv tree using add_node method , while doing pass the layout info.

  LOOP AT gt_cls INTO l_alv_data-grid_data.
    PERFORM setup_grid_attrs USING l_alv_data.
    PERFORM add_sub_tree USING l_alv_data.
  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  setup_grid_attrs
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LAYOUT   text
*----------------------------------------------------------------------*
FORM setup_grid_attrs USING p_alv_data TYPE zty_ecat_toc_tree.

  CLEAR: p_alv_data-node_layout, p_alv_data-item_layout.

  p_alv_data-relationship = 6.
  p_alv_data-node_text    = p_alv_data-grid_data-cltx2.

  IF p_alv_data-grid_data-stufe IS INITIAL.
    IF p_alv_data-grid_data-clin1 = p_alv_data-grid_data-clin2.
      CLEAR: p_alv_data-grid_data-cltx2.
      p_alv_data-node_layout-n_image   = icon_tree.
      p_alv_data-node_layout-exp_image = icon_tree.
    ELSE.
      CLEAR  p_alv_data-node_text.
      p_alv_data-node_text = p_alv_data-grid_data-clas2.
      CLEAR  p_alv_data-grid_data-clas2.
      p_alv_data-node_layout-n_image   = icon_material.
      p_alv_data-node_layout-exp_image = icon_material.
*      p_alv_data-item_layout-class
*          = cl_gui_column_tree=>item_class_link.
*      p_alv_data-item_layout-fieldname = '&HIERARCHY'.
    ENDIF.
  ELSE.
    CLEAR: p_alv_data-grid_data-cltx2.
*    READ TABLE gt_cls WITH KEY clin1 = p_alv_data-grid_data-clin2
*      TRANSPORTING NO FIELDS.
    READ TABLE gt_cls
      WITH KEY clas1 = p_alv_data-grid_data-clas2
               stufe = 0 TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      p_alv_data-node_layout-n_image   = icon_oo_object.
      p_alv_data-node_layout-exp_image = icon_oo_object.
    ELSE.
      p_alv_data-node_layout-n_image   = icon_oo_class.
      p_alv_data-node_layout-exp_image = icon_oo_class.
    ENDIF.
  ENDIF.

ENDFORM.                    "setup_grid_attrs

*&---------------------------------------------------------------------*
*&      Form  add_sub_tree
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_CLS      text
*----------------------------------------------------------------------*
FORM add_sub_tree USING p_alv_data TYPE zty_ecat_toc_tree.

  DATA: lt_item_layout TYPE lvc_t_layi.

  REFRESH lt_item_layout.
  IF p_alv_data-item_layout IS NOT INITIAL.
    APPEND p_alv_data-item_layout TO lt_item_layout.
  ENDIF.

*-check for parent
  READ TABLE gt_parent_stack INTO g_parent_stack
       WITH KEY parent = p_alv_data-grid_data-clin1
       BINARY SEARCH.
  IF sy-subrc <> 0.
    CLEAR g_parent_stack.
  ENDIF.

  CALL METHOD g_alv_tree->add_node
    EXPORTING
      i_relat_node_key = g_parent_stack-node_key
      i_relationship   = p_alv_data-relationship
      i_node_text      = p_alv_data-node_text
      is_outtab_line   = p_alv_data-grid_data
      is_node_layout   = p_alv_data-node_layout
      it_item_layout   = lt_item_layout
    IMPORTING
      e_new_node_key   = p_alv_data-node_key
    EXCEPTIONS
      node_not_found   = 1.

  IF sy-subrc <> 0.
  ENDIF.

*-since materials do not contain classes, use their parent
*-as search.
  g_srch = p_alv_data-grid_data-clin2.
*  IF p_alv_data-grid_data-clin2 IS INITIAL.
*    g_srch = p_alv_data-grid_data-clin1.
*  ENDIF.

*-insert current entry with tree node
  READ TABLE gt_parent_stack
       WITH KEY parent = g_srch
       BINARY SEARCH TRANSPORTING NO FIELDS.
  IF sy-subrc <> 0.
    CLEAR g_parent_stack.
    g_parent_stack-parent = g_srch.
    g_parent_stack-node_key = p_alv_data-node_key.
    INSERT g_parent_stack INTO gt_parent_stack INDEX sy-tabix.
  ENDIF.

ENDFORM.                    "add_sub_tree

Regards

Vjay