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: 

Shortdump in ALV-Grid when building a node-hierarchy

Former Member
0 Kudos
220

Hi Experts,

i read several posts to my problem, but i found no solution.

I want to build a header-hierarchy in my report. for this i use the following form:

FORM add_h_header_line USING  s_zma_header TYPE zma_header
                              p_relat_key TYPE lvc_nkey
                     CHANGING p_node_key TYPE lvc_nkey.
  DATA: l_node_text TYPE lvc_value,
        s2_zma_header  TYPE zma_header.

  DATA: lt_item_layout TYPE lvc_t_layi,
        ls_item_layout TYPE lvc_s_layi,
        ls_node_layout TYPE lvc_s_layn.
 set item-layout
  ls_item_layout-t_image = '@7T@'.
  ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
  APPEND ls_item_layout TO lt_item_layout.
* longtext for CARRID
  READ TABLE it_u_header WITH KEY typ = s_zma_header-typ.
  l_node_text =  it_u_header-text.
* D'n'D-ID
  ls_node_layout-dragdropid = g_handle_tree.
* add node for CARRID
  CALL METHOD tree1->add_node
    EXPORTING
      i_relat_node_key = p_relat_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      i_node_text      = l_node_text
      is_node_layout   = ls_node_layout
      is_outtab_line   = s2_zma_header
      it_item_layout   = lt_item_layout
    IMPORTING
      e_new_node_key   = p_node_key.
  CLEAR it_u_header.
ENDFORM.                               " ADD_H_HEADER_LINE

When the form calls the method add_node, there will be an shurtdump, because in the method the field-symbol <tab1> can't be assigned:

METHOD ADD_NODE.
  FIELD-SYMBOLS: <TAB1> TYPE standard TABLE,
                 <wa> type any.

  assign mt_outtab->* to <tab1>.

* insert line in outtab
  DATA: L_INDEX TYPE SY-TABIX.
  if is_outtab_line is initial.
*   create initial line
    data l_dref_wa type ref to data.
    create data l_dref_wa like line of <tab1>.
    assign l_dref_wa->* to <wa>.
    l_index = 0.
    append <wa> to <Tab1>.
  else.
    APPEND IS_OUTTAB_LINE TO <TAB1>.
  endif.
  L_INDEX = SY-TABIX.

* add node to model
  CALL METHOD ME->ADD_MODEL_NODE
              EXPORTING
                 I_RELAT_NODE_KEY  = I_RELAT_NODE_KEY
                 I_RELATIONSHIP    = I_RELATIONSHIP
                 IS_NODE_LAYOUT    = IS_NODE_LAYOUT
                 IT_ITEM_LAYOUT    = IT_ITEM_LAYOUT
                 I_NODE_TEXT       = I_NODE_TEXT
                 I_INDEX_OUTTAB    = L_INDEX
              IMPORTING
                 E_NEW_NODE_KEY    = E_NEW_NODE_KEY.

ENDMETHOD.

in other forums I read that I have to build global variables. I did, but it didn't run. Can anybody please help me?

Thank you very much.

Stephan

1 ACCEPTED SOLUTION

franois_henrotte
Active Contributor
0 Kudos
96

MT_OUTTAB is a data reference, in other words a variable containing an address pointing to your data table

as long as you didn't fill the variable with the address, the ASSIGN will cause a short dump

the filling of MT_OUTTAB is done in the method SET_TABLE_FOR_FIRST_DISPLAY

* set pointer to output_table
  get reference of it_outtab into mt_outtab.

so you have to call this method before you are able to add nodes.

the main advantage of class CL_GUI_ALV_TREE is it builds the node hierarchy for you. If you want to build it by yourself you should consider another class like CL_GUI_COLUMN_TREE

5 REPLIES 5

franois_henrotte
Active Contributor
0 Kudos
97

MT_OUTTAB is a data reference, in other words a variable containing an address pointing to your data table

as long as you didn't fill the variable with the address, the ASSIGN will cause a short dump

the filling of MT_OUTTAB is done in the method SET_TABLE_FOR_FIRST_DISPLAY

* set pointer to output_table
  get reference of it_outtab into mt_outtab.

so you have to call this method before you are able to add nodes.

the main advantage of class CL_GUI_ALV_TREE is it builds the node hierarchy for you. If you want to build it by yourself you should consider another class like CL_GUI_COLUMN_TREE

0 Kudos
96

Hi experts,

it works. The reason was as Francois stated.

I placed the SET_TABLE_FOR_FIRST_DISPLAY-Method befor the form add_h_header. So the pointer is set to mt_ottab.

Thank you very much.

0 Kudos
96

Hi experts,

one more aditional question to this problem.

Is it possible to expand the whole tree on start?

Thank you very much.

0 Kudos
96

call method EXPAND_NODE and provide parameter I_EXPAND_SUBTREE = 'X'

if you have only one root node you just call it once

if you have several root nodes you have to call it for each root node

0 Kudos
96

Hi Francois,

thank you very much.

I tried to call the method EXPAND_NODE.

CALL METHOD tree1->expand_node
        EXPORTING
          i_node_key          = ???
          i_level_count       = 1
          i_expand_subtree    = 'X'
*        EXCEPTIONS
*          failed              = 1
*          illegal_level_count = 2
*          cntl_system_error   = 3
*          node_not_found      = 4
*          cannot_expand_leaf  = 5
*          others              = 6
              .

But how can I get the i_node_key?

When I add the node, the variable l_h_header_key is not valid to i_node_key.

CALL METHOD tree1->add_node
        EXPORTING
          i_relat_node_key = ''
*          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = l_node_text
          is_node_layout   = ls_node_layout
          is_outtab_line   = s2_zma_header
          it_item_layout   = lt_item_layout
        IMPORTING
          e_new_node_key   = l_h_header_key.
      CLEAR it_h_header.

Thank you very much.