‎2006 Dec 06 2:12 PM
Hi all
please help me.I have to display values in tree view form based on the one input value called partner number.using this partner number i have to search a table zrelation and all the dependent relativ numbers on this partner should be displayed under this partner.If these dependent numbers are independent then no problem otherwise i have to display the numbers which or dependent on these relation numbers.Please help me to do this.
Thanks in advance.
Regards
Giri.
‎2006 Dec 06 2:17 PM
HI ,
You need to use<b> 'RS_TREE_CONSTRUCT'</b> function moduel ..
look at the sameple program ..
*******start of code
REPORT Ztree_TEST_PGM.
Type-pools : fibs,stree.
data : t_node type snodetext.
data : node_tab like t_node occurs 0 with header line.
clear : node_tab, node_tab[].
node_tab-type = 'T'.
node_tab-name = 'Earth'.
node_tab-tlevel = '01'.
node_tab-nlength = '5'.
node_tab-color = '4'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 3.
append node_tab.
clear node_tab.
node_tab-type = 'P'.
node_tab-name = 'Europe'.
node_tab-tlevel = '02'.
node_tab-nlength = '6'.
node_tab-color = '1'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 4.
append node_tab.
clear node_tab.
node_tab-type = 'P'.
node_tab-name = 'Germany'.
node_tab-tlevel = '03'.
node_tab-nlength = '7'.
node_tab-color = '4'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 4.
append node_tab.
clear node_tab.
node_tab-type = 'P'.
node_tab-name = 'Berlin'.
node_tab-tlevel = '04'.
node_tab-nlength = '6'.
node_tab-color = '4'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 3.
append node_tab.
clear node_tab.
node_tab-type = 'P'.
node_tab-name = 'Asia'.
node_tab-tlevel = '02'.
node_tab-nlength = '4'.
node_tab-color = '1'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 3.
append node_tab.
clear node_tab.
node_tab-type = 'P'.
node_tab-name = 'India'.
node_tab-tlevel = '03-'.
node_tab-nlength = '5'.
node_tab-color = '1'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 3.
append node_tab.
clear node_tab.
node_tab-type = 'P'.
node_tab-name = 'Bombay'.
node_tab-tlevel = '04-'.
node_tab-nlength = '6'.
node_tab-color = '1'.
node_tab-text = 'Hello'.
node_tab-tlength ='5'.
node_tab-tcolor = 3.
append node_tab.
clear node_tab.
CALL FUNCTION 'RS_TREE_CONSTRUCT'
* EXPORTING
* INSERT_ID = '000000'
* RELATIONSHIP = ' '
* LOG =
TABLES
NODETAB = node_tab
* EXCEPTIONS
* TREE_FAILURE = 1
* ID_NOT_FOUND = 2
* WRONG_RELATIONSHIP = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATA: type_mapping TYPE stree_ctl_type_mapping_tab.
DATA: wa_type TYPE stree_ctl_type_mapping.
CLEAR: type_mapping[].
wa_type-type = 'A'.
wa_type-icon = '@BL@'.
APPEND wa_type TO type_mapping.
*CALL FUNCTION 'RS_TREE_CONTROL_PREPARE'
* EXPORTING
** CONTROL_PATTERN = STREE_CTL_GENERIC
* CONTROL_PATTERN = 'PH'
*
** HIERARCHY_HEADER =
** INITIAL_HEADER_WIDTH =
** LIST_ITEM_HEADER =
* MULTIPLE_SELECTION = 'X'
** ITEM_SELECTION = STREE_FALSE
** SUPPRESS_NODE_ICON = STREE_FALSE
** SUPPRESS_FOLDER_ICON = STREE_FALSE
** CALLBACK_PROGRAM =
** CALLBACK_ITEM_DISPLAY =
** COLOR_MAPPING =
* TYPE_MAPPING = type_mapping
** IMPORTING
** SUBSCREEN_PROGRAM =
** SUBSCREEN_DYNNR =
** EXCEPTIONS
** NOT_AVAILABLE = 1
** OTHERS = 2
* .
*IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*
*CALL FUNCTION 'RS_TREE_SET_CURRENT_LAYOUT'
** EXPORTING
** CURSOR_COLUMN = 3
** CURSOR_LINE = 2
** FIRST_NODE = 1
** FIRST_NODE_TYPE = ' '
** LIST_COLUMN = 1
** LIST_LINE = 1
** LAYOUT_MODE = STREE_LAYOUT_NORMAL
** IMPORTING
** INCONSISTENT_LAYOUT =
** TABLES
** LAYOUT =
* .
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
* CALLBACK_PROGRAM =
* CALLBACK_USER_COMMAND =
* CALLBACK_TEXT_DISPLAY =
* CALLBACK_MOREINFO_DISPLAY =
* CALLBACK_COLOR_DISPLAY =
* CALLBACK_TOP_OF_PAGE =
* CALLBACK_GUI_STATUS =
* CALLBACK_CONTEXT_MENU =
* STATUS = 'IMPLICIT'
* CHECK_DUPLICATE_NAME = '1'
* COLOR_OF_NODE = '4'
* COLOR_OF_MARK = '3'
* COLOR_OF_LINK = '1'
* COLOR_OF_MATCH = '5'
* LOWER_CASE_SENSITIVE = ' '
* MODIFICATION_LOG = ' '
* NODE_LENGTH = 30
* TEXT_LENGTH = 75
* TEXT_LENGTH1 = 0
* TEXT_LENGTH2 = 0
* RETURN_MARKED_SUBTREE = ' '
* SCREEN_START_COLUMN = 0
* SCREEN_START_LINE = 0
* SCREEN_END_COLUMN = 0
* SCREEN_END_LINE = 0
* SUPPRESS_NODE_OUTPUT = ' '
* LAYOUT_MODE = ' '
* USE_CONTROL = STREE_USE_LIST
USE_CONTROL = 'L'.
* IMPORTING
* F15 =
**********end of program . <b>A list of other function modules that can also be used to construct tree reports:</b>
SEUT, Hierarchy framework
RS_TREE_ADD_NODE Insert nodes
RS_TREE_AUTOMATIC_REFRESH
RS_TREE_COMPRESS Hide subtree(s)
RS_TREE_CONSTRUCT Construct new hierarchy or insert subtree
RS_TREE_CONTROL_PREPARE
RS_TREE_CREATE Create hierarchy
RS_TREE_DELETE_NODE Delete node with associated sub-tree
RS_TREE_EXPAND Expand subtree
RS_TREE_GET_CURRENT_LAYOUT Get layout information for displayed hierarchy
RS_TREE_GET_CURRENT_NODE Get node at which cursor is positioned
RS_TREE_GET_CURRENT_ROOT Get current root node
RS_TREE_GET_CURRENT_TREE Get structure information for displayed hierarchy
RS_TREE_GET_INPUT Get entires from input fields
RS_TREE_GET_MARKED_NODES Get selected nodes
RS_TREE_GET_MODIFICATION_LOG Get change log for hierarchy
RS_TREE_GET_NODE Get nodes for specified ID
RS_TREE_GET_NODE_BY_NAME Get node for specified node name
RS_TREE_GET_PREDECESSOR Get preceding node
RS_TREE_GET_SEARCHSTRING Get last search strinng
RS_TREE_LIST Simulate hierarchy or subtree display
RS_TREE_LIST_DISPLAY Display hierarchy
RS_TREE_LIST_DISPLAY Display hierarchy
RS_TREE_MODIFY_NODE
RS_TREE_MOVE Reassign node with subtree
RS_TREE_POP Get hierarchy from the stack and restore
RS_TREE_PUSH Place hierarchy on the stack
RS_TREE_RESET_LOCK Deselect node
RS_TREE_SET_CURRENT_LAYOUT Set layout with marked cursor position
RS_TREE_SET_CURRENT_TREE Set other hierarchy
RS_TREE_SET_LOCK Select node
RS_TREE_SET_NODE Change Nodes
RS_TREE_SET_SCROLL_POS Position node at the beginning of the page
RS_TREE_SLEEP
RS_TREE_SORT_CHILDREN
‎2006 Dec 06 2:37 PM
Here is one using classes.
Create a screen 9000 with a custom control named TREE. And in PBO add a new module init_9000.
REPORT zkb_tree_example.
TYPES: BEGIN OF t_sbook,
customid TYPE sbook-customid,
fldate TYPE sbook-fldate,
bookid TYPE sbook-bookid,
END OF t_sbook.
DATA: i_sbook TYPE TABLE OF t_sbook,
w_sbook TYPE t_sbook.
SELECT-OPTIONS: s_custid FOR w_sbook-customid.
DATA: o_custom_container TYPE REF TO cl_gui_custom_container,
o_tree TYPE REF TO cl_gui_simple_tree.
TYPES: t_node_table LIKE TABLE OF trstree.
DATA: i_node TYPE t_node_table,
w_node TYPE LINE OF t_node_table.
START-OF-SELECTION.
CALL SCREEN 9000.
&----
*& Module status_9000 OUTPUT
&----
text
----
MODULE status_9000 OUTPUT.
SET PF-STATUS '9000'.
ENDMODULE. " status_9000 OUTPUT
&----
*& Module user_command_9000 INPUT
&----
text
----
MODULE user_command_9000 INPUT.
CASE sy-ucomm .
WHEN 'BACK' OR 'EXIT'.
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. " user_command_9000 INPUT
&----
*& Module init_9000 OUTPUT
&----
text
----
MODULE init_9000 OUTPUT.
DATA: lw_sbook TYPE t_sbook.
SELECT customid fldate bookid FROM sbook
INTO TABLE i_sbook WHERE customid IN s_custid.
SORT i_sbook BY customid ASCENDING.
CREATE OBJECT o_custom_container
EXPORTING
container_name = 'TREE'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE 'Error Creating Container' TYPE 'E'.
ENDIF.
CREATE OBJECT o_tree
EXPORTING
parent = o_custom_container
node_selection_mode =
cl_gui_simple_tree=>node_sel_mode_single
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
failed = 4
illegal_node_selection_mode = 5.
IF sy-subrc <> 0.
MESSAGE 'Error Creating Tree' TYPE 'E'.
ENDIF.
Add ROOT Folder
CLEAR w_node.
w_node-node_key = 'ROOT'.
w_node-text = 'Root'.
w_node-isfolder = 'X'.
APPEND w_node TO i_node.
CLEAR lw_sbook .
LOOP AT i_sbook INTO w_sbook.
IF lw_sbook-customid NE w_sbook-customid.
lw_sbook-customid = w_sbook-customid.
CLEAR w_node.
w_node-node_key = w_sbook-customid.
w_node-text = w_sbook-customid.
w_node-relatkey = 'ROOT'.
w_node-relatship = cl_gui_simple_tree=>relat_last_child.
w_node-isfolder = 'X'.
APPEND w_node TO i_node.
ENDIF.
CLEAR w_node.
w_node-node_key = w_sbook-bookid.
w_node-relatkey = w_sbook-customid.
w_node-relatship = cl_gui_simple_tree=>relat_last_child.
w_node-text = w_sbook-bookid.
APPEND w_node TO i_node.
ENDLOOP.
CALL METHOD o_tree->add_nodes
EXPORTING
table_structure_name = 'TRSTREE'
node_table = i_node
EXCEPTIONS
failed = 1
error_in_node_table = 2
dp_error = 3
table_structure_name_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE 'Error Adding Node to Tree' TYPE 'E'.
ENDIF.
Expand tree
CALL METHOD o_tree->expand_root_nodes
EXPORTING
level_count = 2
expand_subtree = ' '
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE 'Error Expanding Tree' TYPE 'E'.
ENDIF.
ENDMODULE. " init_9000 OUTPUT
Regards
Kathirvel