Posted: Sat Sep 15, 2007 8:22 pm Post subject: Company/Plant/Storage Hierarchy cl_gui_list_tree
Company/Plant/Storage Location Hierarchy.
This program displays the hierarchy in a list tree. Additional custom toolbar allow expand / collapse the tree.
Note. SAP Toolbar requires the Microsoft Common Control. You therefore need to install Microsoft Internet Explorer Version 4.0.
Used objects and methods:
cl_gui_splitter_container
cl_gui_container
cl_gui_toolbar
cl_gui_list_tree
handling application events (with triggering PAI)
context menus
GUI Status 'MAIN' has one function: BACK of Type ' ' (Normal application function), assigned to standard button: .
Screen 100 has only field g_ok_code for handling user command:
PROCESS BEFORE OUTPUT.
MODULE PBO_100.
PROCESS AFTER INPUT.
MODULE PAI_100.
*---------------------------------------------------------------------*
* Data declaration
*---------------------------------------------------------------------*
constants c_width type i value 400.
class lcl_application definition deferred.
class cl_gui_cfw definition load.
types: item_table_type like standard table of mtreeitm
with default key.
data: g_application type ref to lcl_application,
splitter_h type ref to cl_gui_splitter_container,
g_gui_container type ref to cl_gui_container,
g_gui_container_r type ref to cl_gui_container,
g_tree type ref to cl_gui_list_tree,
*------node key = CCCCPPPPSSSS
* \--/ Company t001-bukrs
* \--/ Plant t001k-bwkey
* \--/ Storage Location t001l-lgort
g_cntl type ref to cl_gui_toolbar,
g_ok_code type sy-ucomm. "screen 100 field (only)
*---------------------------------------------------------------------*
* CLASS LCL_APPLICATION DEFINITION
*---------------------------------------------------------------------*
class lcl_application definition.
public section.
*--- methods for nodes and items of tree
methods:
handle_node_double_click
for event node_double_click
of cl_gui_list_tree
importing node_key,
handle_expand_no_children
for event expand_no_children
of cl_gui_list_tree
importing node_key,
handle_item_double_click
for event item_double_click
of cl_gui_list_tree
importing node_key item_name,
handle_button_click
for event button_click
of cl_gui_list_tree
importing node_key item_name,
handle_link_click
for event link_click
of cl_gui_list_tree
importing node_key item_name,
handle_checkbox_change
for event checkbox_change
of cl_gui_list_tree
importing node_key item_name checked,
*--- methods for sap toolbar
handle_pushbutton_click
for event function_selected
of cl_gui_toolbar
importing fcode,
*--- methods for context menus for nodes and items of tree
handle_node_context_menu_req
for event node_context_menu_request
of cl_gui_list_tree
importing node_key menu,
handle_node_context_menu_sel
for event node_context_menu_select
of cl_gui_list_tree
importing node_key fcode,
handle_dft_context_menu_req
for event default_context_menu_request
of cl_gui_list_tree
importing menu,
handle_dft_context_menu_sel
for event default_context_menu_select
of cl_gui_list_tree
importing fcode.
endclass.
*---------------------------------------------------------------------*
* CLASS LCL_APPLICATION IMPLEMENTATION
*---------------------------------------------------------------------*
class lcl_application implementation.
method handle_node_double_click.
data: text1 type string,
text2 type string,
text3 type string.
if node_key(4) <> 'Root'.
concatenate 'Company:' node_key(4) into text1 separated by space.
endif.
if node_key+4(4) <> space.
concatenate 'Plant:' node_key+4(4) into text2 separated by space.
endif.
if node_key+8(4) <> space.
concatenate 'Storage Location:' node_key+8(4) into text3
separated by space.
endif.
message i398(00) with 'Handle' text1 text2 text3.
endmethod.
method handle_item_double_click.
data: text0 type string,
text1 type string,
text2 type string,
text3 type string.
case item_name.
when '1'. text0 = 'Handle code for'.
when '2'. text0 = 'Handle name for'.
when '3'. text0 = 'Handle city for'.
when others. text0 = 'Handle'.
endcase.
if node_key(4) <> 'Root'.
concatenate 'Company:' node_key(4) into text1 separated by space.
endif.
if node_key+4(4) <> space.
concatenate 'Plant:' node_key+4(4) into text2 separated by space.
endif.
if node_key+8(4) <> space.
concatenate 'Storage Location:' node_key+8(4) into text3
separated by space.
endif.
message i398(00) with text0 text1 text2 text3.
endmethod.
method handle_link_click.
endmethod.
method handle_button_click.
endmethod.
method handle_checkbox_change.
endmethod.
method handle_expand_no_children.
data: node_table type treev_ntab,
node type treev_node,
item_table type item_table_type,
item type mtreeitm,
wa_t001l type t001l.
select lgort lgobe from t001l
into (wa_t001l-lgort, wa_t001l-lgobe)
where werks = node_key+4.
method handle_pushbutton_click.
data level type i.
case fcode.
when 'COMPANY'. level = 0.
when 'PLANT'. level = 1.
when 'STORAGE'. level = 2.
when 'COLLAPSE'. level = -1.
endcase.
call method g_tree->collapse_all_nodes.
if level >= 0.
call method g_tree->expand_node exporting node_key = 'Root'
level_count = level
expand_subtree = space.
endif.
endmethod.
method handle_node_context_menu_req.
data: text type gui_text.
if node_key(4) <> 'Root'.
concatenate 'Company:' node_key(4) into text separated by space.
call method menu->add_function
exporting text = text
fcode = 'COMPANY'.
endif.
if node_key+4(4) <> space.
concatenate 'Plant:' node_key+4(4) into text separated by space.
call method menu->add_function
exporting text = text
fcode = 'PLANT'.
endif.
if node_key+8(4) <> space.
concatenate 'Storage Location:' node_key+8(4) into text
separated by space.
call method menu->add_function
exporting text = text
fcode = 'STORAGE'.
endif.
text = 'About...'.
call method menu->add_function
exporting text = text
fcode = 'ABOUT'.
endmethod.
method handle_node_context_menu_sel.
data text type string.
case fcode.
when 'COMPANY'.
concatenate 'Do something for company' node_key(4)
into text separated by space.
when 'PLANT'.
concatenate 'Do something for plant' node_key+4(4)
into text separated by space.
when 'STORAGE'.
concatenate 'Do something for storage location' node_key+8(4)
into text separated by space.
when 'ABOUT'. text = 'Object Oriented Abap Demo'.
endcase.
message i398(00) with text.
endmethod.
method handle_dft_context_menu_req.
data: text type gui_text.
text = 'About...'.
call method menu->add_function
exporting text = text
fcode = 'ABOUT'.
text = 'Exit...'.
call method menu->add_function
exporting text = text
fcode = 'BYE'.
endmethod.
method handle_dft_context_menu_sel.
case fcode.
when 'ABOUT'. message i398(00) with 'Object Oriented Abap Demo'.
when 'BYE'.
perform finish_program.
leave program.
endcase.
endmethod.
endclass.
*---------------------------------------------------------------------*
* MODULE PBO_100 OUTPUT *
*---------------------------------------------------------------------*
module pbo_100 output.
set pf-status 'MAIN'.
if g_tree is initial.
perform create_and_init_tree.
endif.
endmodule. " PBO_0100 OUTPUT
*---------------------------------------------------------------------*
* MODULE PAI_100 INPUT *
*---------------------------------------------------------------------*
module pai_100 input.
data: return_code type i.
* CL_GUI_CFW=>DISPATCH must be called if events are registered
* that trigger PAI
* this method calls the event handler method of an event
call method cl_gui_cfw=>dispatch
importing return_code = return_code.
if return_code <> cl_gui_cfw=>rc_noevent.
" a control event occured => exit PAI
clear g_ok_code.
exit.
endif.
case g_ok_code.
when 'BACK'. " Finish program
perform finish_program.
leave program.
endcase.
*---------------------------------------------------------------------*
* Form CREATE_AND_INIT_TREE
*---------------------------------------------------------------------*
form create_and_init_tree.
data: node_table type treev_ntab,
item_table type item_table_type,
events type cntl_simple_events,
event type cntl_simple_event.
* assign event handlers in the application class to each desired event
set handler g_application->handle_node_double_click for g_tree.
set handler g_application->handle_item_double_click for g_tree.
set handler g_application->handle_expand_no_children for g_tree.
set handler g_application->handle_link_click for g_tree.
set handler g_application->handle_button_click for g_tree.
set handler g_application->handle_checkbox_change for g_tree.
set handler g_application->handle_pushbutton_click for g_cntl.
set handler g_application->handle_node_context_menu_req for g_tree.
set handler g_application->handle_node_context_menu_sel for g_tree.
set handler g_application->handle_dft_context_menu_req for g_tree.
set handler g_application->handle_dft_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_and_item_table using node_table item_table.
*---------------------------------------------------------------------*
* Form build_node_and_item_table
*---------------------------------------------------------------------*
form build_node_and_item_table
using
node_table type treev_ntab
item_table type item_table_type.
data: node type treev_node,
item type mtreeitm,
wa_t001 like t001,
wa_t001l like t001l,
wa_t001w like t001w,
wa_t001k like t001k.
* 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
* must not occur in the node table before its parent node.
select bwkey bukrs from t001k
into (wa_t001k-bwkey, wa_t001k-bukrs)
where bukrs = wa_t001-bukrs.
clear node.
node-node_key = wa_t001-bukrs.
node-node_key+4 = wa_t001k-bwkey.
node-relatkey = wa_t001-bukrs.
node-relatship = cl_gui_list_tree=>relat_last_child.
node-isfolder = 'X'.
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_nc is
" fired. The programmer can
" add the children of the
" node within the event handler of the expand_nc
" event (see callback handle_expand_nc).
append node to node_table.
select single name1 from t001w into wa_t001w-name1
where werks = wa_t001k-bwkey.
*---------------------------------------------------------------------*
* Form finish_program
*----------------------------------------------------------------------*
form finish_program.
if not g_gui_container is initial.
" destroy tree container (detroys contained tree control, too)
call method g_gui_container->free
exceptions
cntl_system_error = 1
cntl_error = 2.
if sy-subrc <> 0.
message a000.
endif.
clear: g_gui_container, g_tree.
endif.
if not g_gui_container_r is initial.
" destroy right container (detroys contained toolbar, too)
call method g_gui_container_r->free
exceptions
cntl_system_error = 1
cntl_error = 2.
if sy-subrc <> 0.
message a000.
endif.
clear: g_gui_container_r, g_cntl.
endif.
endform. " finish_program
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Start of selection
*---------------------------------------------------------------------*
start-of-selection.
* create the application object
* this object is needed to handle the ABAP Objects Events of
* Controls
create object g_application.
set screen 100.
*---------------------------------------------------------------------*
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.