‎2007 Jul 24 9:48 AM
Hi,
I have the requirement of developing thr column tree but the problem is that the number of rows that should be displayed is known only at the runtime as the entries are filtered and finally all the entries are present in an internal table.
So i want to display the rows in a colum tree format.
I know the methods that are used for the Column tree but i want to know how to handle the number of rows that will be known only at the runtime.
Cheers!!!
‎2007 Jul 24 10:04 AM
Number of rows depend on number of records in internal table passed to method set_table_for_first_display.
Which class are you using...
Are you talking about number of columns?
‎2007 Jul 24 10:09 AM
Im using cl_column_tree_model .
i have fixed number of colums but number of rows is different.
im using the methods add_nodes,relat_last_child,add_items ...etc etc
i want to know how to handle multiple items
for example
1
2
3
.
.
.
n
where n is unknown.
‎2007 Jul 24 10:37 AM
Call method 'add_node' as many time as you want... add_node is meant for adding row dynamically...
‎2007 Jul 24 10:54 AM
refer below code... name of the customer container in screen 100 is 'CUSTOM'
This code add nodes at runtime... depending on the use input it reterieves the records from table T001. Number of row will depend on user input..
REPORT zpw_tree .
TABLES t001 .
DATA : i_t001 TYPE TABLE OF t001 ,
w_t001 TYPE t001 .
DATA : g_custom_container TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_column_tree_model.
DATA: item_table TYPE treemcitab,
item TYPE treemcitem,
node_key TYPE tm_nodekey.
DATA : hierarchy_header TYPE treemhhdr.
SELECT-OPTIONS : s_bukrs FOR t001-bukrs .
START-OF-SELECTION .
SELECT *
INTO TABLE i_t001
FROM t001
WHERE bukrs IN s_bukrs .
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE STATUS_0100 OUTPUT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
CREATE OBJECT g_tree
EXPORTING
node_selection_mode = cl_column_tree_model=>node_sel_mode_single
item_selection = 'X'
hierarchy_column_name = 'BUKRS' "#EC NOTEXT
hierarchy_header = hierarchy_header
EXCEPTIONS
illegal_node_selection_mode = 1
illegal_column_name = 2.
CALL METHOD g_tree->add_column
EXPORTING
name = 'BKTXT'
width = 21
header_text = 'Company Name'
EXCEPTIONS
column_exists = 1
illegal_column_name = 2
too_many_columns = 3
illegal_alignment = 4.
* create a container for the tree model
CREATE OBJECT g_custom_container
EXPORTING
container_name = 'CUSTOM'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
CALL METHOD g_tree->create_tree_control
EXPORTING
parent = g_custom_container
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
failed = 4
tree_control_already_created = 5.
* Add node
CLEAR item.
item-item_name = 'BUKRS'.
item-class = cl_column_tree_model=>item_class_text.
item-text = 'Companies'.
APPEND item TO item_table.
CLEAR item.
item-item_name = 'BKTXT'.
item-class = cl_column_tree_model=>item_class_text.
item-text = 'Company Names'.
APPEND item TO item_table.
CALL METHOD g_tree->add_node
EXPORTING
node_key = 'ROOT'
isfolder = 'X'
item_table = item_table
EXCEPTIONS
node_key_exists = 1
node_key_empty = 2
illegal_relationship = 3
relative_node_not_found = 4
error_in_item_table = 5.
LOOP AT i_t001 INTO w_t001 .
CLEAR : item ,
item_table .
item-item_name = 'BUKRS'.
item-class = cl_column_tree_model=>item_class_text.
item-text = w_t001-bukrs.
APPEND item TO item_table.
CLEAR item.
item-item_name = 'BKTXT'.
item-class = cl_column_tree_model=>item_class_text.
item-text = w_t001-butxt .
APPEND item TO item_table.
node_key = w_t001-bukrs .
CALL METHOD g_tree->add_node
EXPORTING
node_key = node_key
relative_node_key = 'ROOT'
relationship = cl_tree_model=>relat_last_child
isfolder = ' '
item_table = item_table
EXCEPTIONS
node_key_exists = 1
node_key_empty = 2
illegal_relationship = 3
relative_node_not_found = 4
error_in_item_table = 5.
ENDLOOP.
* expand the root node
CALL METHOD g_tree->expand_node
EXPORTING
node_key = 'ROOT'
EXCEPTIONS
node_not_found = 1.
CALL METHOD g_tree->adjust_column_width
EXPORTING
all_columns = 'X' .
ENDMODULE. " STATUS_0100 OUTPUT
‎2007 Jul 24 10:58 AM
Thanks Pavan,
My requirement is such that each node can have n number of items and this inturn can have items. I will try doing the example which u have suggested and get back if i have any problems with that.
‎2007 Jul 24 11:25 AM
That not a big problem.. you will have to play with tha values of 'node_key' and 'relative_node_key' of method add_node... for example see this version.. this will add row as child of previous row...
REPORT zpw_tree .
TABLES t001 .
DATA : i_t001 TYPE TABLE OF t001 ,
w_t001 TYPE t001 .
DATA : g_custom_container TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_column_tree_model.
DATA: item_table TYPE treemcitab,
item TYPE treemcitem,
node_key TYPE tm_nodekey,
parent type tm_nodekey.
DATA : hierarchy_header TYPE treemhhdr.
SELECT-OPTIONS : s_bukrs FOR t001-bukrs .
START-OF-SELECTION .
SELECT *
INTO TABLE i_t001
FROM t001
WHERE bukrs IN s_bukrs .
CALL SCREEN 100.
*---------------------------------------------------------------------*
* MODULE STATUS_0100 OUTPUT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
CREATE OBJECT g_tree
EXPORTING
node_selection_mode = cl_column_tree_model=>node_sel_mode_single
item_selection = 'X'
hierarchy_column_name = 'BUKRS' "#EC NOTEXT
hierarchy_header = hierarchy_header
EXCEPTIONS
illegal_node_selection_mode = 1
illegal_column_name = 2.
CALL METHOD g_tree->add_column
EXPORTING
name = 'BKTXT'
width = 21
header_text = 'Company Name'
EXCEPTIONS
column_exists = 1
illegal_column_name = 2
too_many_columns = 3
illegal_alignment = 4.
* create a container for the tree model
CREATE OBJECT g_custom_container
EXPORTING
container_name = 'CUSTOM'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
CALL METHOD g_tree->create_tree_control
EXPORTING
parent = g_custom_container
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
failed = 4
tree_control_already_created = 5.
* Add node
CLEAR item.
item-item_name = 'BUKRS'.
item-class = cl_column_tree_model=>item_class_text.
item-text = 'Companies'.
APPEND item TO item_table.
CLEAR item.
item-item_name = 'BKTXT'.
item-class = cl_column_tree_model=>item_class_text.
item-text = 'Company Names'.
APPEND item TO item_table.
CALL METHOD g_tree->add_node
EXPORTING
node_key = 'ROOT'
isfolder = 'X'
item_table = item_table
EXCEPTIONS
node_key_exists = 1
node_key_empty = 2
illegal_relationship = 3
relative_node_not_found = 4
error_in_item_table = 5.
LOOP AT i_t001 INTO w_t001 .
IF sy-tabix = 1 .
parent = 'ROOT' .
else.
parent = node_key .
endif.
CLEAR : item ,
item_table .
item-item_name = 'BUKRS'.
item-class = cl_column_tree_model=>item_class_text.
item-text = w_t001-bukrs.
APPEND item TO item_table.
CLEAR item.
item-item_name = 'BKTXT'.
item-class = cl_column_tree_model=>item_class_text.
item-text = w_t001-butxt .
APPEND item TO item_table.
node_key = w_t001-bukrs .
CALL METHOD g_tree->add_node
EXPORTING
node_key = node_key
relative_node_key = parent
relationship = cl_tree_model=>relat_last_child
isfolder = ' '
item_table = item_table
EXCEPTIONS
node_key_exists = 1
node_key_empty = 2
illegal_relationship = 3
relative_node_not_found = 4
error_in_item_table = 5.
ENDLOOP.
* expand the root node
CALL METHOD g_tree->expand_node
EXPORTING
node_key = 'ROOT'
EXCEPTIONS
node_not_found = 1.
CALL METHOD g_tree->adjust_column_width
EXPORTING
all_columns = 'X' .
ENDMODULE. " STATUS_0100 OUTPUT