11-26-2008 11:07 AM
Hello I have a tree control where I have include the navigation, I know that there is a method
HANDLE_NODE_DOUBLE_CLICK FOR G_TREE
but is there an method for only one click, I want to change my alv grid data when I click on several nodes in my tree control
11-27-2008 4:57 PM
Hello Muhammet
I have re-written my sample report ZUS_SDN_TWO_ALV_GRIDS into ZUS_SDN_TREE_AND_GRID_CONTROL which is now display a tree control together with the ALV grid.
When you analyze this new report you will see that every step of the program logic is as I described in my previous e-mails.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_TWO_ALV_GRIDS
*&
*&---------------------------------------------------------------------*
*& Screen '0100' contains no elements.
*& ok_code -> assigned to GD_OKCODE
*&
*& Flow logic:
* PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
* PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
*&
*&---------------------------------------------------------------------*
*& Thread: single click on tree control navigation
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1143770"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_tree_and_grid_control.
TYPE-POOLS: abap, cntl.
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!
CONSTANTS:
BEGIN OF c_nodekey,
root TYPE tv_nodekey VALUE 'Root', "#EC NOTEXT
child1 TYPE tv_nodekey VALUE 'Child1', "#EC NOTEXT
* child2 type tv_nodekey value 'Child2', "#EC NOTEXT
new1 TYPE tv_nodekey VALUE 'New1', "#EC NOTEXT
new2 TYPE tv_nodekey VALUE 'New2', "#EC NOTEXT
* new3 type tv_nodekey value 'New3', "#EC NOTEXT
* new4 type tv_nodekey value 'New4', "#EC NOTEXT
END OF c_nodekey.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
*
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_cell_left TYPE REF TO cl_gui_container,
go_cell_right TYPE REF TO cl_gui_container,
go_tree TYPE REF TO cl_gui_simple_tree,
go_grid1 TYPE REF TO cl_gui_alv_grid,
** go_grid2 TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_knvv TYPE STANDARD TABLE OF knvv.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
** CALL METHOD go_grid1->set_current_cell_via_id
** EXPORTING
*** IS_ROW_ID =
*** IS_COLUMN_ID =
** is_row_no = es_row_no.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
md_event TYPE string READ-ONLY,
md_node_key TYPE tv_nodekey READ-ONLY.
CLASS-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.
ENDCLASS. "LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION 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
md_event = 'NODE_DOUBLE_CLICK'.
md_node_key = node_key.
" Trigger PAI and set ok-code = 'DETAIL'
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'DETAIL'
* IMPORTING
* rc =
.
MESSAGE md_node_key TYPE 'I'.
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
md_event = 'EXPAND_NO_CHILDREN'.
md_node_key = node_key.
IF node_key = 'Child1'.
* add two nodes to the tree control (the children of 'Child1')
* Node with key 'New1'
CLEAR node.
node-node_key = c_nodekey-new1.
node-relatkey = c_nodekey-child1.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-isfolder = ' '.
node-text = 'New1'(ne1).
APPEND node TO node_table.
* Node with key 'New2'
CLEAR node.
node-node_key = c_nodekey-new2.
node-relatkey = c_nodekey-child1.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-n_image = '@10@'.
node-expander = ' '.
node-text = 'New2'(ne2).
APPEND node TO node_table.
CALL METHOD go_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
ENDCLASS. "LCL_APPLICATION IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1 UP TO 100 ROWS
WHERE bukrs = '1000'.
PERFORM init_controls.
* Display data
gs_layout-grid_title = 'Customers: Sales Areas'.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNVV'
is_layout = gs_layout
CHANGING
it_outtab = gt_knvv
EXCEPTIONS
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.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
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.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid1->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
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.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
* User has pushed button "Display Details"
WHEN 'DETAIL'.
MESSAGE gd_okcode TYPE 'I'.
PERFORM entry_show_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM entry_show_details .
* define local data
DATA:
ld_row TYPE i,
ls_knb1 TYPE knb1.
IF ( gt_knvv IS INITIAL ).
SELECT * FROM knvv INTO TABLE gt_knvv
FOR ALL ENTRIES IN gt_knb1
WHERE kunnr = gt_knb1-kunnr.
ELSE.
REFRESH: gt_knvv.
ENDIF.
ENDFORM. " ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 1
columns = 2
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_left.
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = go_cell_right.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_right
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid1.
PERFORM create_and_init_tree.
ENDFORM. " INIT_CONTROLS
*&---------------------------------------------------------------------*
*& Form CREATE_AND_INIT_TREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_and_init_tree .
DATA: lt_node_table TYPE node_table_type,
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
* create a tree control
CREATE OBJECT go_tree
EXPORTING
parent = go_cell_left
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single " single node selection is used
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
ls_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
** ls_event-appl_event = 'X'. " process PAI if event occurs
" NOTE: Do NOT register as application event !!!!!
APPEND ls_event TO lt_events.
CALL METHOD go_tree->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
** MESSAGE a000.
ENDIF.
SET HANDLER:
lcl_application=>handle_node_double_click FOR go_tree,
lcl_application=>handle_expand_no_children FOR go_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 lt_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 go_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = lt_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
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 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 = c_nodekey-root.
" 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'(roo).
APPEND node TO node_table.
* Node with key 'Child1'
node-node_key = c_nodekey-child1.
" Key of the node
" Node is inserted as child of the node with key 'Root'.
node-relatkey = c_nodekey-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'(ch1).
node-style = cl_gui_simple_tree=>style_emphasized_positive.
APPEND node TO node_table.
ENDFORM. " build_node_table
Regards
Uwe
11-26-2008 11:15 AM
11-26-2008 11:21 AM
I have used example report SIMPLE_TREE_CONTROL_DEMOI01 to create my tree control navigation.
Where do I have to use the HOTSPOT?
TYPES: node_table_type LIKE STANDARD TABLE OF ztreenode
WITH DEFAULT KEY.
CONSTANTS:
BEGIN OF c_nodekey,
root TYPE tv_nodekey VALUE 'Root',
child1 TYPE tv_nodekey VALUE 'Child1',
child2 TYPE tv_nodekey VALUE 'Child2',
new1 TYPE tv_nodekey VALUE 'New1',
new2 TYPE tv_nodekey VALUE 'New2',
new3 TYPE tv_nodekey VALUE 'New3',
new4 TYPE tv_nodekey VALUE 'New4',
END OF c_nodekey.
DATA: node_table TYPE node_table_type,
events TYPE cntl_simple_events,
event TYPE cntl_simple_event,
g_tree TYPE REF TO cl_gui_simple_tree.
DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
g_ok_code TYPE sy-ucomm.
DATA: node LIKE ztreenode,
g_node_key TYPE tv_nodekey.
DATA: g_event(30).
CLASS lcl_event_tree DEFINITION DEFERRED.
CLASS lcl_event_tree DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_expand_no_children
FOR EVENT expand_no_children
OF cl_gui_simple_tree
IMPORTING node_key.
ENDCLASS. "lcl_event_tree DEFINITION
CLASS lcl_event_tree IMPLEMENTATION.
METHOD handle_expand_no_children.
DATA: node_table TYPE node_table_type,
node TYPE ztreenode.
g_event = 'EXPAND_NO_CHILDREN'.
g_node_key = node_key.
IF node_key = 'Child1'.
* Node with key 'New1'
CLEAR node.
node-node_key = c_nodekey-new1.
node-relatkey = c_nodekey-child1.
node-relatship = cl_gui_simple_tree=>relat_last_child.
* node-isfolder = ' '.
node-n_image = '@00@'.
node-text = text-001.
APPEND node TO node_table.
CALL METHOD g_tree->add_nodes
EXPORTING
table_structure_name = 'ZTREENODE'
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.
ENDIF.
ENDIF.
ENDMETHOD. "handle_expand_no_children
ENDCLASS. "lcl_event_tree IMPLEMENTATION
PBO
* 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 = 'CONTAINER'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
ENDIF.
* create a tree control
CREATE OBJECT g_tree
EXPORTING
parent = container_1_2
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.
ENDIF.
***********************************************
" expand no children
event-eventid = cl_gui_simple_tree=>eventid_expand_no_children.
event-appl_event = 'X'.
APPEND event TO events.
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.
************************************************
SET HANDLER lcl_event_tree=>handle_expand_no_children FOR g_tree.
PERFORM build_node_table USING node_table.
CALL METHOD g_tree->add_nodes
EXPORTING
table_structure_name = 'ZTREENODE'
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.
ENDIF.
ENDFORM. " ADD_TREE
*&---------------------------------------------------------------------*
*& Form BUILD_NODE_TABLE
*&---------------------------------------------------------------------*
FORM build_node_table
USING
node_table TYPE node_table_type.
* 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 = c_nodekey-root.
" 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 = 'TEST'(roo).
APPEND node TO node_table.
* Node with key 'Child1'
node-node_key = c_nodekey-child1.
" Key of the node
" Node is inserted as child of the node with key 'Root'.
node-relatkey = c_nodekey-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 = 'DISPLAY'.
* node-style = cl_gui_simple_tree=>style_emphasized_positive.
APPEND node TO node_table.
ENDFORM. " BUILD_NODE_TABLE
11-26-2008 11:38 AM
for Single click use this handle_link_click for g_tree
event-eventid = cl_gui_column_tree=>eventid_link_click.
event-appl_event = 'X'.
append event to events.
set handler g_application->handle_link_click for g_tree.
and write the logic in the method handle_link_click
Ranga
11-26-2008 2:41 PM
I dont use cl_gui_column_tree I am using CL_GUI_SIMPLE_TREE.
Is there another alternative?
Actually I use the method
handle_node_double_click
FOR EVENT node_double_click
OF cl_gui_simple_tree
IMPORTING node_key,
This method is running, the only issue is that it dont refresh my alv table when I double click on the tree control item, when I start the debugger the event starts and my table of the alv is also refreshed, but not the display of the alv , why?I dont understand
11-26-2008 8:31 PM
Hello Muhammet
There is a specific event available for this purpose: SELECTION_CHANGED
The SAP standard report RSEIDOC2 uses a different control (CL_GUI_COLUMN_TREE) but the logic is the same (see include RSEIDOC_TREE_CL):
***INCLUDE CLASS_TREE .
*===============================================================
* Klasse für die Eventbehandlung TREE
CLASS vh_event_class DEFINITION.
PUBLIC SECTION.
METHODS:
handle_selection_changed
for event selection_changed
of cl_gui_column_tree
importing node_key.
ENDCLASS.
*----------------------------------------------------------------------*
CLASS vh_event_class IMPLEMENTATION.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
METHOD HANDLE_SELECTION_CHANGED.
" this method handles the node double click event of the tree
" control instance
g_EVENT = 'NODE_DOUBLE_CLICK'. "#EC NOTEXT
G_NODE_KEY = NODE_KEY.
perform fill_new_alv_list_table. " NOTE: Change itab for ALV output !!! us
ENDMETHOD.
*----------------------------------------------------------------------*
endclass.
Within include RSEIDOC_F01 you can see that in this case the event is registered as application event:
form init_tree.
...
* definieren der Ereignisse
event-eventid = cl_gui_column_tree=>eventid_selection_changed.
event-appl_event = 'X'. " process PAI if event occurs
append event to events.
* registrieren lassen der Ereignisse, auf die ich reagieren will
call method vh_tree->set_registered_events
exporting
events = events
exceptions
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
if sy-subrc ne 0.
message id sy-msgid type 'A' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* assign event handlers
set handler vh_event->handle_selection_changed for vh_tree.
...
And within the PBO module PBO you can see that they alwasy call method SET_TABLE_FOR_FIRST_DISPLAY to ensure the refreshing of the ALV list output.
Regards
Uwe
11-27-2008 3:32 AM
11-27-2008 4:57 PM
Hello Muhammet
I have re-written my sample report ZUS_SDN_TWO_ALV_GRIDS into ZUS_SDN_TREE_AND_GRID_CONTROL which is now display a tree control together with the ALV grid.
When you analyze this new report you will see that every step of the program logic is as I described in my previous e-mails.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_TWO_ALV_GRIDS
*&
*&---------------------------------------------------------------------*
*& Screen '0100' contains no elements.
*& ok_code -> assigned to GD_OKCODE
*&
*& Flow logic:
* PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
* PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
*&
*&---------------------------------------------------------------------*
*& Thread: single click on tree control navigation
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1143770"></a>
*&---------------------------------------------------------------------*
REPORT zus_sdn_tree_and_grid_control.
TYPE-POOLS: abap, cntl.
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!
CONSTANTS:
BEGIN OF c_nodekey,
root TYPE tv_nodekey VALUE 'Root', "#EC NOTEXT
child1 TYPE tv_nodekey VALUE 'Child1', "#EC NOTEXT
* child2 type tv_nodekey value 'Child2', "#EC NOTEXT
new1 TYPE tv_nodekey VALUE 'New1', "#EC NOTEXT
new2 TYPE tv_nodekey VALUE 'New2', "#EC NOTEXT
* new3 type tv_nodekey value 'New3', "#EC NOTEXT
* new4 type tv_nodekey value 'New4', "#EC NOTEXT
END OF c_nodekey.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
*
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_cell_left TYPE REF TO cl_gui_container,
go_cell_right TYPE REF TO cl_gui_container,
go_tree TYPE REF TO cl_gui_simple_tree,
go_grid1 TYPE REF TO cl_gui_alv_grid,
** go_grid2 TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_knvv TYPE STANDARD TABLE OF knvv.
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
** CALL METHOD go_grid1->set_current_cell_via_id
** EXPORTING
*** IS_ROW_ID =
*** IS_COLUMN_ID =
** is_row_no = es_row_no.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
md_event TYPE string READ-ONLY,
md_node_key TYPE tv_nodekey READ-ONLY.
CLASS-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.
ENDCLASS. "LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION 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
md_event = 'NODE_DOUBLE_CLICK'.
md_node_key = node_key.
" Trigger PAI and set ok-code = 'DETAIL'
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'DETAIL'
* IMPORTING
* rc =
.
MESSAGE md_node_key TYPE 'I'.
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
md_event = 'EXPAND_NO_CHILDREN'.
md_node_key = node_key.
IF node_key = 'Child1'.
* add two nodes to the tree control (the children of 'Child1')
* Node with key 'New1'
CLEAR node.
node-node_key = c_nodekey-new1.
node-relatkey = c_nodekey-child1.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-isfolder = ' '.
node-text = 'New1'(ne1).
APPEND node TO node_table.
* Node with key 'New2'
CLEAR node.
node-node_key = c_nodekey-new2.
node-relatkey = c_nodekey-child1.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-n_image = '@10@'.
node-expander = ' '.
node-text = 'New2'(ne2).
APPEND node TO node_table.
CALL METHOD go_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
ENDCLASS. "LCL_APPLICATION IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1 UP TO 100 ROWS
WHERE bukrs = '1000'.
PERFORM init_controls.
* Display data
gs_layout-grid_title = 'Customers: Sales Areas'.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNVV'
is_layout = gs_layout
CHANGING
it_outtab = gt_knvv
EXCEPTIONS
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.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
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.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid1->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
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.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
* User has pushed button "Display Details"
WHEN 'DETAIL'.
MESSAGE gd_okcode TYPE 'I'.
PERFORM entry_show_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM entry_show_details .
* define local data
DATA:
ld_row TYPE i,
ls_knb1 TYPE knb1.
IF ( gt_knvv IS INITIAL ).
SELECT * FROM knvv INTO TABLE gt_knvv
FOR ALL ENTRIES IN gt_knb1
WHERE kunnr = gt_knb1-kunnr.
ELSE.
REFRESH: gt_knvv.
ENDIF.
ENDFORM. " ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
*& Form INIT_CONTROLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 1
columns = 2
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_left.
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = go_cell_right.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_right
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid1.
PERFORM create_and_init_tree.
ENDFORM. " INIT_CONTROLS
*&---------------------------------------------------------------------*
*& Form CREATE_AND_INIT_TREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_and_init_tree .
DATA: lt_node_table TYPE node_table_type,
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
* create a tree control
CREATE OBJECT go_tree
EXPORTING
parent = go_cell_left
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single " single node selection is used
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
ls_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
** ls_event-appl_event = 'X'. " process PAI if event occurs
" NOTE: Do NOT register as application event !!!!!
APPEND ls_event TO lt_events.
CALL METHOD go_tree->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
** MESSAGE a000.
ENDIF.
SET HANDLER:
lcl_application=>handle_node_double_click FOR go_tree,
lcl_application=>handle_expand_no_children FOR go_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 lt_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 go_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
node_table = lt_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
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 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 = c_nodekey-root.
" 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'(roo).
APPEND node TO node_table.
* Node with key 'Child1'
node-node_key = c_nodekey-child1.
" Key of the node
" Node is inserted as child of the node with key 'Root'.
node-relatkey = c_nodekey-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'(ch1).
node-style = cl_gui_simple_tree=>style_emphasized_positive.
APPEND node TO node_table.
ENDFORM. " build_node_table
Regards
Uwe
01-15-2022 10:19 AM
For CL_GUI_ALV_TREE set also these two attributes:
CREATE OBJECT gr_alv_tree
EXPORTING
....
node_selection_mode = cl_tree_control_base=>node_sel_mode_single
item_selection = abap_false