Skip to Content
avatar image
Former Member

How to Define hierarchy for an unknown internal table

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Oct 27, 2015 at 01:34 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 27, 2015 at 02:16 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

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

  • avatar image
    Former Member
    Oct 28, 2015 at 08:10 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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