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 add child node to a simple tree

Former Member
0 Kudos

Hi friends,

I m using CL_GUI_SIMPLE_TREE to build a tree ,

I have created nodes using method ADD_NODES.

Now i have to add child node to that node ,can any one tell me is there any method to perform tht.

Thanks in advance.

Kalpanashri Rajendran.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Refer to the sap example SAPSIMPLE_TREE_CONTROL_DEMO.Here you will get the entire technique of adding a node.

4 REPLIES 4

Former Member
0 Kudos

Refer to the sap example SAPSIMPLE_TREE_CONTROL_DEMO.Here you will get the entire technique of adding a node.

Former Member
0 Kudos

Hi

METHOD build_node_table.

  • CHANGING p_node_table TYPE t_node_table_type.

DATA: lw_node_table TYPE trstree,

lv_old_rqowner TYPE tsp01-rqowner,

lv_text TYPE string.

SORT i_tsp01 BY rqowner rqident rqcretime ASCENDING.

  • Add ROOT Folder

CLEAR lw_node_table.

lw_node_table-node_key = 'ROOT'.

lw_node_table-text = 'Spool Details'.

lw_node_table-isfolder = 'X'.

lw_node_table-n_image = 'ICON_OUTPUT_REQUEST'.

APPEND lw_node_table TO p_node_table.

  • Add other sub nodes and child items

CLEAR lv_old_rqowner.

LOOP AT i_tsp01 INTO w_tsp01.

IF lv_old_rqowner <> w_tsp01-rqowner.

lv_old_rqowner = w_tsp01-rqowner.

lw_node_table-node_key = w_tsp01-rqowner.

lw_node_table-relatkey = 'ROOT'.

lw_node_table-relatship = cl_gui_simple_tree=>relat_last_child.

lw_node_table-text = w_tsp01-rqowner.

lw_node_table-isfolder = 'X'.

lw_node_table-n_image = 'ICON_SYSTEM_USER_MENU'.

APPEND lw_node_table TO p_node_table.

ENDIF.

  • Adding Child Nodes

CLEAR lv_text.

lv_text = w_tsp01-rqident.

lw_node_table-node_key = w_tsp01-rqident.

lw_node_table-relatkey = w_tsp01-rqowner.

lw_node_table-relatship = cl_gui_simple_tree=>relat_last_child.

lw_node_table-text = lv_text.

lw_node_table-isfolder = ' '.

lw_node_table-n_image = 'ICON_SPOOL_REQUEST'.

APPEND lw_node_table TO p_node_table.

ENDLOOP. " LOOP AT i_tsp01 INTO w_tsp01.

Sample programs are

SAPTLIST_TREE_CONTROL_DEMO

SAPCOLUMN_TREE_CONTROL_DEMO

SAPSIMPLE_TREE_CONTROL_DEMO

Regards

Kathirvel

ENDMETHOD. "build_node_table

Former Member
0 Kudos

See this subroutine

FORM CREATE_NODE_RIGHT .

DATA: NODE LIKE MTREESNODE.

  • node table of the left tree

CLEAR NODE.

NODE-NODE_KEY = 'Root2'.

NODE-ISFOLDER = 'X'.

NODE-TEXT = 'Friends'.

NODE-DRAGDROPID = ' '.

APPEND NODE TO NODE_ITAB2.

CLEAR NODE.

NODE-NODE_KEY = 'Child3'.

NODE-RELATKEY = 'Root2'.

NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

NODE-TEXT = 'Jose'.

NODE-DRAGDROPID = 1.

APPEND NODE TO NODE_ITAB2.

CLEAR NODE.

NODE-NODE_KEY = 'child4'.

NODE-RELATKEY = 'Root2'.

NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

NODE-TEXT = 'Biju'.

NODE-DRAGDROPID = 1.

APPEND NODE TO NODE_ITAB2.

CLEAR NODE.

NODE-NODE_KEY = 'Root5'.

NODE-RELATKEY = 'Root2'.

NODE-ISFOLDER = 'X'.

NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

NODE-TEXT = 'Friends10'.

NODE-DRAGDROPID = ' '.

APPEND NODE TO NODE_ITAB2.

CLEAR NODE.

NODE-NODE_KEY = 'Root6'.

NODE-RELATKEY = 'Root5'.

NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

NODE-TEXT = 'Friends101'.

NODE-DRAGDROPID = ' '.

APPEND NODE TO NODE_ITAB2.

ENDFORM. " create_node_right

It created a tree like

**********************

Friends

-


Jose

-


Biju

-


Friends10

-


Friends101

Former Member
0 Kudos

firstly u need to create a node table as follows ...

LWA_NODE-NODE_KEY = 'N001' .

LWA_NODE-ISFOLDER = 'X' .

LWA_NODE-TEXT = 'VISTEX DEPARTMENTS' .

APPEND LWA_NODE TO GT_NODE .

LWA_NODE-NODE_KEY = 'N0011' .

LWA_NODE-RELATKEY = 'N001' .

LWA_NODE-RELATSHIP = cl_gui_simple_tree=>relat_first_child.

LWA_NODE-ISFOLDER = 'X' .

LWA_NODE-TEXT = 'IT DEPARTMENT' .

APPEND LWA_NODE TO GT_NODE .

LWA_NODE-NODE_KEY = 'N00111' .

LWA_NODE-RELATKEY = 'N0011' .

LWA_NODE-RELATSHIP = cl_gui_simple_tree=>relat_FIRST_child.

LWA_NODE-ISFOLDER = ' ' .

LWA_NODE-TEXT = 'SWAPNIL' .

APPEND LWA_NODE TO GT_NODE .

LWA_NODE-NODE_KEY = 'N0012' .

LWA_NODE-RELATKEY = 'N0011' .

LWA_NODE-RELATSHIP = cl_gui_simple_tree=>relat_NEXT_SIBLING.

LWA_NODE-ISFOLDER = 'X' .

LWA_NODE-TEXT = 'FINANCE DEPARTMENT' .

APPEND LWA_NODE TO GT_NODE .

LWA_NODE-NODE_KEY = 'N00121' .

LWA_NODE-RELATKEY = 'N0012' .

LWA_NODE-RELATSHIP = cl_gui_simple_tree=>relat_LAST_child.

LWA_NODE-ISFOLDER = ' ' .

LWA_NODE-TEXT = 'KAMLESH' .

APPEND LWA_NODE TO GT_NODE .

this will hav the foll structure .

vistex department(folder)

-it department(folder)

- swapnil(node)

-finance department(folder)

- kamlesh(node)

now all u need to do is call the foll method .

CALL METHOD ref_simple_tree->add_nodes

EXPORTING

table_structure_name = 'MTREESNODE' "structure of ur node table

node_table = GT_NODE[] " node table

EXCEPTIONS

ERROR_IN_NODE_TABLE = 1

FAILED = 2

DP_ERROR = 3

TABLE_STRUCTURE_NAME_NOT_FOUND = 4

others = 5

this should do it

if helpful plz reward points ....