07-05-2007 1:52 PM
Hi Experts,
I´m cracking my skull open to figure out how to make a tree like in SE80.
My problem is i´d like to make a splitter in wich the left side there is a tree menu, and in the right side is a display with some tabs, but it look like it is impossible to call subscreens with subscreens on them in the right side....
i´d like to know if there is some workround this ... i know it is possible because this style of design exists in se80, it appears in se80 when you open some screen details in a program.
help-me sap experts you guys/gals are my only hope ...
07-05-2007 2:04 PM
Hello,
There is a sample on tcode abapdocu.
Or check the following code:
REPORT yarboles MESSAGE-ID TREE_CONTROL_MSG.
include yarbolestop.
include ymanejoeventos.
include yarbolespbo.
include yarbolespai.
include yarbolesfun.
START-OF-SELECTION.
create the application object
this object is needed to handle the ABAP Objects Events of
Controls
CREATE OBJECT g_evento.
SET SCREEN 100.
&----
*& Include YARBOLESTOP
&----
CLASS lcl_evento DEFINITION DEFERRED.
CLASS cl_gui_cfw DEFINITION LOAD.
TYPES: node_table_type LIKE STANDARD TABLE OF mtreesnode
WITH DEFAULT KEY.
CAUTION: MTREESNODE is the name of the node structure which must
be defined by the programmer. DO NOT USE MTREESNODE!
DATA: g_evento TYPE REF TO lcl_evento,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_gui_simple_tree,
g_ok_code TYPE sy-ucomm.
Fields on Dynpro 100
DATA: g_event(30),
g_node_key TYPE tv_nodekey,
g_ctx_fcode TYPE sy-ucomm.
&----
*& Include YMANEJOEVENTOS
&----
----
*
----
CLASS LCL_EVENTO DEFINITION.
CLASS lcl_evento DEFINITION.
PUBLIC SECTION.
METHODS:
handle_node_double_click
FOR EVENT node_double_click
OF cl_gui_simple_tree
IMPORTING node_key,
handle_expand_no_children
FOR EVENT expand_no_children
OF cl_gui_simple_tree
IMPORTING node_key,
handle_node_context_menu
FOR EVENT node_context_menu_request
OF cl_gui_simple_tree
IMPORTING node_key menu,
handle_node_context_menu_sel
FOR EVENT node_context_menu_select
OF cl_gui_simple_tree
IMPORTING node_key fcode..
ENDCLASS. "LCL_EVENTO DEFINITION
----
CLASS LCL_EVENTO IMPLEMENTATION
----
*
----
CLASS lcl_evento IMPLEMENTATION.
METHOD handle_node_double_click.
" this method handles the node double click event of the tree
" control instance
" show the key of the double clicked node in a dynpro field
g_event = 'NODE_DOUBLE_CLICK'.
g_node_key = node_key.
ENDMETHOD. "HANDLE_NODE_DOUBLE_CLICK
METHOD handle_expand_no_children.
" this method handles the expand no children event of the tree
" control instance
DATA: node_table TYPE node_table_type,
node TYPE mtreesnode.
" show the key of the double clicked node in a dynpro field
g_event = 'EXPAND_NO_CHILDREN'.
g_node_key = node_key.
IF node_key = 'Child1'. "#EC NOTEXT
add two nodes to the tree control (the children of 'Child1')
Node with key 'New1'
CLEAR node.
node-node_key = 'New1'. "#EC NOTEXT
node-relatkey = 'Child1'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-isfolder = ' '.
node-text = 'New1'.
APPEND node TO node_table.
Node with key 'New2'
CLEAR node.
node-node_key = 'New2'. "#EC NOTEXT
node-relatkey = 'Child1'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-n_image = '@10@'.
node-expander = ' '.
node-text = 'New2'.
APPEND node TO node_table.
CALL METHOD g_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = node_table
EXCEPTIONS
failed = 1
error_in_node_table = 2
dp_error = 3
table_structure_name_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE a000.
ENDIF.
ENDIF.
ENDMETHOD. "HANDLE_EXPAND_NO_CHILDREN
METHOD handle_node_context_menu .
" Maneja menu de contexto
" show the key of the double clicked node in a dynpro field
g_event = 'CONTEXT_MENU'.
g_node_key = node_key.
Construye el menu
DATA: text TYPE gui_text.
" first entry in context menu
text = 'FUNCION 1'. "#EC NOTEXT
CONCATENATE text node_key INTO text SEPARATED BY ' '.
CALL METHOD menu->add_function
EXPORTING
text = text
fcode = 'FUNC1'. "#EC NOTEXT
" second entry in context menu
CALL METHOD menu->add_function
EXPORTING
text = 'FUNCION 2' "#EC NOTEXT
fcode = 'FUNC2'. "#EC NOTEXT
ENDMETHOD. "HANDLE_NODE_CONTEXT_MENU
METHOD handle_node_context_menu_sel.
" this method handles the node context select event of the tree
" control instance
" write chosen FCODE in dynpro field
g_ctx_fcode = fcode.
ENDMETHOD. "handle_node_context_menu_sel
ENDCLASS. "LCL_EVENTO IMPLEMENTATION
&----
*& Include YARBOLESPBO
&----
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
module STATUS_0100 output.
SET PF-STATUS 'MAIN'.
IF G_TREE IS INITIAL.
" The Tree Control has not been created yet.
" Create a Tree Control and insert nodes into it.
PERFORM CREATE_AND_INIT_TREE.
ENDIF.
endmodule. " STATUS_0100 OUTPUT
&----
*& Include YARBOLESPAI
&----
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
module USER_COMMAND_0100 input.
CASE SY-UCOMM.
WHEN 'BACK'.
IF NOT G_CUSTOM_CONTAINER IS INITIAL.
" destroy tree container (detroys contained tree control, too)
CALL METHOD G_CUSTOM_CONTAINER->FREE
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
IF SY-SUBRC <> 0.
MESSAGE A000.
ENDIF.
CLEAR G_CUSTOM_CONTAINER.
CLEAR G_TREE.
ENDIF.
LEAVE PROGRAM.
ENDCASE.
CLEAR G_OK_CODE.
endmodule. " USER_COMMAND_0100 INPUT
&----
*& Include YARBOLESFUN
&----
&----
*& Form CREATE_AND_INIT_TREE
&----
text
----
--> p1 text
<-- p2 text
----
FORM create_and_init_tree .
DATA: node_table TYPE node_table_type,
events TYPE cntl_simple_events,
event TYPE cntl_simple_event.
create a container for the tree control
CREATE OBJECT g_custom_container
EXPORTING
container_name = 'CONTENEDOR_ARBOL'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE a000.
ENDIF.
create a tree control
CREATE OBJECT g_tree
EXPORTING
parent = g_custom_container
" single node selection is used
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 a000.
ENDIF.
define the events which will be passed to the backend
" node double click
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = 'X'. " process PAI if event occurs
APPEND event TO events.
" expand no children
event-eventid = cl_gui_simple_tree=>eventid_expand_no_children.
event-appl_event = 'X'.
APPEND event TO events.
Sacar el Menu de contexto
event-eventid = cl_gui_simple_tree=>eventid_node_context_menu_req.
event-appl_event = ' '.
APPEND event TO events.
" process PAI if context menu select event occurs
CALL METHOD g_tree->set_ctx_menu_select_event_appl
EXPORTING
appl_event = 'X'.
CALL METHOD g_tree->set_registered_events
EXPORTING
events = events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE a000.
ENDIF.
assign event handlers in the application class to each desired event
SET HANDLER g_evento->handle_node_double_click FOR g_tree.
SET HANDLER g_evento->handle_expand_no_children FOR g_tree.
SET HANDLER g_evento->handle_node_context_menu FOR g_tree.
SET HANDLER g_evento->handle_node_context_menu_sel FOR g_tree.
add some nodes to the tree control
NOTE: the tree control does not store data at the backend. If an
application wants to access tree data later, it must store the
tree data itself.
PERFORM build_node_table USING node_table.
node_table_structure_name = 'MTREESNODE'
A programmer using the tree control must create a structure in the
dictionary. This structure must include the structure TREEV_NODE
and must contain a character field with the name 'TEXT'.
CALL METHOD g_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = node_table
EXCEPTIONS
failed = 1
error_in_node_table = 2
dp_error = 3
table_structure_name_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE a000.
ENDIF.
ENDFORM. " CREATE_AND_INIT_TREE
&----
*& Form BUILD_NODE_TABLE
&----
text
----
-->P_NODE_TABLE text
----
FORM build_node_table USING node_table TYPE node_table_type.
DATA: node LIKE mtreesnode.
Build the node table.
Caution: The nodes are inserted into the tree according to the order
in which they occur in the table. In consequence, a node must not
occur in the node table before its parent node.
Node with key 'Root'
node-node_key = 'Root'. "#EC NOTEXT
" Key of the node
CLEAR node-relatkey. " Special case: A root node has no parent
CLEAR node-relatship. " node.
node-hidden = ' '. " The node is visible,
node-disabled = ' '. " selectable,
node-isfolder = 'X'. " a folder.
CLEAR node-n_image. " Folder-/ Leaf-Symbol in state "closed":
" use default.
CLEAR node-exp_image. " Folder-/ Leaf-Symbol in state "open":
" use default
CLEAR node-expander. " see below.
node-text = 'Root'.
APPEND node TO node_table.
Node with key 'Child1'
node-node_key = 'Child1'. "#EC NOTEXT
" Key of the node
" Node is inserted as child of the node with key 'Root'.
node-relatkey = 'Root'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-hidden = ' '.
node-disabled = ' '.
node-isfolder = 'X'.
CLEAR node-n_image.
CLEAR node-exp_image.
node-expander = 'X'. " The node is marked with a '+', although
" it has no children. When the user clicks on the
" + to open the node, the event
" expand_no_children is fired. The programmer can
" add the children of the
" node within the event handler of the
" expand_no_children event
" (see method handle_expand_no_children
" of class lcl_application)
node-text = 'Child1'.
node-style = cl_gui_simple_tree=>style_emphasized_positive.
APPEND node TO node_table.
ENDFORM. " BUILD_NODE_TABLE
Hope this helps!!
Dont forget to reward
Gabriel
09-02-2014 11:06 AM
Hi!
I have a quick question.
Do you have any idea why in the code it is written "DO NOT USE MTREESNODE"?
I am about to use it
Thanks.
KR,
Bruno
09-02-2014 12:21 PM
No idea Bruno, it was a one time deal for me. I've not used it since that time.
Regards !
07-05-2007 2:30 PM
hi friend,
check out the demo programs in sap..
all types of TREE programs are available in the package 'SEU_TREE_MODEL'...
kindly g thru it....
thankx
jaideep
if useful reward points...
07-24-2007 7:48 PM
The demos helped a lot the development of the menu tree.... and it´s done !