Posted: Mon Sep 10, 2007 7:56 pm Post subject: TREE Report
Code:
****** CLASS DEFINITION
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
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.
ENDCLASS.
****** CLASS IMPLEMENTATION
CLASS lcl_application 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
READ TABLE itab_data WITH KEY node_key = node_key INTO wa_data.
* You now have the data to do anything you wish
* ….
ENDMETHOD.
METHOD handle_item_double_click.
" this method handles the item double click event of the tree
" control instance. You have variables node_key and item_name
" show the key of the node and the name of the item
" of the double clicked item in a dynpro field
READ TABLE itab_data WITH KEY node_key = node_key INTO wa_data.
* You now have the data to do anything you wish
* ….
ENDMETHOD.
METHOD handle_link_click.
" this method handles the link click event of the tree
" control instance
" show the key of the node and the name of the item
" of the clicked link in a dynpro field
g_node_key = node_key.
g_item_name = item_name.
ENDMETHOD.
METHOD handle_button_click.
" this method handles the button click event of the tree
" control instance
" show the key of the node and the name of the item
" of the clicked button in a dynpro field
g_node_key = node_key.
g_item_name = item_name.
ENDMETHOD.
METHOD handle_checkbox_change.
" this method handles the checkbox_change event of the tree
" control instance
" show the key of the node and the name of the item
" of the clicked checkbox in a dynpro field
g_node_key = node_key.
g_item_name = item_name.
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.
* show the key of the expanded node in a dynpro field
g_node_key = node_key.
IF node_key = 'Child2'. "#EC NOTEXT
* add the children for node with key 'Child2'
* Node with key 'New3'
CLEAR node.
node-node_key = 'New3'. "#EC NOTEXT
node-relatkey = 'Child2'.
node-relatship = cl_gui_list_tree=>relat_last_child.
APPEND node TO node_table.
****** DATA DEFINITIONS
* Type definitions
types: begin of itab_type,
folder type flag,
node_key type mtreeitm,
relatkey type tv_nodekey,
type like qmel-QMART,
qmnum like qmel-qmnum,
qwrnum like qmel-qwrnum,
end of itab_type.
* Data Definitions
data: okcode like sy-ucomm,
itab_data type itab_type occurs 0,
wa_data type itab_type.
* Tree list definitions
class lcl_application definition deferred.
class cl_gui_cfw definition load.
* CAUTION: MTREEITM is the name of the item structure which must
* be defined by the programmer. DO NOT USE MTREEITM!
types: item_table_type like standard table of mtreeitm
with default key.
****** SELECTION SCREEN
*----------------------------------------------------------------------*
* 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.
CALL SCREEN 2000. "Tree Report
END-OF-SELECTION.
****** SUBROUTINES
*&---------------------------------------------------------------------*
*& Form update_sel_screen_attributes
*&---------------------------------------------------------------------*
FORM update_sel_screen_attributes.
LOOP AT SCREEN.
*&---------------------------------------------------------------------*
*& 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.
* create a container for the tree control
CREATE OBJECT g_custom_container
EXPORTING
" the container is linked to the custom control with the
" name 'TREE_CONTAINER' on the dynpro
container_name = 'TREE_CONTAINER'
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(tree_control_msg).
ENDIF.
* create a list tree control
CREATE OBJECT g_tree
EXPORTING
parent = g_custom_container
node_selection_mode = cl_gui_list_tree=>node_sel_mode_single
item_selection = 'X'
with_headers = ' '
EXCEPTIONS
cntl_system_error = 1
create_error = 2
failed = 3
illegal_node_selection_mode = 4
lifetime_error = 5.
IF sy-subrc <> 0.
MESSAGE a000(tree_control_msg).
ENDIF.
* define the events which will be passed to the backend
" node double click
event-eventid = cl_gui_list_tree=>eventid_node_double_click.
event-appl_event = 'X'. "
APPEND event TO events.
* 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.
* 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.
ENDFORM. " create_and_init_tree
*&---------------------------------------------------------------------*
*& 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.
* Build the node and item table.
LOOP AT itab_data INTO wa_data.
CLEAR node.
ENDFORM. " build_node_and_item_table
*&---------------------------------------------------------------------*
*& Form create_input_table
*&---------------------------------------------------------------------*
FORM create_input_table TABLES p_itab_data LIKE itab_data.
DATA: t_counter(4) TYPE n,
t_parent(4) TYPE c,
t_parent1(4) TYPE c,
t_qmnum LIKE qmel-qmnum,
t_qmnum1 LIKE qmel-qmnum.
t_counter = 1.
CLEAR: t_parent, t_parent1.
IF NOT s_ecr IS INITIAL.
SELECT qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qmnum IN s_ecr AND
qmart = 'C3'.
* Check for ECNs attached to this ECR
SELECT qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qwrnum = qmel-qmnum AND
qmart = 'C4'.
* Check for ECOs attached to this ECN
SELECT qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qwrnum = qmel-qmnum AND
qmart = 'C5'.
t_qmnum = qmel-qmnum.
* Is an ECR attached?
IF NOT qmel-qwrnum IS INITIAL.
SELECT SINGLE qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qmnum = qmel-qwrnum.
IF sy-subrc = 0.
CLEAR: wa_data.
wa_data-folder = 'X'.
wa_data-node_key = t_counter.
wa_data-relatkey = t_parent1.
wa_data-type = qmel-qmart.
wa_data-qmnum = qmel-qmnum.
wa_data-qwrnum = qmel-qwrnum.
APPEND wa_data TO p_itab_data.
ADD 1 TO t_counter.
ENDIF.
ENDIF.
qmel-qmnum = t_qmnum.
* Check for ECOs attached to this ECN
SELECT qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qwrnum = qmel-qmnum AND
qmart = 'C5'.
t_qmnum = qmel-qmnum.
IF NOT qmel-qwrnum IS INITIAL.
* Check for ECNs attached to this ECO
SELECT qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qmnum = qmel-qwrnum AND
qmart = 'C4'.
t_qmnum1 = qmel-qmnum.
IF NOT qmel-qwrnum IS INITIAL.
* Check for ECRs attached to this ECN
SELECT qmnum qmart qwrnum
INTO (qmel-qmnum, qmel-qmart, qmel-qwrnum)
FROM qmel
WHERE qmnum = qmel-qwrnum AND
qmart = 'C3'.
****** PBO Screen 2000
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_2000 output.
SET PF-STATUS 'ZCM_2000'.
SET TITLEBAR 'ZCM_2000'.
endmodule. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*& Module init_data_2000 OUTPUT
*&---------------------------------------------------------------------*
module init_data_2000 output.
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. " init_data_2000 OUTPUT
****** PAI Screen 2000
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
module user_command_2000 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 okcode.
exit.
endif.
case okcode.
when 'RETURN'. " Finish program
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(TREE_CONTROL_MSG).
endif.
clear g_custom_container.
clear g_tree.
endif.
leave to screen 0.
endcase.
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.