Skip to Content
avatar image
Former Member

ALV tree with Dynamic child nodes

Hello Experts,

Have a requirement to build a tree structure with child nodes and on clicking or double clicking of child nodes - on the right side of the screen Editable ALV to load where the user can enter details and save to custom table.

I was able to do a proto using Simple ALV tree cl_gui_simple_tree as shown below.


Now the problem arises when the Child nodes are to be dynamic - Simple ALV as per my understanding does not allow this - as the NodeKey structure is fixed.... thats where i am struck.

Explored BCALV programs and SDN - tried using cl_gui_alv_tree - but this requires output table to provided and which display the columns - does not fit what i am looking for.

We need the child nodes to displayed and only on double click require ALV to be loaded with variable columns....

Simple ALV seems to suit perfect - provided it can be made dynamic nodes ... any trick or tips to make this work. Please suggest or any sample program or reference would greatly help.

alv-tree.jpg (101.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Jun 10, 2017 at 12:46 PM

    If you are using CL_GUI_ALV_TREE_SIMPLE, then you can't add new nodes after having used SET_TABLE_FOR_FIRST_DISPLAY. Instead, you may use CL_GUI_ALV_TREE, which provides the method ADD_NODE.

    Add comment
    10|10000 characters needed characters exceeded

    • Yes, it's possible.

      If you want additional columns in the tree, i.e. not only the "hierarchy column" but also additional columns at the right of this column, you can do it with CL_GUI_ALV_TREE. But if you don't need the ALV features, you may also use either CL_GUI_COLUMN_TREE or CL_COLUMN_TREE_MODEL. All three classes are using the same OCX control, so they have basically the same features and look like the same (only the class themselves restrict some of the control features, like CL_GUI_ALV_TREE_SIMPLE which doesn't allow adding nodes).

      If you prefer to display only a single text at each line (as you show in pictures), then you may use CL_GUI_SIMPLE_TREE or CL_SIMPLE_TREE_MODEL (both are based on an OCX control which is different from the OCX control for column trees). You can run the demo program SAPSIMPLE_TREE_CONTROL_DEMO.

      The double click feature is available for all trees. Displaying an ALV grid is possible, and do whatever you want too.

      Please look at the links provided by Raymond above.

  • Jun 09, 2017 at 08:02 AM

    I may not be following you correctly, but writing a wrapper around the cl_gui_Alv_Grid object that accepts a field catalog and a memory reference to a dynamically created work area and table seems to be quite easy to me. So, when you build your alv tree have a non displayable field which is a table of column names and their definitions (or the name of a DDic structure), and when the node is clicked create thE table using CREATE DATA, populate the table and get a memory reference to it. Pass that and the field catalog to your wrapper and then construct the ALV from that.

    You can also include things like the alv grid title etc etc as parameters or even the name of a global class which encapsulates the alv grid object so that you can handle data in different ways..


    Add comment
    10|10000 characters needed characters exceeded

    • What I am suggesting is to have two additional non displayed fields on the tree table row. This would contain a field cayalog and the second will have an internal table with the relevant records in it.

      I obviously don't follow what your on about with the nodes - I have no problem adding extra nodes to tree. There is no fixed number - each node is a structure not a distinct field in the structure

  • Jun 09, 2017 at 08:24 AM

    Which of the avalable tree classes did you already try (Overview of SAP Tree Classes), did you check for samples)

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 19, 2017 at 04:34 AM

    thanks all i am able to display varying nodes using Simple ALV tree and split container to display the ALV grid. works fine. thanks a lot for all your help and suggestions.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Sandra, its working now - as we made few changes to requirement and the development as well... firstly now we have arrived a tree at the time of initiating the tree object - hence the simple tree is able to do it...

      also have now used docking container for tree object and the other half of the screen have used custom container in a screen to display ALV object -which will change as per the double click event on tree nodes...

      thanks again.