10-27-2015 1:04 PM
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-27-2015 1: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
10-27-2015 1:43 PM
Plz find the attached sample data. Based on the data in the table hierarchy should be applied.
10-27-2015 1:58 PM
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?
10-27-2015 2:04 PM
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.
10-27-2015 2:07 PM
10-27-2015 2:16 PM
Hi Raju,
Is the internal table structure always changing in your requirement? If not did you try checking the below example?
10-27-2015 2:19 PM
The structure is always changing. The table I've given is just to understand and build hierarchy from it.
10-28-2015 8: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.
10-28-2015 11:09 AM
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).
10-28-2015 11:36 AM
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