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: 

How to Define hierarchy for an unknown internal table

Former Member
0 Kudos

I am trying to display a dynamic alv tree, whose contents are passed through an internal table at runtime. How can code a method for defining the hierarchy from the data in the table.

10 REPLIES 10

Former Member
0 Kudos

Do you have a column in your table structure that contains the hierarchy level?

On what criteria should the hierarchy be built?

After you got the nodes reference from the ALV_tree you can start adding nodes, basically how you like, but any kind of differentiation is needed to determine where an element shall be placed

0 Kudos

Plz find the attached sample data. Based on the data in the table hierarchy should be applied.

0 Kudos

ok, just to clarify the result should then be:

A

     A1

     A2

     A3

B

     B1

     B2

          B21

          B22

          B23

     B3

ok 2 more questions:

so what is the count column for?

Where do you store your data? In the same table or in a second table?

0 Kudos

That is just a sample data. There is no special significance for the 'count' column, It given just to understand how data comes in that internal table.

Since the table is passed as parameter to a method, we will store the data in other table to perform operations.

0 Kudos

ok, give me a minute, will edit then

Former Member
0 Kudos

Hi Raju,

Is the internal table structure always changing in your requirement? If not did you try checking the below example?

Example about ALV Tree - Code Gallery - SCN Wiki

0 Kudos

The structure is always changing. The table I've given is just to understand and build hierarchy from it.

Former Member
0 Kudos

ok been a bit busy yesterday, but here you go for creating the tree from an unknown Table

After the factory you can start building your hierarchy as usual using the add_node function of the CL_SALV_NODES object you get from the ALV by using  the get_nodes function.

Also don't forget in the current way this code will dump if you throw something else but a table on the importing parameter, you might want to add some error handling or escalate the error.

  METHODS:
      build_hierarchy
       
IMPORTING
            it_table    
TYPE table, "Empty Table with the target Structure

METHOD build_hierarchy
DATA:     lr_type   TYPE REF TO cl_abap_tabledescr,
          lt_table 
TYPE REF TO data.

   
FIELD-SYMBOLS: <ls_hierarchy> TYPE ty_hierarchy,
                   <lt_table>    
TYPE table.

    lr_type ?= cl_abap_tabledescr
=>describe_by_data( it_table ).

   
CREATE DATA lt_table TYPE HANDLE lr_type.
   
ASSIGN lt_table->* TO <lt_table>.

   
TRY .
        cl_salv_tree
=>factory(
         
IMPORTING
            r_salv_tree
= mr_tree
         
CHANGING
            t_table    
= <lt_table>
              
).
     
CATCH cx_salv_error.
       
" Implement error handling
       
EXIT.
   
ENDTRY.
    " Build Hierarchy here

ENDMETHOD.

0 Kudos

Hi markus,Thank u.

I've understood the part of dynamic table creation.I'm actually concerned with hierarchy creation.

As the hierarchy that I've to create is dynamic in nature,I would need a thought to identify the nodes and child fields from the internal table ( it_table).

0 Kudos

at this stage it_table has to be empty, so there is no way to create a hierarchy out of it.

to build a hierarchy you have to define some kind of logic that applies to the tables you want to display if these tables should be the only input