ALV tree using Objects
Hi,
I am making an ALV tree using objects and the code is crashing due to an error in the Screen 100 ( which I am using ). I tried to implement the example provided at http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htm but that is not working.
Can anyone please tell me a working example or a brief tutorial so that I can correct the logical errors in my code.
Thanks,
Gaurav
Hi,
Check whether u have uncommented the PAI and PBO modules.
Try this one.
REPORT ZZZTEST_3
NO STANDARD PAGE HEADING
MESSAGE-ID zcs_cs_001.
1/ Report Name: ZZZ_ALV_TREE_DEMO
The definition and implementation of the event reciever class
include <icon>.
Predefine a local class for event handling to allow the
declaration of a reference variable before the class is defined.
class lcl_event_receiver definition deferred.
data :
Alv Containers
tree definition
o_tree type ref to cl_gui_simple_tree,
Event Handler
o_eventreceiver type ref to lcl_event_receiver,
o_dockingcontainer TYPE REF TO cl_gui_docking_container.
data :
node structures for tree building
i_nodes type table of abdemonode, " node table def create bespoke
w_nodes like line of i_nodes, " work area
i_tree_event type cntl_simple_events, " Itab for Tree Events
w_tree_event type cntl_simple_event. " Work area for Tree Events
data:
v_ratio1 type i, "docking container screen area
container screen area
v_action(12) type c.
Internal Tables Used for Object ALV Display.
data:
i_toolbar type table of stb_button, "Tool bar for Grid1
i_exclude1 type ui_functions,
i_exclude2 type ui_functions,
i_groups type lvc_t_sgrp, " Group Definitions
i_selected_rows type lvc_t_row. " Select row type
constants: c_x(1) type c value 'X', "Checked
c_a(1) type c value 'A'. "All Layouts
CLASS lcl_event_receiver DEFINITION
class lcl_event_receiver definition.
event receiver definitions for ALV actions
public section.
class-methods:
Status bar
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm,
Tree Actions
handle_node_double_click
for event node_double_click of cl_gui_simple_tree
importing node_key,
Row Double click for dirll down.
handle_double_click
for event double_click of cl_gui_alv_grid
importing e_row
e_column
es_row_no.
endclass.
Implementation
Every event handler that is specified below should also be set after
the object has been created. This is done in the PBO processing.
with the following command
SET HANDLER oEventreceiver->handle_toolbar FOR o_Alvgrid.
class lcl_event_receiver implementation.
method handle_user_command.
In event handler method for event USER_COMMAND: Query your
function codes defined in step 2 and react accordingly.
endmethod.
*& Method handle_double_click
This method is called when the user double clicks on a line to drill
down.
The following are exported from the ALV
LVC_S_ROW
LVC_S_COL
LVC_S_ROID
method handle_double_click.
The double click drill down processing should be
coded in the form below.
endmethod.
*& Method handle_node_double_click
This method handles the node double click event of the tree
LVC_S_ROW
LVC_S_COL
LVC_S_ROID
method handle_node_double_click.
perform f9903_handle_node_double_click using node_key.
endmethod.
endclass.
INITIALIZATION
INITIALIZATION.
PERFORM f050_initialize_values.
FORM f050_initialize_values.
v_ratio1 = 30. "tree size
ENDFORM. " f050_initialize_values
START-OF-SELECTION
START-OF-SELECTION.
END-OF-SELECTION
END-OF-SELECTION.
CALL SCREEN 9001.
*Data Selection
FORM f9000_objects_create USING value(pobject)
pparent
value(pratio)
value(prows)
value(pcolumns).
CASE pobject.
WHEN 'o_dockingcontainer'.
IF o_dockingcontainer IS INITIAL.
CREATE OBJECT o_dockingcontainer
EXPORTING
side = v_dock_side1
ratio = pratio "amount of screen
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
PERFORM f9800_error_handle USING text-e06.
ENDIF.
WHEN 'o_tree'.
IF o_tree IS INITIAL.
CREATE OBJECT o_tree
EXPORTING
LIFETIME =
parent = pparent
SHELLSTYLE =
node_selection_mode = o_tree->node_sel_mode_single
HIDE_SELECTION =
name = 'Transactions'
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
failed = 4
illegal_node_selection_mode = 5
others = 6.
PERFORM f9800_error_handle USING text-e06.
ENDIF.
WHEN 'o_eventreceiver'.
IF o_eventreceiver IS INITIAL.
CREATE OBJECT o_eventreceiver.
PERFORM f9800_error_handle USING text-e08.
ENDIF.
WHEN OTHERS.
do nothing
ENDCASE.
ENDFORM. " f9000_objects_create
*& Form f9100_create_tree
Create the Tree
-->P_O_TREE tree data
FORM f9100_create_tree USING p_o_tree TYPE REF TO cl_gui_simple_tree.
REFRESH: i_nodes.
CLEAR: w_nodes.
Header Tree Folder
w_nodes-node_key = 'ROOT'.
w_nodes-isfolder = c_x.
w_nodes-expander = c_x.
w_nodes-text = 'Transactions'.
APPEND w_nodes TO i_nodes.
Adding Root Nodes for the tree.
Key:
NODE_KEY, RELATKEY, RELATSHIP, HIDDEN, DISABLED, ISFOLDER, N_IMAGE,
EXP_IMAGE, STYLE, LAST_HITEM, NO_BRANCH, EXPANDER, DRAGDROPID, TEXT
PERFORM f9101_node_list USING: '1' 'ROOT' '' '' '' c_x '' '' '' '' ''
c_x '' 'Sales Orders'.
Adding subitems for the root node.
PERFORM f9101_node_list USING:
Material Details
'VA01' '1' '' '' '' '' '@15@' '' '' '' '' ''
'' 'Create Sales Orders',
Document Details
'VA02' '1' '' '' '' '' '@15@' '' '' '' '' ''
'' 'Change Sales Orders'.
PERFORM f9101_node_list USING: '2' 'ROOT' '' '' '' c_x '' '' '' '' ''
c_x '' 'Deliveries'.
Adding subitems for the root node.
PERFORM f9101_node_list USING:
Material Details
'VL01' '2' '' '' '' '' '@15@' '' '' '' '' ''
'' 'Create Outbound Delivery',
Document Details
'VL02' '2' '' '' '' '' '@15@' '' '' '' '' ''
'' 'Change Outbound Delivery'.
add the nodes to the tree object,
PERFORM f9102_add_treenodes TABLES i_nodes
USING 'ABDEMONODE' "node definition
p_o_tree. "tree declaration
enabling event handlers for the tree
PERFORM f9103_tree_event_handle USING p_o_tree.
ENDFORM. " f9100_create_tree
*& Form f9101_node_list
Adding Nodes in a TREE
FORM f9101_node_list USING value(pnodekey)
value(prelatkey)
value(prelatship)
value(phidden)
value(pdisabled)
value(pisfolder)
value(pimage)
value(pexpimage)
value(pstyle)
value(plastitem)
value(pnobranch)
value(pexpander)
value(pdragdropid)
value(ptext).
w_nodes-node_key = pnodekey.
w_nodes-relatkey = prelatkey.
w_nodes-relatship = prelatship. "Natural number
w_nodes-hidden = phidden.
w_nodes-disabled = pdisabled.
w_nodes-isfolder = pisfolder.
w_nodes-n_image = pimage. "Icons / embedded bitmap
w_nodes-exp_image = pexpimage. "Icons / embedded bitmap
w_nodes-style = pstyle.
w_nodes-last_hitem = plastitem. "Tree Control: Column Name / Item
"Name
w_nodes-no_branch = pnobranch.
w_nodes-expander = pexpander.
w_nodes-dragdropid = pdragdropid.
w_nodes-text = ptext.
APPEND w_nodes TO i_nodes.
ENDFORM. " f9101_node_list
*& Form f9102_add_treenodes
Adding the Nodes to the Tree
-->PI_NODES Table containg the Nodes
-->PTABLE Name of the Table structure name
-->PO_TREE tree object
FORM f9102_add_treenodes TABLES pi_nodes TYPE STANDARD TABLE
USING value(ptable)
po_tree TYPE REF TO cl_gui_simple_tree.
CALL METHOD po_tree->add_nodes
EXPORTING
table_structure_name = ptable "may need to change
node_table = pi_nodes[]
EXCEPTIONS
error_in_node_table = 1
failed = 2
dp_error = 3
table_structure_name_not_found = 4
OTHERS = 5
PERFORM f9800_error_handle USING text-e10.
ENDFORM. " f9102_add_treenodes
*& Form f9103_tree_event_handle
Event Handling for Tree.
-->P_P_O_TREE text
FORM f9103_tree_event_handle USING
p_o_tree TYPE REF TO cl_gui_simple_tree.
w_tree_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
w_tree_event-appl_event = ' '. " process PAI if event occurs
APPEND w_tree_event TO i_tree_event.
CALL METHOD p_o_tree->set_registered_events
EXPORTING
events = i_tree_event
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE A000.
ENDIF.
IF o_eventreceiver IS INITIAL.
CREATE OBJECT o_eventreceiver.
ENDIF.
SET HANDLER o_eventreceiver->handle_node_double_click FOR p_o_tree.
ENDFORM. " f9103_tree_event_handle
-->P_IEXCLUDE text
-->P_1150 text
FORM f9200_exclude_functions USING pexclude LIKE i_exclude1
value(pfunction).
DATA: l_exclude TYPE ui_func.
l_exclude = pfunction.
APPEND l_exclude TO pexclude.
ENDFORM. " f9200_exclude_functions
*& Form f9903_handle_node_double_click
This form is used to handle the double click event for the tree
-->P_NODE_KEY Node clicked.
FORM f9903_handle_node_double_click USING p_node_key.
CASE p_node_key.
WHEN 'VA01'.
SUBMIT ZZZ_TEST AND RETURN.
CALL TRANSACTION 'VA01'. " and skip first screen.
WHEN 'VA02'.
CALL TRANSACTION 'VA02'. " and skip first screen.
WHEN 'VL01'.
CALL TRANSACTION 'VL01'. " and skip first screen.
WHEN 'VL02'.
CALL TRANSACTION 'VL02'. " and skip first screen.
WHEN OTHERS.
do nothning.
ENDCASE.
ENDFORM. " f9903_handle_node_double_click
*& Form f9700_free_objects
This form handles the freeing of the following objects
ALV
Docking Container
-->P_O_ALVGRID text
-->P_0020 text
-->P_0021 text
FORM f9700_free_objects USING pobject
value(ptype)
value(ptext).
Need to type the field symbol or it does not work
CASE ptype.
WHEN 'DOCKING'.
DATA: l_odock TYPE REF TO cl_gui_docking_container.
l_odock = pobject.
IF NOT ( l_odock IS INITIAL ).
CALL METHOD l_odock->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, l_odock.
PERFORM f9800_error_handle USING ptext.
ENDIF.
WHEN 'TREE'.
DATA: l_otree TYPE REF TO cl_gui_simple_tree.
l_otree = pobject.
IF NOT ( l_otree IS INITIAL ).
CALL METHOD l_otree->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
CLEAR: pobject, l_otree.
PERFORM f9800_error_handle USING ptext.
ENDIF.
WHEN OTHERS.
do something.
ENDCASE.
ENDFORM. " f9700_free_objects
*& Form f9800_error_handle
Handles Errors
-->P_PTEXT text
FORM f9800_error_handle USING value(ptext).
IF sy-subrc NE 0.
add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-e01
txt2 = sy-subrc
txt1 = ptext.
ENDIF.
ENDFORM. " f9800_error_handle
*PBO & PAI Modules
*& Module STATUS_9001 OUTPUT
text
module status_9001 output.
Set the Status Bar
set pf-status 'Z_STATUS'.
Set the Title
set titlebar 'Z_TITLE'.
perform f9000_objects_create using:
create docking container
'o_dockingcontainer' '' v_ratio1 '' '',
create a tree
'o_tree' o_dockingcontainer '' '' '',
Create the event reciever
'o_eventreceiver' '' '' '' ''.
Create the Tree View.
perform f9100_create_tree using o_tree.
endmodule. " STATUS_9001 OUTPUT
*& Module USER_COMMAND_9001 INPUT
text
module user_command_9001 input.
case sy-ucomm.
when 'EXIT' or 'CANC'.
perform f9700_free_objects using:
o_tree 'TREE' text-E03,
o_dockingcontainer 'DOCKING' text-E05,
o_eventreceiver 'EVENT' text-e09.
leave program.
leave. " to SCREEN 0.
when 'BACK'.
perform f9700_free_objects using:
o_tree 'TREE' text-E03,
o_dockingcontainer 'DOCKING' text-e05,
o_eventreceiver 'EVENT' text-E09.
set screen '0'.
leave screen.
when others.
endcase.
endmodule. " USER_COMMAND_9001 INPUT
Get back to me if u have any queries. Give me ur mail id, i will send one more sample code for ALV tree. This sample program will display only Tree not grid u can add ALV grid too.
Thanks & Regards,
Judith.
Similar Messages
-
Can anyone tell me how to Copy a node on an ALV Tree using context menu ?
Hello Vidya
The sample report ZUS_SDN_ALVTREE_CTXMENU demonstrates how to copy nodes on an ALV tree.
Before showing the entire coding I would like to point out a few crucial parts of the coding:
(1) Defintion of OUTTAB list
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
The OUTTAB list contains two additional fields holding the tree key (LVC_NKEY) and the node type.
(2) The main logic of the report is implemented in event handler method handle_node_ctxmenu_sel.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
" Note: similar logic like in routine CREATE_HIERARCHY
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
*& Report ZUS_SDN_ALVTREE_CTXMENU
*& Based on: BCALV_TREE_03
REPORT zus_sdn_alvtree_ctxmenu.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_repid TYPE syst-repid,
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_alvtree TYPE REF TO cl_gui_alv_tree.
DATA:
gt_outtab TYPE ty_t_outtab, " Sales Document
gt_fcat TYPE lvc_t_fcat.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
* §2. Define an event handler method to build up a context menu
* (postfix of event name: _CONTEXT_MENU_REQUEST).
* This event is fired each time the user klick with the right
* mouse button on a node.
CLASS-METHODS:
handle_node_ctxmenu_req
FOR EVENT node_context_menu_request OF cl_gui_alv_tree
IMPORTING
node_key
menu,
* §3. Define an event handler method to respond to a function code
* triggered by your menu (postfix: _CONTEXT_MENU_SELECTED).
* This event is fired when the user selects an entry of the
* build up context menu.
handle_node_ctxmenu_sel
FOR EVENT node_context_menu_selected OF cl_gui_alv_tree
IMPORTING
node_key
fcode
sender.
* 'sender' is an implicit event parameter that is provided by
* ABAP Objects runtime system. It contains a reference to the
* object that fired the event. You may directly use it to
* call methods of this instance.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
* §4. Implement your event handler methods.
METHOD handle_node_ctxmenu_req.
* Event parameter 'menu' holds a reference to the standard context
* menu of ALV Tree (functions 'Expand'/'Collapse' on nodes).
* You may either append your own functions (separated by a line)
* or clear the menu if you do not want to allow standard functions.
* In this case the standard menu is cleared.
CALL METHOD menu->clear.
* The next line defines one line of the context menu.
CALL METHOD menu->add_function
EXPORTING
fcode = 'DEL_SUBTREE'
text = 'Delete Subtree'(901). "Delete Subtree
CALL METHOD menu->add_function
EXPORTING
fcode = 'COPY_SUBTREE'
text = 'Copy Subtree'(902). "Copy Subtree
ENDMETHOD. "handle_node_ctxmenu_req
METHOD handle_node_ctxmenu_sel.
* At this point of execution, the user selected a menu entry of the
* menu build up in event handler method handle_node_cm_req.
* Query your own function codes and react accordingly.
DATA:
l_rc TYPE c,
ld_ntype TYPE lvc_value,
ld_parent_key TYPE lvc_nkey,
ld_node_key TYPE lvc_nkey,
lt_subtree TYPE lvc_t_nkey,
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
CASE fcode.
WHEN 'DEL_SUBTREE'.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
textline1 = 'Do you really want to delete'(902)
textline2 = 'this node and all its subnodes?'(903)
titel = 'Confirmation'(904)
cancel_display = ' '
IMPORTING
answer = l_rc.
IF l_rc EQ 'J'.
CALL METHOD sender->delete_subtree
EXPORTING
i_node_key = node_key.
* Do not forget to refresh the display when you change the contents
* of your list.
CALL METHOD sender->frontend_update.
ENDIF.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
IF ( ld_ntype = 'VKORG' ).
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' ).
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' OR
ld_ntype = 'SPART' ).
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH_TREE'
* IMPORTING
* RC =
ENDCASE.
ENDMETHOD. "handle_node_ctxmenu_sel
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
PERFORM init_controls.
* 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.
CALL SCREEN '0100'.
* NOTE: no screen elements, ok_code -> gd_okcode
** 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'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE. " facilitate manual entries
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
when 'REFRESH_TREE'.
CALL METHOD go_alvtree->update_calculations
* EXPORTING
* NO_FRONTEND_UPDATE =
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
DATA:
ls_hierarchy_header TYPE treev_hhdr.
* 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.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size screen
EXCEPTIONS
cntl_error = 1
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.
* create tree control
CREATE OBJECT go_alvtree
EXPORTING
parent = go_docking
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = ' '
no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
PERFORM build_hierarchy_header CHANGING ls_hierarchy_header.
* Hide columns and sum up values initially using the fieldcatalog
PERFORM build_fieldcatalog.
* IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
* (even after this method call). You can change data of your table
* by calling methods of CL_GUI_ALV_TREE.
* Furthermore, the output table 'gt_outtab' must be global and can
* only be used for one ALV Tree Control.
CALL METHOD go_alvtree->set_table_for_first_display
EXPORTING
is_hierarchy_header = ls_hierarchy_header
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_outtab. "table must be empty !
PERFORM init_tree.
ENDFORM. " INIT_CONTROLS
*& Form INIT_TREE
* text
* --> p1 text
* <-- p2 text
FORM init_tree .
PERFORM create_hierarchy.
PERFORM register_events.
* Update calculations which were initially defined by field DO_SUM
* of the fieldcatalog. (see build_fieldcatalog).
CALL METHOD go_alvtree->update_calculations.
* Send data to frontend.
CALL METHOD go_alvtree->frontend_update.
ENDFORM. " INIT_TREE
*& Form build_hierarchy_header
* text
* <--P_LS_HIERARCHY_HEADER text
FORM build_hierarchy_header
CHANGING
cs_hierarchy_header TYPE treev_hhdr.
cs_hierarchy_header-heading =
'SalesOrg/DistChannel/Division'(300).
cs_hierarchy_header-tooltip = 'Customer: Master Sales Data'(400).
cs_hierarchy_header-width = 45.
cs_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form build_fieldcatalog
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
REFRESH: gt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_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.
LOOP AT gt_fcat INTO ls_fcat.
CASE ls_fcat-fieldname.
WHEN 'VBELN' OR
'AUDAT' OR
'AUART' OR
'WAERK' OR
'VKORG' OR
'VTWEG' OR
'SPART' OR
'BSTNK' OR
'KUNNR'.
WHEN 'NETWR'.
ls_fcat-do_sum = 'X'.
ls_fcat-h_ftype = 'SUM'. " or: 'MAX' / 'AVG'
WHEN OTHERS.
ls_fcat-tech = 'X'.
ENDCASE.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.
ENDFORM. " build_fieldcatalog
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
FORM create_hierarchy .
* define local data
DATA:
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
" Select data
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE lt_outtab
UP TO 1550 ROWS.
" sort table according to conceived hierarchy
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
* Define one top node. In this way it is possible to calculate
* values for the whole hierarchy.
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = 'Sales Documents'
IMPORTING
e_new_node_key = ld_top_key.
CLEAR: ls_outtab.
ls_outtab-nkey = ld_top_key.
ls_outtab-ntype = 'ROOT'.
MODIFY gt_outtab FROM ls_outtab INDEX 1
TRANSPORTING nkey ntype.
LOOP AT lt_outtab INTO ls_outtab.
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form ADD_SALES_ORG
* text
* -->P_LS_OUTTAB text
* -->P_LD_TOP_KEY text
* <--P_LD_VKORG_KEY text
FORM add_sales_org
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vkorg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " ADD_SALES_ORG
*& Form add_DISTRIB_CHAN
* text
* -->P_LS_OUTTAB text
* -->P_LD_VKORG_KEY text
* <--P_LD_VTWEG_KEY text
FORM add_distrib_chan
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vtweg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_DISTRIB_CHAN
*& Form add_division
* text
* -->P_LS_OUTTAB text
* -->P_LD_VTWEG_KEY text
* <--P_LD_SPART_KEY text
FORM add_division
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-spart.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_division
*& Form add_complete_line
* text
* -->P_LS_OUTTAB text
* -->P_LD_SPART_KEY text
* <--P_LD_LAST_KEY text
FORM add_complete_line
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
WRITE us_outtab-kunnr TO ld_nodetext+0 NO-ZERO.
WRITE us_outtab-audat TO ld_nodetext+20 DD/MM/YYYY.
CONDENSE ld_nodetext.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = us_outtab " !!!
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
FORM register_events .
DATA:
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
* The following four tree events registers ALV Tree in the constructor
* method itself.
* - cl_gui_column_tree=>eventid_expand_no_children
* (needed to load data to frontend when a user expands a node)
* - cl_gui_column_tree=>eventid_header_context_men_req
* (needed for header context menu)
* - cl_gui_column_tree=>eventid_header_click
* (allows selection of columns (only when item selection activated))
* - cl_gui_column_tree=>eventid_item_keypress
* (needed for F1-Help (only when item selection activated))
* Nevertheless you have to provide their IDs again if you register
* additional events with SET_REGISTERED_EVENTS (see below).
* To do so, call first method GET_REGISTERED_EVENTS (this way,
* all already registered events remain registered, even your own):
CALL METHOD go_alvtree->get_registered_events
IMPORTING
events = lt_events.
* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.
* Register additional events for your own purposes:
* §5. Register first context menu event on frontend (with postfix
* (_REQUEST). The second is registered automatically.
ls_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND ls_event TO lt_events.
* register events on frontend
CALL METHOD go_alvtree->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
* §6. Register both context menu events on backend (ABAP Objects
* event handling).
SET HANDLER:
lcl_eventhandler=>handle_node_ctxmenu_req FOR go_alvtree,
lcl_eventhandler=>handle_node_ctxmenu_sel FOR go_alvtree.
ENDFORM. " register_events
Regards,
Uwe -
ALV Tree using Function Modules
Hi,
I want a simple example of ALV Tree using Function Modules which can display multiple Columns in the Hierarchically arranged fashion along with nodes & icons.
Also should be able to handle the events.
Thanks in Advance..Hi Ramesh,
Here is a example of alv tree
*& Report BCALV_TREE_DEMO *
report bcalv_tree_demo.
class cl_gui_column_tree definition load.
class cl_gui_cfw definition load.
data tree1 type ref to cl_gui_alv_tree.
data mr_toolbar type ref to cl_gui_toolbar.
include <icon>.
include bcalv_toolbar_event_receiver.
include bcalv_tree_event_receiver.
data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.
data: gt_sflight type sflight occurs 0, "Output-Table
gt_fieldcatalog type lvc_t_fcat, "Fieldcatalog
ok_code like sy-ucomm. "OK-Code
start-of-selection.
end-of-selection.
call screen 100.
*& Module PBO OUTPUT
* process before output
module pbo output.
set pf-status 'MAIN100'.
if tree1 is initial.
perform init_tree.
endif.
call method cl_gui_cfw=>flush.
endmodule. " PBO OUTPUT
*& Module PAI INPUT
* process after input
module pai input.
case ok_code.
when 'EXIT' or 'BACK' or 'CANC'.
perform exit_program.
when others.
call method cl_gui_cfw=>dispatch.
endcase.
clear ok_code.
call method cl_gui_cfw=>flush.
endmodule. " PAI INPUT
*& Form build_fieldcatalog
* build fieldcatalog for structure sflight
form build_fieldcatalog.
* get fieldcatalog
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'SFLIGHT'
changing
ct_fieldcat = gt_fieldcatalog.
* change fieldcatalog
data: ls_fieldcatalog type lvc_s_fcat.
loop at gt_fieldcatalog into ls_fieldcatalog.
case ls_fieldcatalog-fieldname.
when 'CARRID' or 'CONNID' or 'FLDATE'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-key = ''.
when 'PRICE' or 'SEATSOCC' or 'SEATSMAX' or 'PAYMENTSUM'.
ls_fieldcatalog-do_sum = 'X'.
endcase.
modify gt_fieldcatalog from ls_fieldcatalog.
endloop.
endform. " build_fieldcatalog
*& Form build_hierarchy_header
* build hierarchy-header-information
* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
form build_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
p_hierarchy_header-heading = 'Hierarchy Header'. "#EC NOTEXT
p_hierarchy_header-tooltip =
'This is the Hierarchy Header !'. "#EC NOTEXT
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ''.
endform. " build_hierarchy_header
*& Form exit_program
* free object and leave program
form exit_program.
call method tree1->free.
leave program.
endform. " exit_program
*& Form build_header
* build table for html_header
* --> p1 text
* <-- p2 text
form build_comment using
pt_list_commentary type slis_t_listheader
p_logo type sdydo_value.
data: ls_line type slis_listheader.
* LIST HEADING LINE: TYPE H
clear ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'ALV-tree-demo: flight-overview'. "#EC NOTEXT
append ls_line to pt_list_commentary.
* STATUS LINE: TYPE S
clear ls_line.
ls_line-typ = 'S'.
ls_line-key = 'valid until'. "#EC NOTEXT
ls_line-info = 'January 29 1999'. "#EC NOTEXT
append ls_line to pt_list_commentary.
ls_line-key = 'time'.
ls_line-info = '2.00 pm'. "#EC NOTEXT
append ls_line to pt_list_commentary.
* ACTION LINE: TYPE A
clear ls_line.
ls_line-typ = 'A'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'actual data'. "#EC NOTEXT
append ls_line to pt_list_commentary.
p_logo = 'ENJOYSAP_LOGO'.
endform.
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
form create_hierarchy.
data: ls_sflight type sflight,
lt_sflight type sflight occurs 0.
* get data
select * from sflight into table lt_sflight
UP TO 200 ROWS .
sort lt_sflight by carrid connid fldate.
* add data to tree
data: l_carrid_key type lvc_nkey,
l_connid_key type lvc_nkey,
l_last_key type lvc_nkey.
loop at lt_sflight into ls_sflight.
on change of ls_sflight-carrid.
perform add_carrid_line using ls_sflight
changing l_carrid_key.
endon.
on change of ls_sflight-connid.
perform add_connid_line using ls_sflight
l_carrid_key
changing l_connid_key.
endon.
perform add_complete_line using ls_sflight
l_connid_key
changing l_last_key.
endloop.
* calculate totals
call method tree1->update_calculations.
* this method must be called to send the data to the frontend
call method tree1->frontend_update.
endform. " create_hierarchy
*& Form add_carrid_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
form add_carrid_line using ps_sflight type sflight
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_sflight type sflight.
* set item-layout
data: lt_item_layout type lvc_t_layi,
ls_item_layout type lvc_s_layi.
ls_item_layout-t_image = '@3P@'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
append ls_item_layout to lt_item_layout.
* add node
l_node_text = ps_sflight-carrid.
call method tree1->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key.
endform. " add_carrid_line
*& Form add_connid_line
* add hierarchy-level 2 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
form add_connid_line using ps_sflight type sflight
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_sflight type sflight.
* set item-layout
data: lt_item_layout type lvc_t_layi,
ls_item_layout type lvc_s_layi.
ls_item_layout-t_image = '@3Y@'.
ls_item_layout-style =
cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
append ls_item_layout to lt_item_layout.
* add node
l_node_text = ps_sflight-connid.
call method tree1->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key.
endform. " add_connid_line
*& Form add_cmplete_line
* add hierarchy-level 3 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
form add_complete_line using ps_sflight type sflight
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value.
* set item-layout
data: lt_item_layout type lvc_t_layi,
ls_item_layout type lvc_s_layi.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.
ls_item_layout-editable = 'X'.
append ls_item_layout to lt_item_layout.
l_node_text = ps_sflight-fldate.
call method tree1->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = ps_sflight
i_node_text = l_node_text
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key.
endform. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
form register_events.
* define the events which will be passed to the backend
data: lt_events type cntl_simple_events,
l_event type cntl_simple_event.
* define the events which will be passed to the backend
l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
append l_event to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
append l_event to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
append l_event to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
append l_event to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
append l_event to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_click.
append L_EVENT to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
append L_EVENT to lt_events.
call method tree1->set_registered_events
exporting
events = lt_events
exceptions
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
* set Handler
data: l_event_receiver type ref to lcl_tree_event_receiver.
create object l_event_receiver.
set handler l_event_receiver->handle_node_ctmenu_request
for tree1.
set handler l_event_receiver->handle_node_ctmenu_selected
for tree1.
set handler l_event_receiver->handle_item_ctmenu_request
for tree1.
set handler l_event_receiver->handle_item_ctmenu_selected
for tree1.
endform. " register_events
*& Form change_toolbar
* text
* --> p1 text
* <-- p2 text
form change_toolbar.
* get toolbar control
call method tree1->get_toolbar_object
importing
er_toolbar = mr_toolbar.
check not mr_toolbar is initial.
* add seperator to toolbar
call method mr_toolbar->add_button
exporting
fcode = ''
icon = ''
butn_type = cntb_btype_sep
text = ''
quickinfo = 'This is a Seperator'. "#EC NOTEXT
* add Standard Button to toolbar (for Delete Subtree)
call method mr_toolbar->add_button
exporting
fcode = 'DELETE'
icon = '@18@'
butn_type = cntb_btype_button
text = ''
quickinfo = 'Delete subtree'. "#EC NOTEXT
* add Dropdown Button to toolbar (for Insert Line)
call method mr_toolbar->add_button
exporting
fcode = 'INSERT_LC'
icon = '@17@'
butn_type = cntb_btype_dropdown
text = ''
quickinfo = 'Insert Line'. "#EC NOTEXT
* set event-handler for toolbar-control
create object toolbar_event_receiver.
set handler toolbar_event_receiver->on_function_selected
for mr_toolbar.
set handler toolbar_event_receiver->on_toolbar_dropdown
for mr_toolbar.
endform. " change_toolbar
*& Form init_tree
* text
* --> p1 text
* <-- p2 text
FORM init_tree.
* create fieldcatalog for structure sflight
perform build_fieldcatalog.
* create container for alv-tree
data: l_tree_container_name(30) type c,
l_custom_container type ref to cl_gui_custom_container.
l_tree_container_name = 'TREE1'.
if sy-batch is initial.
create object l_custom_container
exporting
container_name = l_tree_container_name
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
endif.
* create tree control
create object tree1
exporting
parent = l_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
no_html_header = ''
no_toolbar = ''
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
* create Hierarchy-header
data l_hierarchy_header type treev_hhdr.
perform build_hierarchy_header changing l_hierarchy_header.
* create info-table for html-header
data: lt_list_commentary type slis_t_listheader,
l_logo type sdydo_value.
perform build_comment using
lt_list_commentary
l_logo.
* repid for saving variants
data: ls_variant type disvariant.
ls_variant-report = sy-repid.
* create emty tree-control
call method tree1->set_table_for_first_display
exporting
is_hierarchy_header = l_hierarchy_header
it_list_commentary = lt_list_commentary
i_logo = l_logo
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
changing
it_outtab = gt_sflight "table must be emty !!
it_fieldcatalog = gt_fieldcatalog.
* create hierarchy
perform create_hierarchy.
* add own functioncodes to the toolbar
perform change_toolbar.
* register events
perform register_events.
* adjust column_width
call method tree1->COLUMN_OPTIMIZE.
ENDFORM. " init_tree
regards,
venu. -
Attaining Hot spot in ALV Tree Using OOPS concept
Hi All,
In our requirement we are displaying the data in ALV Tree Using OOPS.
We need to achieve hot spot on one of the header field.
I am using Class 'CL_GUI_ALV_TREE'
Ex:
CreditAccnt/ Company codes DSO DDSO
26 15 15
8000 5 5
8545 10 10
In the above example for every credit accnt in header we r displaying the values ( DSO ,DDSO) for all company codes.
Now we require hot spot on Credit Accnt 26. Such that when user clicks on the credit accnt it should navigate to another transaction.
NOTE: we havent build any field catalogue for field CreditAccnt/ Company codes .Hi,
You can refer to the tutorial -
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/an%20easy%20reference%20for%20alv%20grid%20control.pdf
Or try using the code below-
CLASS lcl_event_receiver DEFINITION
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
Hot Spot Click
handle_hotspot
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id
e_column_id
es_row_no,
ENDCLASS.
Implementation
*& Method handle_hotspot
This method is called when the user clicks on a hotspot to drill down.
The following types are exported from the ALV
LVC_S_ROW
LVC_S_COL
LVC_S_ROID
METHOD handle_hotspot.
The hotspot processing coded in the form below.
PERFORM f9802_handle_hotspot USING e_row_id
e_column_id
es_row_no.
ENDMETHOD.
*& Form f9802_handle_hotspot
This form is called when the user clicks on a hotspot on the ALV grid
The parameters are of type
-->P_E_ROW text
-->P_E_COL text
-->P_E_ROID text
FORM f9802_handle_hotspot USING p_row
p_col
p_roid.
DATA: lw_output LIKE LINE OF i_output.
READ TABLE i_output INDEX p_row INTO lw_output.
SET PARAMETER ID 'MAT' FIELD lw_output-matnr.
CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
ENDFORM. " f9802_handle_hotspot
FORM f9300_modify_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat.
Field-symbols: <lfs_fieldcat> TYPE lvc_s_fcat.
LOOP AT p_fieldcat ASSIGNING <lfs_fieldcat>.
CASE <lfs_fieldcat>-fieldname.
WHEN 'MATNR'.
<lfs_fieldcat>-hotspot = c_x.
<lfs_fieldcat>-key = c_x.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDFORM.
In PBO,
module STATUS_9001 output.
Set handlers for events
SET HANDLER o_eventreceiver->handle_hotspot FOR o_Alvgrid.
ENDMODULE.
Hope this helps -
Downloading ALV Grid (using objects) output to Excel
Hi all,
I'm using objects for ALV Grid. I have few other fields (few are above and few are below the custom control) on screen other than custom control. I want to download the entire screen to excel (including other fields). But using Export option I'm able to download only ALV Grid. I did tried with Excel in place option which is not pulling data from ALV Grid control.
Please suggest me the solution.
Regards
Jaker.hi
use this code in ALV format
TABLES USR03.
DATA: BEGIN OF ISAPDAT OCCURS 0,
BNAME LIKE USR03-BNAME,
NAME1 LIKE USR03-NAME1,
NAME2 LIKE USR03-NAME2,
END OF ISAPDAT.
PARAMETERS P_FNAME LIKE RLGRAP-FILENAME
DEFAULT 'd:\sapdata.xls' OBLIGATORY.
SELECT * FROM USR03 INTO CORRESPONDING FIELDS OF TABLE ISAPDAT.
SORT ISAPDAT.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FILENAME = P_FNAME
TABLES
I_TAB_SAP_DATA = ISAPDAT
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ 'Download to Excel complete'.
ELSE.
WRITE:/ 'Error with download'.
ENDIF.
Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 2:34 PM -
How to get the Row and Column values in ALV (without using Objects)
Hi All,
I need to get the Row / Column when double click is used in ALV, I can use the double click event for this. However, I do not want to use the Object Oriented ALV. I want to implement the same functionality using general (using functions) ALV.
Is there any way to get the row / column values for a Generia (non-OOPs) ALV report.
Please help.
Thanks,
Vishal.Hello,
The only think you have to do is to get the index where the user clicked, and then read the internal table you sent to the alv
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = 'prg_name'
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND' " this is to the click event!!
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout = alv_layout
it_fieldcat = alv_fieldcat
i_save = 'A'
it_events = alv_events[]
TABLES
t_outtab = i_totmez. ---> TOUR IT.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" then....
FORM user_commandUSING r_ucomm TYPE sy-ucomm
ls_selfield TYPE slis_selfield.
" r_ucomm -> HAS THE STATUS
" ls_selfield-tabindex -> HAS THE SELECTED INDEX
" THEN READ THE INTERNAL TABLE
" HERE YOU WILL HAVE THE SELECTED ROW
READ TABLE i_totmez INDEX ls_selfield-tabindex.
ENDFORM.
cheers,
Gabriel P. -
Problem with focus with an ALV grid using object methods
Hi, i have an editable ALV and there is something wrong that we haven't been able to solve it yet, hope you can understand my explanation
Supose a grid 2 x 5
cell 1 - cell 2 - Cell 3 - Cell 4 - Cell 5
001 John Doe
So when a press tab or enter to the any cell diferent from cell 1 the focus get back to the cell 1, and i have to tab ( in this example) 3 times to fill cell 4, and then 4 times to fill cell 5
Any ideas???
ttorresHi,
Use method :SET_CURRENT_CELL_VIA_ID of grid to set the cursor position in a cell.
Ex:
CALL METHOD O_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = V_ROW
IS_COLUMN_ID = V_COLUMN
IS_ROW_NO = V_ROW_NUM.
use methods : get_current_cell_row_id, get_current_cell
to get the required parameters for SET_CURRENT_CELL_VIA_ID.
Regards
Appana -
ALV grid using Object oriented programming
Hi,
I need to display a report with 14 fields of which some fields need sub totals and some fields need average values and some other fields require both subtotals and totals. But if I need only the subtotals. I'm not able to find a way for doing so. Please help.
Thanks and regards
RadhikaYou will have to specify DO_SUM = X for the fields which you want to totalled or sub-totalled and set DO_SUM = C for getting the average of the field. This needs to be done in the field catalog.
Also, specify the SORT criteria for the doing the sub-totals in the IT_SORT table, of the SET_TABLE method or the user can do that himself in the report.
Regards,
Ravi
Note - Please mark all the helpful answers -
Runtime Error in ALV Tree Output
Dear All, I am trying to create a ALV Tree using Class cl_gui_alv_tree. The Report Shows the Output with the first Node but when i try to expand it is dumping with a runtime error GETWA_NOT_ASSIGNED in class CL_ALV_TREE_BASE and method SET_ITEMS_FOR_COLUMN. The Reason being the data which was copied in the initial node display to mt_outtab is getting refreshed.
Can any one of you help me the reason for the table getting refreshed. Do i need to pass any data.
I am doing the following steps.
1. Create Container,
2. Create Tree Class object
3. Generate the Field Catalog.
4. Set table for first display " With empty internal table
5. Generate the Hierarchy
6. Call the Method Frontend Update.
Let me know if i had missed any steps in the process.
Thank you,
Regards,
Swaroop PatriOne reason for getting this error is using local defined tables for it_outtab parameter in the below code:
To get rid of the dump, define two distinct output tables globally: one is an empty table which you will pass to the below method, other one is your real output table whose size increases dependently.
CALL METHOD go_tree->set_table_for_first_display
EXPORTING
is_hierarchy_header = ls_hier_header
CHANGING
it_outtab = gt_data_e "Empty table
it_fieldcatalog = gt_fcat_tree. -
i am trying to call a docking container (on hotspot click of ALV.-> Reuse_alv_grid_display).
And a alv tree is to be displayed in docking container.
I have wrote the entire code and there is no error is thrown by the system, but docking container displayed.
I am posting entire code .Please let me know where i am mistaken.
check r_ucomm eq '&IC1'."when user double click on any cell of ALV.
CASE rs_selfield-SEL_TAB_FIELD.
WHEN 'I_MKPF-WERKS'.
perform create_dock.
perform create_alv_tree.
* WHEN .
* WHEN OTHERS.
ENDCASE.
FORM CREATE_DOCK ."docking container is created
check obj1 is initial.
CREATE OBJECT OBJ1
EXPORTING
* PARENT =
REPID = sy-repid
DYNNR = sy-dynnr
SIDE = obj1->DOCK_AT_bottom
EXTENSION = 500
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
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.
ENDFORM.
FORM CREATE_ALV_TREE . "alv Tree
create object tree
exporting
parent = obj1
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
no_html_header = 'X'
no_toolbar = ''
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
data l_hierarchy_header type treev_hhdr.
perform build_hierarchy_header changing l_hierarchy_header.
IF gt_fieldcatalog[] is initial.
perform buildfield_cat using 'TRNTYP' 'TRNTYP' .
perform buildfield_cat using 'EXDAT' 'Excise Doc' .
perform buildfield_cat using 'WERKS' 'Excise Doc' .
perform buildfield_cat using 'EXNUM' 'Excise Doc' .
perform buildfield_cat using 'EXYEAR' 'Excise Doc' .
perform buildfield_cat using 'MATNR' 'Excise Doc' .
perform buildfield_cat using 'RITEM1' 'Excise Doc' .
perform buildfield_cat using 'RITEM2' 'Excise Doc' .
perform buildfield_cat using 'MAKTX' 'Excise Doc' .
perform buildfield_cat using 'REMOVAL' 'Excise Doc' .
perform buildfield_cat using 'MEINS' 'Excise Doc' .
perform buildfield_cat using 'EXBAS' 'Excise Doc' .
perform buildfield_cat using 'EXBED' 'Excise Doc' .
endif.
call method tree->set_table_for_first_display
EXPORTING
* i_structure_name = 'SFLIGHT'
is_hierarchy_header = l_hierarchy_header
CHANGING
it_outtab = t_J_1IEXCDTL[] "table must be empty !
it_fieldcatalog = gt_fieldcatalog.
perform create_hierarchy.
call method tree->frontend_update.
FORM CREATE_HIERARCHY .
sort IJ_1IEXCDTL by chapid matnr.
LOOP AT IJ_1IEXCDTL into WJ_1IEXCDTL.
on change of WJ_1IEXCDTL-chapid.
perform add_carrid_line using WJ_1IEXCDTL
changing l_carrid_key.
endon.
on change of WJ_1IEXCDTL-matnr.
perform add_complete_line using WJ_1IEXCDTL"last complete line.
l_carrid_key
changing l_last_key.
endon.
ENDLOOP.
endform.
form add_carrid_line using WJ_1IEXCDTL1 type J_1IEXCDTL
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value.
l_node_text = WJ_1IEXCDTL1-chapid.
call method tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = WJ_1IEXCDTL
IMPORTING
e_new_node_key = p_node_key.
endform. "add_carrid_line
form add_complete_line using WJ_1IEXCDTL2 type J_1IEXCDTL
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value.
write WJ_1IEXCDTL2-matnr to l_node_text .
call method tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = WJ_1IEXCDTL2
i_node_text = l_node_text
IMPORTING
e_new_node_key = p_node_key.
endform. "add_complete_lineThis is the ALV and i want docking container containing alv tree to be displayed with the details of this alv
at bottom of screen. -
Drag and Drop between two ALV Tree Controls
Hello all,
I have designed a spilt control of two ALV Trees using CL_GUI_ALV_TREE.
I have a top node as the Sales order Number and the child node as the items belonging to that sales order number.
Now i need to drag and drop the lines from one sales order to another.
Also these drag drop can take place between the nodes of the two different trees.
Can someone provide with a detail example as i need to complete the same urgently.
Regards,
ArunOnce check the Below code For tree to tree drag an drop
* CLASS lcl_main DEFINITION
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
* Types
TYPES:
BEGIN OF t_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF t_ekpo.
TYPES:
BEGIN OF t_vbap,
vbeln TYPE vbeln,
posnr TYPE vbelp,
END OF t_vbap.
* Internal Tables
DATA:
i_ekpo TYPE STANDARD TABLE OF t_ekpo,
i_ekpo_op TYPE STANDARD TABLE OF t_ekpo,
i_vbap TYPE STANDARD TABLE OF t_vbap,
i_vbap_op TYPE STANDARD TABLE OF t_vbap,
i_fcat_ekpo TYPE lvc_t_fcat,
i_fcat_vbap TYPE lvc_t_fcat.
* Work Areas
DATA:
wa_ekpo TYPE t_ekpo,
wa_ekpo1 TYPE t_ekpo,
wa_vbap TYPE t_vbap,
wa_vbap1 TYPE t_vbap.
* Data Declarations
DATA:
g_ebeln TYPE ebeln,
g_vbeln TYPE vbeln_va.
DATA: g_variant TYPE disvariant,
g_hierarchy_header TYPE treev_hhdr,
g_handle_drag TYPE i,
g_handle_drop TYPE i.
* Class data
DATA:
splitter TYPE REF TO cl_gui_splitter_container,
container TYPE REF TO cl_gui_custom_container,
container_1 TYPE REF TO cl_gui_container,
container_2 TYPE REF TO cl_gui_container,
tree1 TYPE REF TO cl_gui_alv_tree,
tree2 TYPE REF TO cl_gui_alv_tree,
g_drag TYPE REF TO cl_dragdrop,
g_drop TYPE REF TO cl_dragdrop.
* Constants
CONSTANTS:
c_30(2) TYPE c VALUE '30'.
* Methods
METHODS:
get_data, " Data Fatch
build_display, " Display Container
display_ekpo, " Ekpo table display
display_vbap, " Vbap table display
add_node_ekpo " Add node to Ekpo
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
add_node_vbap " Add node to vbap
IMPORTING table TYPE t_vbap
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
dnd_behaviour, " Drag and drop behavour
register_events_ekpo, " Register Events Ekpo
register_events_vbap, " Register events vbap
handle_drag_multiple " Drag Multiple Values
FOR EVENT on_drag_multiple
OF cl_gui_alv_tree
IMPORTING sender node_key_table fieldname drag_drop_object,
handle_drop " Drop the values
FOR EVENT on_drop
OF cl_gui_alv_tree
IMPORTING sender node_key drag_drop_object,
add_node_drop " Add node to Drop Node
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
CHANGING i_key TYPE lvc_nkey.
ENDCLASS. " Lcl_main DEFINITION
* CLASS LCL_DRAGOBJ DEFINITION
* Drag And drop Structure
CLASS lcl_dragobj DEFINITION INHERITING FROM lcl_main FINAL.
PUBLIC SECTION.
* Types
TYPES: BEGIN OF t_node_info,
l_ekpo TYPE t_ekpo,
l_node_text TYPE lvc_value,
l_node_key TYPE lvc_nkey,
END OF t_node_info.
* Data
DATA: i_node_info TYPE TABLE OF t_node_info,
wa_node_info TYPE t_node_info.
ENDCLASS. " LCL_DRAGOBJ DEFINITION
* Object Declarations
DATA obj_main TYPE REF TO lcl_main.
* Initialization *
INITIALIZATION.
CREATE OBJECT obj_main.
* Selection Screen *
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME.
SELECT-OPTIONS:
s_ebeln FOR obj_main->g_ebeln,
s_vbeln FOR obj_main->g_vbeln MATCHCODE OBJECT cs_vbeln.
SELECTION-SCREEN END OF BLOCK block1.
* Start of Selection *
START-OF-SELECTION.
* Call Screen
CALL SCREEN 100.
* CLASS lcl_main IMPLEMENTATION
* Local class Implementation
CLASS lcl_main IMPLEMENTATION.
* Get Data *
METHOD get_data.
* Data from Ekpo
SELECT ebeln
ebelp
FROM ekpo
UP TO 100 ROWS
INTO TABLE i_ekpo
WHERE ebeln IN s_ebeln.
* Data from Vbap
SELECT vbeln
posnr
FROM vbap
UP TO 100 ROWS
INTO TABLE i_vbap
WHERE vbeln IN s_vbeln.
ENDMETHOD. " Get_data
* Build Display *
METHOD build_display.
* Create Container
CREATE OBJECT container
EXPORTING
container_name = 'CUST_CONT'.
* Split the container
CREATE OBJECT splitter
EXPORTING
parent = container
rows = 1
columns = 2.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = container_1.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = container_2.
* create tree control
CREATE OBJECT tree1
EXPORTING
parent = container_1
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
CREATE OBJECT tree2
EXPORTING
parent = container_2
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
g_variant-report = sy-repid.
g_variant-handle = space.
g_variant-log_group = space.
g_variant-username = space.
g_variant-text = space.
g_variant-dependvars = space.
* Call method for get data
CALL METHOD get_data.
* Drap And Drop behaviour method
CALL METHOD dnd_behaviour.
* Display the Ekpo table
CALL METHOD obj_main->display_ekpo.
* Diaplay the vbap table
CALL METHOD obj_main->display_vbap.
CALL METHOD tree1->frontend_update.
CALL METHOD tree2->frontend_update.
ENDMETHOD. " Build_display
* Display EKPO *
METHOD display_ekpo.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'EKPO'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_ekpo
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_ekpo FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Purchase Order Details'(001).
g_hierarchy_header-tooltip = 'Purchase Order'(002).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Diaply
CALL METHOD tree1->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_ekpo_op
it_fieldcatalog = i_fcat_ekpo.
LOOP AT i_ekpo INTO wa_ekpo1.
MOVE wa_ekpo1 TO wa_ekpo.
l_key1 = ''.
AT NEW ebeln.
MOVE wa_ekpo-ebeln TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key1
text = l_node_text
flag = space
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_ekpo-ebelp TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key2
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_ekpo INTO wa_ekpo1.
* Call method For Register events
CALL METHOD register_events_ekpo.
ENDMETHOD. " Display_ekpo
* Display VBAP *
METHOD display_vbap.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
REFRESH i_fcat_vbap.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'VBAP'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_vbap
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_vbap FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Sales Order Details'(003).
g_hierarchy_header-tooltip = 'Sales Order'(004).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Display
CALL METHOD tree2->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_vbap_op
it_fieldcatalog = i_fcat_vbap.
LOOP AT i_vbap INTO wa_vbap1.
MOVE wa_vbap1 TO wa_vbap.
l_key1 = ''.
AT NEW vbeln.
MOVE wa_vbap-vbeln TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key1
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_vbap-posnr TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key2
text = l_node_text
flag = space
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_vbap INTO wa_vbap1.
* Call method For Register events
CALL METHOD register_events_vbap.
ENDMETHOD. " Display_vbap
* Add Node to Ekko *
METHOD add_node_ekpo.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drag.
ENDIF. " IF flag = 'X'.
* Add node to tree1
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
ENDMETHOD. " Add_node_ekpo
* Add Node to Vbap *
METHOD add_node_vbap.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drop.
ENDIF. " IF flag = 'X'.
* Add node for tree2
CALL METHOD tree2->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
ENDMETHOD. " Add_node_vbap
* Dnd behaviour *
METHOD dnd_behaviour.
* Data
DATA: effect TYPE i,
l_flavor TYPE c VALUE 'f'.
* For drag
CREATE OBJECT g_drag.
effect = cl_dragdrop=>copy.
CALL METHOD g_drag->add
EXPORTING
flavor = l_flavor
dragsrc = 'X'
droptarget = ' '
effect = effect
effect_in_ctrl = effect.
CALL METHOD g_drag->get_handle
IMPORTING
handle = g_handle_drag.
* For Drop
CREATE OBJECT g_drop.
effect = cl_dragdrop=>copy.
CALL METHOD g_drop->add
EXPORTING
flavor = l_flavor
dragsrc = ' '
droptarget = 'X'
effect = effect
effect_in_ctrl = effect.
CALL METHOD g_drop->get_handle
IMPORTING
handle = g_handle_drop.
ENDMETHOD. " Dnd_behaviour
* register events *
METHOD register_events_ekpo.
* Data
DATA: lt_events TYPE cntl_simple_events.
* Tree events registers ALV Tree
CALL METHOD tree1->get_registered_events
IMPORTING
events = lt_events.
* Register events on frontend
CALL METHOD tree1->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
* Event Handling
SET HANDLER obj_main->handle_drag_multiple FOR tree1.
ENDMETHOD. " Register_events_ekpo
* register events *
METHOD register_events_vbap.
* Data
DATA: lt_events TYPE cntl_simple_events.
* Tree events registers ALV Tree
CALL METHOD tree2->get_registered_events
IMPORTING
events = lt_events.
* Register events on frontend
CALL METHOD tree2->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
* Event
SET HANDLER obj_main->handle_drop FOR tree2.
ENDMETHOD. " Register_events_vbap
* Handle drag multiple Values *
METHOD handle_drag_multiple.
* Data
DATA: dataobj TYPE REF TO lcl_dragobj,
l_node_key TYPE lvc_nkey,
l_ekpo TYPE t_ekpo,
l_node_text TYPE lvc_value,
l_node_layout TYPE lvc_s_layn.
* Create and fill dataobject for event ON_DROP.
CREATE OBJECT dataobj.
* Loop the Node key Table
LOOP AT node_key_table INTO l_node_key.
CALL METHOD sender->get_outtab_line
EXPORTING
i_node_key = l_node_key
IMPORTING
e_outtab_line = l_ekpo
e_node_text = l_node_text
es_node_layout = l_node_layout.
IF l_node_layout-isfolder NE 'X'.
dataobj->wa_node_info-l_node_key = l_node_key.
dataobj->wa_node_info-l_ekpo = l_ekpo.
dataobj->wa_node_info-l_node_text = l_node_text.
APPEND dataobj->wa_node_info TO dataobj->i_node_info.
ENDIF. " IF l_node_layout-isfolder NE 'X'.
ENDLOOP. " LOOP AT node_key_table INTO l_node_key
drag_drop_object->object = dataobj.
ENDMETHOD. " Handle_drag_multiple
* Handle drop multiple Values *
METHOD handle_drop.
DATA: dataobj TYPE REF TO lcl_dragobj,
l_new_key TYPE lvc_nkey,
l_node_text TYPE lvc_value.
CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
* ON_DROP
dataobj ?= drag_drop_object->object.
LOOP AT dataobj->i_node_info INTO dataobj->wa_node_info.
MOVE dataobj->wa_node_info-l_node_text TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_drop
EXPORTING
table = dataobj->wa_node_info-l_ekpo
key = node_key
text = l_node_text
CHANGING
i_key = l_new_key.
ENDLOOP. " LOOP AT dataobj->i_node_info INTO dataobj->wa_node_inf
* Expand the node
CALL METHOD sender->expand_node
EXPORTING
i_node_key = node_key
CALL METHOD sender->frontend_update.
ENDCATCH.
IF sy-subrc NE 0.
CALL METHOD drag_drop_object->abort.
ENDIF. " IF sy-subrc NE 0
ENDMETHOD. " Handle_drop
* Add Node to drop *
METHOD add_node_drop.
* Add node to drop tree
CALL METHOD tree2->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
* is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0
ENDMETHOD. " Add_node_drop
ENDCLASS. " lcl_main IMPLEMENTATION
*& Module STATUS_0100 OUTPUT
* Screen 100 Pbo
MODULE status_0100 OUTPUT.
SET PF-STATUS 'BACK'.
* SET TITLEBAR 'xxx'.
CALL METHOD obj_main->build_display.
ENDMODULE. " Status_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* Screen 100 Pai
MODULE user_command_0100 INPUT.
IF sy-ucomm EQ 'BACK'.
LEAVE TO SCREEN 0.
ENDIF. " IF sy-ucomm EQ 'BACK'
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Report ZBPS_TREE_DRAG_DROP
REPORT zbps_tree_drag_drop.
* CLASS lcl_main DEFINITION
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
* Types
TYPES:
BEGIN OF t_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF t_ekpo.
TYPES:
BEGIN OF t_vbap,
vbeln TYPE vbeln,
posnr TYPE vbelp,
END OF t_vbap.
* Internal Tables
DATA:
i_ekpo TYPE STANDARD TABLE OF t_ekpo,
i_ekpo_op TYPE STANDARD TABLE OF t_ekpo,
i_vbap TYPE STANDARD TABLE OF t_vbap,
i_vbap_op TYPE STANDARD TABLE OF t_vbap,
i_fcat_ekpo TYPE lvc_t_fcat,
i_fcat_vbap TYPE lvc_t_fcat.
* Work Areas
DATA:
wa_ekpo TYPE t_ekpo,
wa_ekpo1 TYPE t_ekpo,
wa_vbap TYPE t_vbap,
wa_vbap1 TYPE t_vbap.
* Data Declarations
DATA:
g_ebeln TYPE ebeln,
g_vbeln TYPE vbeln_va.
DATA: g_variant TYPE disvariant,
g_hierarchy_header TYPE treev_hhdr,
g_handle_drag TYPE i,
g_handle_drop TYPE i.
* Class data
DATA:
splitter TYPE REF TO cl_gui_splitter_container,
container TYPE REF TO cl_gui_custom_container,
container_1 TYPE REF TO cl_gui_container,
container_2 TYPE REF TO cl_gui_container,
tree1 TYPE REF TO cl_gui_alv_tree,
tree2 TYPE REF TO cl_gui_alv_tree,
g_drag TYPE REF TO cl_dragdrop,
g_drop TYPE REF TO cl_dragdrop.
* Constants
CONSTANTS:
c_30(2) TYPE c VALUE '30'.
* Methods
METHODS:
get_data, " Data Fatch
build_display, " Display Container
display_ekpo, " Ekpo table display
display_vbap, " Vbap table display
add_node_ekpo " Add node to Ekpo
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
add_node_vbap " Add node to vbap
IMPORTING table TYPE t_vbap
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
dnd_behaviour, " Drag and drop behavour
register_events_ekpo, " Register Events Ekpo
register_events_vbap, " Register events vbap
handle_drag_multiple " Drag Multiple Values
FOR EVENT on_drag_multiple
OF cl_gui_alv_tree
IMPORTING sender node_key_table fieldname drag_drop_object,
handle_drop " Drop the values
FOR EVENT on_drop
OF cl_gui_alv_tree
IMPORTING sender node_key drag_drop_object,
add_node_drop " Add node to Drop Node
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
CHANGING i_key TYPE lvc_nkey.
ENDCLASS. " Lcl_main DEFINITION
* CLASS LCL_DRAGOBJ DEFINITION
* Drag And drop Structure
CLASS lcl_dragobj DEFINITION INHERITING FROM lcl_main FINAL.
PUBLIC SECTION.
* Types
TYPES: BEGIN OF t_node_info,
l_ekpo TYPE t_ekpo,
l_node_text TYPE lvc_value,
l_node_key TYPE lvc_nkey,
END OF t_node_info.
* Data
DATA: i_node_info TYPE TABLE OF t_node_info,
wa_node_info TYPE t_node_info.
ENDCLASS. " LCL_DRAGOBJ DEFINITION
* Object Declarations
DATA obj_main TYPE REF TO lcl_main.
* Initialization *
INITIALIZATION.
CREATE OBJECT obj_main.
* Selection Screen *
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME.
SELECT-OPTIONS:
s_ebeln FOR obj_main->g_ebeln,
s_vbeln FOR obj_main->g_vbeln MATCHCODE OBJECT cs_vbeln.
SELECTION-SCREEN END OF BLOCK block1.
* Start of Selection *
START-OF-SELECTION.
* Call Screen
CALL SCREEN 100.
* CLASS lcl_main IMPLEMENTATION
* Local class Implementation
CLASS lcl_main IMPLEMENTATION.
* Get Data *
METHOD get_data.
* Data from Ekpo
SELECT ebeln
ebelp
FROM ekpo
UP TO 100 ROWS
INTO TABLE i_ekpo
WHERE ebeln IN s_ebeln.
* Data from Vbap
SELECT vbeln
posnr
FROM vbap
UP TO 100 ROWS
INTO TABLE i_vbap
WHERE vbeln IN s_vbeln.
ENDMETHOD. " Get_data
* Build Display *
METHOD build_display.
* Create Container
CREATE OBJECT container
EXPORTING
container_name = 'CUST_CONT'.
* Split the container
CREATE OBJECT splitter
EXPORTING
parent = container
rows = 1
columns = 2.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = container_1.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = container_2.
* create tree control
CREATE OBJECT tree1
EXPORTING
parent = container_1
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
CREATE OBJECT tree2
EXPORTING
parent = container_2
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
g_variant-report = sy-repid.
g_variant-handle = space.
g_variant-log_group = space.
g_variant-username = space.
g_variant-text = space.
g_variant-dependvars = space.
* Call method for get data
CALL METHOD get_data.
* Drap And Drop behaviour method
CALL METHOD dnd_behaviour.
* Display the Ekpo table
CALL METHOD obj_main->display_ekpo.
* Diaplay the vbap table
CALL METHOD obj_main->display_vbap.
CALL METHOD tree1->frontend_update.
CALL METHOD tree2->frontend_update.
ENDMETHOD. " Build_display
* Display EKPO *
METHOD display_ekpo.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'EKPO'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_ekpo
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_ekpo FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Purchase Order Details'(001).
g_hierarchy_header-tooltip = 'Purchase Order'(002).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Diaply
CALL METHOD tree1->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_ekpo_op
it_fieldcatalog = i_fcat_ekpo.
LOOP AT i_ekpo INTO wa_ekpo1.
MOVE wa_ekpo1 TO wa_ekpo.
l_key1 = ''.
AT NEW ebeln.
MOVE wa_ekpo-ebeln TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key1
text = l_node_text
flag = space
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_ekpo-ebelp TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key2
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_ekpo INTO wa_ekpo1.
* Call method For Register events
CALL METHOD register_events_ekpo.
ENDMETHOD. " Display_ekpo
* Display VBAP *
METHOD display_vbap.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
REFRESH i_fcat_vbap.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'VBAP'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_vbap
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_vbap FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Sales Order Details'(003).
g_hierarchy_header-tooltip = 'Sales Order'(004).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Display
CALL METHOD tree2->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_vbap_op
it_fieldcatalog = i_fcat_vbap.
LOOP AT i_vbap INTO wa_vbap1.
MOVE wa_vbap1 TO wa_vbap.
l_key1 = ''.
AT NEW vbeln.
MOVE wa_vbap-vbeln TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key1
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_vbap-posnr TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key2
text = l_node_text
flag = space
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_vbap INTO wa_vbap1.
* Call method For Register events
CALL METHOD register_events_vbap.
ENDMETHOD. " Display_vbap
* Add Node to Ekko *
METHOD add_node_ekpo.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drag.
ENDIF. " IF flag = 'X'.
* Add node to tree1
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
ENDMETHOD. " Add_node_ekpo
* Add Node to Vbap *
METHOD add_node_vbap.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drop.
ENDIF. " IF flag = 'X'.
* Add node for tree2
CALL METHOD t -
Hi All,
I am displaying the output of my report in ALV Tree form displaying Plant, Functional Location,
Equipment, Order as Levels.
The Requirement is when i double click on the order number, it should navigate to the Details of the Order i.e. navigate to Transaction IW33.
I have used the Function Module "RS_TREE_LIST_DISPLAY" for displaying my ALV output as below :
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = 'ZPM714'.
Please suggest me for this.
Thanks & Regards,
BhavikaHi Pavan,
Please find the code below :
FORM BUILD_TREE .
CLEAR : WA_NODE, WT_NODE[], WT_NODE.
***Building ALV Tree maintaining the Hierarchy of Plant,Functional Location,Equipment Number,& Object Number
WA_NODE-TYPE = 'T'.
WA_NODE-NAME = 'Plant'.
WA_NODE-TLEVEL = '01'.
WA_NODE-NLENGTH = '15'.
WA_NODE-COLOR = '5'.
WA_NODE-TPOS = '45'.
WA_NODE-TPOS = '85'.
WA_NODE-TEXT = 'Actual Costs'.
WA_NODE-TLENGTH = '15'.
WA_NODE-TCOLOR = '3'.
WA_NODE-TPOS1 = '60'.
WA_NODE-TPOS1 = '100'.
WA_NODE-TEXT1 = 'Planned Costs'.
WA_NODE-TLENGTH1 = '20'.
WA_NODE-TCOLOR1 = '3'.
APPEND WA_NODE TO WT_NODE.
CLEAR WA_NODE.
LOOP AT WT_P.
WA_NODE-TYPE = 'P'.
WA_NODE-TLEVEL = '02'.
WA_NODE-TEXT = WT_P-WERKS.
WA_NODE-TLENGTH = '15'.
WA_NODE-TCOLOR = '1'.
CLEAR WV_VALUE.
WV_VALUE = WT_P-WTGBTR.
CONDENSE WV_VALUE.
WA_NODE-TEXT1 = WV_VALUE.
WA_NODE-TLENGTH1 = '15'.
WA_NODE-TCOLOR1 = '1'.
WA_NODE-TPOS1 = '45'.
WA_NODE-TPOS1 = '85'.
CLEAR WV_VALUE.
WV_VALUE = WT_P-WTG001.
CONDENSE WV_VALUE.
WA_NODE-TEXT2 = WV_VALUE.
WA_NODE-TLENGTH2 = '15'.
WA_NODE-TCOLOR2 = '1'.
WA_NODE-TPOS2 = '60'.
WA_NODE-TPOS2 = '100'.
APPEND WA_NODE TO WT_NODE.
CLEAR WA_NODE.
LOOP AT WT_FL WHERE WERKS = WT_P-WERKS.
WA_NODE-TYPE = 'P'.
WA_NODE-TLEVEL = '03'.
WA_NODE-TEXT = WT_FL-ILOAN.
WA_NODE-TEXT = WT_FL-TPLNR.
WA_NODE-TLENGTH = '12'.
WA_NODE-TLENGTH = '30'.
WA_NODE-TCOLOR = '1'.
CLEAR WV_VALUE.
WV_VALUE = WT_FL-AC.
CONDENSE WV_VALUE.
WA_NODE-TEXT1 = WV_VALUE.
WA_NODE-TLENGTH1 = '15'.
WA_NODE-TCOLOR1 = '1'.
WA_NODE-TPOS1 = '45'.
WA_NODE-TPOS1 = '85'.
CLEAR WV_VALUE.
WV_VALUE = WT_FL-PC.
CONDENSE WV_VALUE.
WA_NODE-TEXT2 = WV_VALUE.
WA_NODE-TLENGTH2 = '15'.
WA_NODE-TCOLOR2 = '1'.
WA_NODE-TPOS2 = '60'.
WA_NODE-TPOS2 = '100'.
APPEND WA_NODE TO WT_NODE.
CLEAR WA_NODE.
LOOP AT WT_EQ WHERE WERKS = WT_FL-WERKS AND
FUNC_LOC = WT_FL-ILOAN.
TPLNR = WT_FL-TPLNR.
WA_NODE-TYPE = 'P'.
WA_NODE-TLEVEL = '04'.
WA_NODE-TEXT = WT_EQ-EQUNR.
WA_NODE-TLENGTH = '18'.
WA_NODE-TCOLOR = '1'.
WA_NODE-TEXT1 = WT_EQ-EQKTX.
WA_NODE-TLENGTH1 = '40'.
WA_NODE-TCOLOR1 = '1'.
WA_NODE-TPOS1 = '45'.
WA_NODE-TPOS1 = '40'.
CLEAR WV_VALUE.
WV_VALUE = WT_EQ-AC.
CONDENSE WV_VALUE.
WA_NODE-TEXT2 = WV_VALUE.
WA_NODE-TLENGTH2 = '15'.
WA_NODE-TCOLOR2 = '1'.
WA_NODE-TPOS1 = '45'.
WA_NODE-TPOS2 = '85'.
CLEAR WV_VALUE.
WV_VALUE = WT_EQ-PC.
CONDENSE WV_VALUE.
WA_NODE-TEXT3 = WV_VALUE.
WA_NODE-TLENGTH3 = '15'.
WA_NODE-TCOLOR3 = '1'.
WA_NODE-TPOS2 = '60'.
WA_NODE-TPOS3 = '100'.
APPEND WA_NODE TO WT_NODE.
CLEAR WA_NODE.
LOOP AT WT_OB WHERE WERKS = WT_EQ-WERKS AND
FUNC_LOC = WT_EQ-FUNC_LOC AND
TPLNR = WT_EQ-TPLNR AND
EQUNR = WT_EQ-EQUNR.
WA_NODE-TYPE = 'P'.
WA_NODE-TLEVEL = '05'.
WA_NODE-TEXT = WT_OB-OBJNR.
WA_NODE-TEXT = WT_OB-AUFNR.
WA_NODE-TLENGTH = '22'.
WA_NODE-TLENGTH = '12'.
WA_NODE-TCOLOR = '1'.
WA_NODE-TEXT1 = WT_OB-KTEXT.
WA_NODE-TLENGTH1 = '40'.
WA_NODE-TCOLOR1 = '1'.
WA_NODE-TPOS1 = '45'.
WA_NODE-TPOS1 = '40'.
CLEAR WV_VALUE.
WV_VALUE = WT_OB-AC.
CONDENSE WV_VALUE.
WA_NODE-TEXT2 = WV_VALUE.
WA_NODE-TLENGTH2 = '15'.
WA_NODE-TCOLOR2 = '1'.
WA_NODE-TPOS1 = '45'.
WA_NODE-TPOS2 = '85'.
CLEAR WV_VALUE.
WV_VALUE = WT_OB-PC.
CONDENSE WV_VALUE.
WA_NODE-TEXT3 = WV_VALUE.
WA_NODE-TLENGTH3 = '15'.
WA_NODE-TCOLOR3 = '1'.
WA_NODE-TPOS2 = '60'.
WA_NODE-TPOS3 = '100'.
APPEND WA_NODE TO WT_NODE.
CLEAR WA_NODE.
LOOP AT WT_CE WHERE AUFNR = WT_OB-AUFNR.
WA_NODE-TYPE = 'P'.
WA_NODE-TLEVEL = '06'.
WA_NODE-TEXT = WT_CE-KSTAR.
WA_NODE-TLENGTH = '10'.
WA_NODE-TCOLOR = '1'.
CLEAR WV_VALUE.
WV_VALUE = WT_CE-AC.
CONDENSE WV_VALUE.
WA_NODE-TEXT1 = WV_VALUE.
WA_NODE-TLENGTH1 = '15'.
WA_NODE-TCOLOR1 = '1'.
WA_NODE-TPOS1 = '85'.
CLEAR WV_VALUE.
WV_VALUE = WT_CE-PC.
CONDENSE WV_VALUE.
WA_NODE-TEXT2 = WV_VALUE.
WA_NODE-TLENGTH2 = '15'.
WA_NODE-TCOLOR2 = '1'.
WA_NODE-TPOS2 = '100'.
APPEND WA_NODE TO WT_NODE.
CLEAR WA_NODE.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDFORM. " BUILD_TREE
*& Form DISPLAY_TREE
text
--> p1 text
<-- p2 text
FORM DISPLAY_TREE .
**Constructing the ALV Tree using Func Mod RS_TREE_CONSTRUCT*
CALL FUNCTION 'RS_TREE_CONSTRUCT'
EXPORTING
INSERT_ID = '000000'
RELATIONSHIP = ' '
LOG =
TABLES
NODETAB = WT_NODE
EXCEPTIONS
TREE_FAILURE = 1
ID_NOT_FOUND = 2
WRONG_RELATIONSHIP = 3
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.
**Displaying the ALV Tree using Func Mod RS_TREE_LIST_DISPLAY*
IF WT_FINAL_TEMP[] IS INITIAL.
MESSAGE 'No Data Available' TYPE 'S'.
ELSE.
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = 'ZPM714'
CALLBACK_USER_COMMAND = 'USER_COMMAND'
ENDIF.
ENDFORM. " DISPLAY_TREE
Regards,
Bhavika -
Displaying ALV tree in expanded form in first ouput
Hi all,
I have a problem with alv tree. My requirement is, on the first output itself the alv tree should appear expanded depending on one of the filter criteria in the tool bar. How can i trigger the toolbar event in PBO itself? Can it be done? if yes please provide sample code. Points assured for helpfull answers.
Thanks,
ShafiqHi Walter,
The method CL_GUI_ALV_TREE->EXPAND_NODES has only one importing parameter and that is the nodes of the ALV tree. But the commenting of the following lines from my code made it work which i have made it bold.Thank you very much for your help.I Have awarded points for you.
REPORT ztest_2105.
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
g_custom_container TYPE REF TO cl_gui_custom_container.
DATA: gt_sflight TYPE sflight OCCURS 0, "Output-Table
gt_fieldcatalog TYPE lvc_t_fcat,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm, "OK-Code
g_max TYPE i VALUE 255. "maximum of db records to select
DATA : it_node_key TYPE lvc_t_nkey,
wa_node_key LIKE LINE OF it_node_key.
LOCAL CLASSES
*§1. Define a (local) class for event handling
CLASS lcl_tree_event_receiver DEFINITION.
PUBLIC SECTION.
*§2. Define an event handler method for each event you want to react to
METHODS handle_node_double_click
FOR EVENT node_double_click OF cl_gui_alv_tree
IMPORTING node_key sender.
'sender' is an implicit event parameter that is provided by
ABAP Objects runtime system. It contains a reference to the
object that fired the event. You may directly use it to
call methods of this instance.
ENDCLASS.
CLASS lcl_tree_event_receiver IMPLEMENTATION.
*§3. Implement your event handler methods.
METHOD handle_node_double_click.
DATA: lt_children TYPE lvc_t_nkey.
*first check if the node is a leaf, i.e. can not be expanded
CALL METHOD sender->get_children
EXPORTING i_node_key = node_key
IMPORTING et_children = lt_children.
IF NOT lt_children IS INITIAL.
CALL METHOD sender->expand_node
EXPORTING i_node_key = node_key
i_level_count = 2.
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
END-OF-SELECTION.
CALL SCREEN 100.
*& Module PBO OUTPUT
process before output
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAINTITLE'.
IF g_alv_tree IS INITIAL.
PERFORM init_tree.
CALL METHOD g_alv_tree->expand_nodes
EXPORTING
it_node_key = it_node_key
EXCEPTIONS
FAILED = 1
CNTL_SYSTEM_ERROR = 2
ERROR_IN_NODE_KEY_TABLE = 3
DP_ERROR = 4
NODE_NOT_FOUND = 5
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.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS cntl_system_error = 1
cntl_error = 2.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Automation Queue failure'(801)
txt1 = 'Internal error:'(802)
txt2 = 'A method in the automation queue'(803)
txt3 = 'caused a failure.'(804).
ENDIF.
ENDIF.
ENDMODULE. " PBO OUTPUT
*& Module PAI INPUT
process after input
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
WHEN OTHERS.
§5. Call dispatch to process toolbar functions
Toolbar events are registered in constructur method of
CL_ALV_TREE_BASE as application events. So the dispatch call
is a must if you want to use the standard toolbar.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " PAI INPUT
*& Form init_tree
text
--> p1 text
<-- p2 text
FORM init_tree.
create container for alv-tree
DATA: l_tree_container_name(30) TYPE c.
l_tree_container_name = 'CCONTAINER1'.
CREATE OBJECT g_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'(100).
ENDIF.
create tree control
CREATE OBJECT g_alv_tree
EXPORTING
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
DATA l_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
Hide columns and sum up values initially using the fieldcatalog
PERFORM build_fieldcatalog.
IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
(even after this method call). You can change data of your table
by calling methods of CL_GUI_ALV_TREE.
Furthermore, the output table 'gt_outtab' must be global and can
only be used for one ALV Tree Control.
CALL METHOD g_alv_tree->set_table_for_first_display
EXPORTING
is_hierarchy_header = l_hierarchy_header
CHANGING
it_fieldcatalog = gt_fieldcatalog
it_outtab = gt_sflight. "table must be empty!
PERFORM create_hierarchy.
PERFORM register_events.
Update calculations which were initially defined by field DO_SUM
of the fieldcatalog. (see build_fieldcatalog).
CALL METHOD g_alv_tree->update_calculations.
Send data to frontend.
CALL METHOD g_alv_tree->frontend_update.
ENDFORM. " init_tree
*& Form build_hierarchy_header
build hierarchy-header-information
-->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Totals/Month/Carrier/Date'(300).
p_hierarchy_header-tooltip = 'Flights in a month'(400).
p_hierarchy_header-width = 35.
p_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form exit_program
free object and leave program
FORM exit_program.
CALL METHOD g_custom_container->free.
LEAVE PROGRAM.
ENDFORM. " exit_program
FORM build_fieldcatalog.
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
The following function module generates a fieldcatalog according
to a given structure.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = gt_fieldcatalog.
Now change the fieldcatalog to hide fields and to determine
some initial calculations for chosen fields.
LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
CASE ls_fieldcatalog-fieldname.
hide columns which are already displayed in our tree
WHEN 'CARRID' OR 'FLDATE'.
ls_fieldcatalog-no_out = 'X'.
Do some initial calculations:
ALV Tree uses the field 'do_sum' to declare that a function
for the corresponding column shall be calculated.
Use 'h_ftype' to set the function type (MAX, MIN, SUM, AVG).
WHEN 'PRICE'.
ls_fieldcatalog-do_sum = 'X'.
ls_fieldcatalog-h_ftype = 'MAX'.
WHEN 'SEATSMAX'.
ls_fieldcatalog-do_sum = 'X'.
ls_fieldcatalog-h_ftype = 'SUM'.
WHEN 'SEATSOCC'.
ls_fieldcatalog-do_sum = 'X'.
ls_fieldcatalog-h_ftype = 'AVG'.
ENDCASE.
MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
ENDLOOP.
The fieldcatalog is provided in form 'init_tree' using method
set_table_for_first_display.
ENDFORM. " build_fieldcatalog
FORM register_events.
*§4. Event registration: tell ALV Tree which events shall be passed
from frontend to backend.
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event,
l_event_receiver TYPE REF TO lcl_tree_event_receiver.
*§4a. Frontend registration(i): get already registered tree events.
The following four tree events registers ALV Tree in the constructor
method itself.
- cl_gui_column_tree=>eventid_expand_no_children
(needed to load data to frontend when a user expands a node)
- cl_gui_column_tree=>eventid_header_context_men_req
(needed for header context menu)
- cl_gui_column_tree=>eventid_header_click
(allows selection of columns (only when item selection activated))
- cl_gui_column_tree=>eventid_item_keypress
(needed for F1-Help (only when item selection activated))
Nevertheless you have to provide their IDs again if you register
additional events with SET_REGISTERED_EVENTS (see below).
To do so, call first method GET_REGISTERED_EVENTS (this way,
all already registered events remain registered, even your own):
CALL METHOD g_alv_tree->get_registered_events
IMPORTING events = lt_events.
(If you do not these events will be deregistered!!!).
You do not have to register events of the toolbar again.
*§4b. Frontend registration(ii): add additional event ids
l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
APPEND l_event TO lt_events.
*§4c. Frontend registration(iii):provide new event table to alv tree
CALL METHOD g_alv_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 x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
*§4d. Register events on backend (ABAP Objects event handling)
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->handle_node_double_click FOR g_alv_tree
ENDFORM. " register_events
*& Form create_hierarchy
text
--> p1 text
<-- p2 text
FORM create_hierarchy.
See BCALV_TREE_01 for more comments on building the hierarchy
DATA: ls_sflight TYPE sflight,
lt_sflight TYPE sflight OCCURS 0,
l_yyyymm(6) TYPE c, "year and month of sflight-fldate
l_yyyymm_last(6) TYPE c,
l_carrid LIKE sflight-carrid,
l_carrid_last LIKE sflight-carrid.
DATA: l_month_key TYPE lvc_nkey,
l_carrid_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey,
l_top_key TYPE lvc_nkey.
Select data
SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS.
sort table according to conceived hierarchy
SORT lt_sflight BY fldate0(6) carrid fldate6(2).
CLEAR : it_node_key, wa_node_key.
* wa_node_key = '&VIRTUALROOT'.
APPEND wa_node_key TO it_node_key.</b>
Define one top node. In this way it is possible to calculate
values for the whole hierarchy.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = text-050
IMPORTING
e_new_node_key = l_top_key.
wa_node_key = l_top_key.
APPEND wa_node_key TO it_node_key.
LOOP AT lt_sflight INTO ls_sflight.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
IF l_yyyymm <> l_yyyymm_last. "on change of l_yyyymm
l_yyyymm_last = l_yyyymm.
month nodes
PERFORM add_month USING l_yyyymm
l_top_key
CHANGING l_month_key.
clear l_carrid_last because this is a new month
CLEAR l_carrid_last.
wa_node_key = l_month_key.
APPEND wa_node_key TO it_node_key.
ENDIF.
Carrier nodes:
IF l_carrid <> l_carrid_last. "on change of l_carrid
l_carrid_last = l_carrid.
PERFORM add_carrid_line USING ls_sflight
l_month_key
CHANGING l_carrid_key.
wa_node_key = l_carrid_key.
APPEND wa_node_key TO it_node_key.
ENDIF.
Leaf:
PERFORM add_complete_line USING ls_sflight
l_carrid_key
CHANGING l_last_key.
* wa_node_key = l_last_key.
APPEND wa_node_key TO it_node_key.</b>
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form add_month
FORM add_month USING p_yyyymm TYPE c
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight,
l_month(15) TYPE c. "output string for month
get month name for node text
PERFORM get_month USING p_yyyymm
CHANGING l_month.
l_node_text = l_month.
add node
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_month
FORM add_carrid_line USING ps_sflight TYPE sflight
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight.
add node
l_node_text = ps_sflight-carrid.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_carrid_line
*& Form add_complete_line
FORM add_complete_line USING ps_sflight TYPE sflight
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value.
WRITE ps_sflight-fldate TO l_node_text MM/DD/YYYY.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = ps_sflight
i_node_text = l_node_text
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_complete_line
*& Form GET_MONTH
text
-->P_P_YYYYMM text
<--P_L_MONTH text
FORM get_month USING p_yyyymm
CHANGING p_month.
DATA: l_monthdigits(2) TYPE c.
l_monthdigits = p_yyyymm+4(2).
CASE l_monthdigits.
WHEN '01'.
p_month = 'January'(701).
WHEN '02'.
p_month = 'February'(702).
WHEN '03'.
p_month = 'March'(703).
WHEN '04'.
p_month = 'April'(704).
WHEN '05'.
p_month = 'May'(705).
WHEN '06'.
p_month = 'June'(706).
WHEN '07'.
p_month = 'July'(707).
WHEN '08'.
p_month = 'August'(708).
WHEN '09'.
p_month = 'September'(709).
WHEN '10'.
p_month = 'October'(710).
WHEN '11'.
p_month = 'November'(711).
WHEN '12'.
p_month = 'December'(712).
ENDCASE.
CONCATENATE p_yyyymm+0(4) '->' p_month INTO p_month.
ENDFORM. " GET_MONTH -
Hi All,
I amd currently developing an ALV tree program to capture the hierarchy of functional location. I managed to display the hierarchy in ALV Tree using cl_gui_column_tree.
Now, i am working on double clicking the functional location and it will bring me to tcode IL03. But, it seems like i cannot capture of the field value clicked. Below are my source code. Can anyone pls help me on this? Thank you very much
*& Form register_events
text
--> p1 text
<-- p2 text
FORM register_events .
Define the events which will be passed to the backend
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event.
CALL METHOD gd_tree->get_registered_events
IMPORTING
events = lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
l_event-appl_event = 'X'.
APPEND l_event TO lt_events.
CALL METHOD gd_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 x208(00) WITH 'ERROR'.
ENDIF.
Set Handler
DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->handle_item_double_click FOR gd_tree.
ENDFORM. " register_events
CLASS lcl_tree_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_item_double_click
FOR EVENT item_double_click OF cl_gui_alv_tree
IMPORTING node_key
fieldname.
ENDCLASS. "lcl_tree_event_receiver DEFINITION
CLASS lcl_tree_event_receiver IMPLEMENTATION.
METHOD handle_item_double_click.
DATA: lt_selected_nodes TYPE lvc_nkey,
lt_fieldname TYPE lvc_fname.
Determine which line is selected
CALL METHOD gd_tree->get_selected_item
IMPORTING
e_selected_node = lt_selected_nodes
e_fieldname = lt_fieldname.
CALL METHOD cl_gui_cfw=>flush.
SET PARAMETER ID 'IFL' FIELD lt_fieldname.
SET PARAMETER ID 'ISR' FIELD 'MOB01'.
CALL TRANSACTION 'IL03' AND SKIP FIRST SCREEN.
ENDMETHOD. "handle_item_double_click
ENDCLASS. "lcl_tree_event_receiver IMPLEMENTATIONHello Goh
Based on your coding you are using CL_GUI_ALV_TREE instead of CL_GUI_COLUMN_TREE.
Calling method get_selected_item within your event handler method is unnecessary because these data are already provided by the event interface.
[code]METHOD handle_item_double_click.
DATA: lt_selected_nodes TYPE lvc_nkey,
lt_fieldname TYPE lvc_fname.
*$Comment: unnecessary because these data are already provided
by the event interface (IMPORTING nodekey fieldname).
Determine which line is selected
**CALL METHOD gd_tree->get_selected_item
**IMPORTING
**e_selected_node = lt_selected_nodes
**e_fieldname = lt_fieldname.
ENDMETHOD. "handle_item_double_click[/code]
The following sample is based in report BCALV_TREE_04 but can be simply applied to your application:
[code] METHOD handle_item_double_click.
define local data
DATA:
ls_outtab TYPE sflight.
FIELD-SYMBOLS:
<ld_fld> TYPE ANY.
Call this method to get the values of the selected tree line
CALL METHOD g_alv_tree->get_outtab_line
EXPORTING
i_node_key = node_key
IMPORTING
e_outtab_line = ls_outtab
E_NODE_TEXT =
et_item_layout =
ES_NODE_LAYOUT =
EXCEPTIONS
node_not_found = 1
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.
ASSIGN COMPONENT fieldname OF STRUCTURE ls_outtab TO <ld_fld>.
IF ( <ld_fld> IS ASSIGNED ).
... Call transaction with selected (item) value.
ENDIF.
ENDMETHOD. "handle_item_double_click[/code]
The ASSIGN statement will work if no item of the hierarchy part is selected.
Regards
Uwe -
Unable to expand child links in ALV Tree
Hi,
I have written the following code for ALV Tree using function modules.
REPORT ZSID_ALV_TREE.
type pool declarations for tree
TYPE-POOLS : fibs,stree.
tables: ekko.
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
it_ekpo TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
it_emptytab TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko,
wa_ekpo TYPE t_ekko.
DATA:w_repid type sy-cprog.
*Data declaration for additional node information
DATA : t_node TYPE snodetext.
*Internal table and wa decl for nodes
DATA : it_node LIKE TABLE OF t_node INITIAL SIZE 0,
wa_node LIKE t_node.
*Start of selection event
START-OF-SELECTION.
*Select the data for tree
PERFORM fetch_data.
*Build the hierarchy for tree
PERFORM build_hierarchy.
*Build Tree for display
PERFORM build_tree.
*& Form fetch_data
text
--> p1 text
<-- p2 text
FORM fetch_data .
SELECT ebeln
up to 10 rows
FROM ekko
INTO corresponding fields of TABLE it_ekko .
loop at it_ekko into wa_ekko.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
FROM ekpo
appending TABLE it_ekpo
where ebeln eq wa_ekko-ebeln.
endloop.
endform.
*& Form build_hierarchy
text
--> p1 text
<-- p2 text
FORM build_hierarchy .
*Building the nodes and hierarchy for tree
CLEAR : it_node[], wa_node.
wa_node-type = 'T'.
wa_node-name = 'Product Hierarchy Level'.
wa_node-tlevel = '01'.
wa_node-nlength = '35'.
wa_node-color = '4'.
wa_node-text = 'Test'.
wa_node-tlength ='20'.
wa_node-tcolor = 3.
APPEND wa_node TO it_node.
CLEAR wa_node.
loop at it_ekpo into wa_ekpo.
wa_node-type = 'P'.
wa_node-name = 'Purchasing Doc'.
wa_node-tlevel = '02'.
wa_node-nlength = '25'.
wa_node-color = '4'.
wa_node-text = wa_ekpo-ebeln.
wa_node-tlength ='20'.
wa_node-tcolor = 3.
APPEND wa_node TO it_node.
CLEAR wa_node.
*Filling the values of internal table into tree
wa_node-type = 'P'.
wa_node-name = 'Material No'.
wa_node-tlevel = '03'.
wa_node-nlength = '20'.
wa_node-color = '1'.
wa_node-text = wa_ekpo-matnr.
wa_node-tlength ='20'.
wa_node-tcolor = 4.
APPEND wa_node TO it_node.
CLEAR wa_node.
ENDLOOP.
ENDFORM. " build_hierarchy
*& Form build_tree
text
--> p1 text
<-- p2 text
FORM build_tree .
*Fm for constructing the tree
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
nodetab = it_node.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
w_repid = SY-CPROG.
*FM for displaying the tree
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = w_repid
CALLBACK_USER_COMMAND = 'USER1_COMMAND'
CALLBACK_TEXT_DISPLAY =
CALLBACK_MOREINFO_DISPLAY =
CALLBACK_COLOR_DISPLAY =
CALLBACK_TOP_OF_PAGE =
CALLBACK_GUI_STATUS =
CALLBACK_CONTEXT_MENU =
STATUS = 'IMPLICIT'
CHECK_DUPLICATE_NAME = '0'
COLOR_OF_NODE = '4'
COLOR_OF_MARK = '3'
COLOR_OF_LINK = '1'
COLOR_OF_MATCH = '5'
LOWER_CASE_SENSITIVE = 'X'
MODIFICATION_LOG = 'X'
NODE_LENGTH = 40
TEXT_LENGTH = 75
TEXT_LENGTH1 = 0
TEXT_LENGTH2 = 0
RETURN_MARKED_SUBTREE = 'X'
SCREEN_START_COLUMN = 0
SCREEN_START_LINE = 0
SCREEN_END_COLUMN = 0
SCREEN_END_LINE = 0
SUPPRESS_NODE_OUTPUT = 'X'
LAYOUT_MODE = ' '
USE_CONTROL = 'L'.
IMPORTING
F15 =
ENDFORM. " build_tree
FORM USER1_COMMAND TABLES node STRUCTURE seucomm
USING command
CHANGING value(exit)
VALUE(LIST_REFRESH).
write 'Hi'.
endform.
But I have a problem
1. I can expand the child links in tree structure when I comment the exporting parameter CALLBACK_USER_COMMAND in the function Module 'RS_TREE_LIST_DISPLAY'.
2 But when i uncomment the exporting parameter I am unable to expand the child links in output.
Please let me know if i have missed something in the code.
Useful answers will be rewarded
Regards,
SiddharthHi Sidhhart,
Check out this prog.
REPORT Z_KULDEEP_ALV_HIERARCHY
message-id zord
line-size 270.
Tables:
Vbap,
Vbak.
*& PROGRAM VARIABLES
type-pools slis.
*& INTERNAL TABLES & STRUCTURES
data:
begin of t_header occurs 0,
EXPCOL type c,
vbeln type vbak-vbeln,
audat type vbak-audat,
vkorg type vbak-vkorg,
vtweg type vbak-vtweg,
spart type vbak-spart,
end of t_header,
begin of t_item occurs 0,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
arktx type vbap-arktx,
pstyv type vbap-pstyv,
end of t_item,
t_fieldcat type standard table of slis_fieldcat_alv with header line,
t_event type standard table of slis_alv_event with header line,
x_keyinfo type slis_keyinfo_alv,
x_layout type slis_layout_alv,
x_variant like disvariant.
*& GLOBAL VARIABLES
data:
g_repid type sy-repid,
g_formname type slis_formname value 'TOP_OF_PAGE'.
*& SELECTION SCREEN *
selection-screen begin of block a with frame title text-000.
Select-options : s_date for vbak-audat obligatory.
p_date type vbak-audat.
selection-screen end of block a.
*& INITIALIZATION *
initialization.
clear : g_repid,t_header,t_item.
refresh : t_header,t_item.
g_repid = sy-repid.
*& AT SELECTION-SCREEN *
at selection-screen.
if s_date-high > sy-datum.
message e001.
endif.
start-of-selection.
select vbeln audat vkorg vtweg spart from vbak
into corresponding fields of table t_header
where audat in s_date.
select vbeln posnr matnr arktx pstyv from vbap
into table t_item
for all entries in t_header
where vbeln = t_header-vbeln.
end-of-selection.
perform sub_display_alv.
*& Form sub_display_alv
text
--> p1 text
<-- p2 text
form sub_display_alv.
*column 1
perform sub_populate_fieldcatalog using:
'VBELN' " field name
'T_HEADER' " table name
'ORDER' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 2
perform sub_populate_fieldcatalog using:
'AUDAT' " field name
'T_HEADER' " table name
'ORDERDATE' " column heading
'10' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 3
perform sub_populate_fieldcatalog using:
'VKORG' " field name
'T_HEADER' " table name
'SALES ORG' " column heading
'6' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 4
perform sub_populate_fieldcatalog using:
'VTWEG' " field name
'T_HEADER' " table name
'DIVISION' " column heading
'2' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 5
perform sub_populate_fieldcatalog using:
'SPART' " field name
'T_HEADER' " table name
'CHANNEL' " column heading
'4' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 6
perform sub_populate_fieldcatalog using:
'vbeln' " field name
'T_item' " table name
'Order' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 7
perform sub_populate_fieldcatalog using:
'POSNR' " field name
'T_ITEM' " table name
'SALES DOC.ITEM' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 8
perform sub_populate_fieldcatalog using:
'MATNR' " field name
'T_ITEM' " table name
'MATERIAL' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 9
perform sub_populate_fieldcatalog using:
'ARKTX' " field name
'T_ITEM' " table name
'SALES ORDER ITEM' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 10
perform sub_populate_fieldcatalog using:
'PSTYV' " field name
'T_ITEM' " table name
'ITEM CATEGORY' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
perform sub_assign_events.
Create a Layout for the ALV
perform sub_layout.
Define the key fields that links the header & item tables
perform sub_define_key.
dispaly list
perform sub_call_list_display.
endform. " sub_display_alv
*& Form sub_populate_fieldcatalog
text
-->P_G_FIELDCAT text
-->P_0198 text
-->P_0199 text
-->P_0200 text
-->P_0201 text
-->P_0202 text
-->P_0203 text
-->P_0204 text
-->P_0205 text
-->P_0206 text
-->P_0207 text
-->P_0208 text
-->P_0209 text
-->P_0210 text
-->P_0211 text
-->P_0212 text
-->P_0213 text
form sub_populate_fieldcatalog using
l_fieldname
l_tabname
l_column_heading
l_outputlen
l_fix_column
l_key
l_no_out
l_do_sum
l_no_sum
l_input
l_cfieldname
l_datatype
l_hotspot.
t_fieldcat-fieldname = l_fieldname.
t_fieldcat-tabname = l_tabname.
t_fieldcat-reptext_ddic = l_column_heading.
t_fieldcat-outputlen = l_outputlen.
t_fieldcat-fix_column = l_fix_column.
t_fieldcat-key = l_key.
t_fieldcat-no_out = l_no_out.
t_fieldcat-do_sum = l_do_sum.
t_fieldcat-no_sum = l_no_sum.
t_fieldcat-cfieldname = l_cfieldname.
t_fieldcat-datatype = l_datatype.
t_fieldcat-hotspot = l_hotspot.
append t_fieldcat.clear t_fieldcat.
endform. " sub_populate_fieldcatalog
*& Form sub_assign_events
text
--> p1 text
<-- p2 text
form sub_assign_events.
refresh t_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 1
importing
et_events = t_event[]
exceptions
list_type_wrong = 1
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.
Read the record for the top-of-page event
read table t_event with key slis_ev_top_of_page.
if sy-subrc = 0.
t_event-form = g_formname.
append t_event.
endif.
endform. " sub_assign_events
*& Form SUB_LAYOUT
text
--> p1 text
<-- p2 text
form sub_layout.
clear x_layout.
x_layout-f2code = 'QUOTE'.
x_layout-zebra = 'X'.
x_layout-expand_fieldname = 'EXPCOL'. " Field for expand/collapse
*Stat
x_layout-colwidth_optimize = 'X'.
x_layout-no_totalline = 'X'. " 0001+
endform. " SUB_LAYOUT
*& Form SUB_DEFINE_KEY
text
--> p1 text
<-- p2 text
form sub_define_key.
clear x_keyinfo.
x_keyinfo-header01 = 'VBELN'.
x_keyinfo-item01 = 'VBELN'.
endform. " SUB_DEFINE_KEY
form top_of_page.
write :/10 sy-datum, 20 sy-pagno, 30 sy-uname.
endform.
form sub_user_command using f_ucomm like sy-ucomm
f_selfield type slis_selfield.
if f_ucomm = 'QUOTE'.
if f_selfield-fieldname = 'VBELN'.
Set Parameter id 'AUN' field f_selfield-value.
call transaction 'VA03'.
endif.
endif.
endform.
*& Form sub_call_list_display
text
--> p1 text
<-- p2 text
form sub_call_list_display.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
i_callback_program = g_repid
i_callback_user_command = 'SUB_USER_COMMAND '
is_layout = x_layout
it_fieldcat = t_fieldcat[]
i_save = 'A'
it_events = t_event[]
i_tabname_header = 'T_HEADER'
i_tabname_item = 'T_ITEM'
is_keyinfo = x_keyinfo
tables
t_outtab_header = t_header[]
t_outtab_item = t_item[]
exceptions
program_error = 1
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.
endform. " sub_call_list_display
Maybe you are looking for
-
"error occured while reading from device"
when trying to sync our itouches the device is initailly recongnized in itunes and will begin to sync , but never gets through the whole proccess - each time it gets to a different step, but always ends with error message "ipod cannot sync as an erro
-
IPOD NOT RECOGNIZED BY COMPUTER! :'( HELP PLZZ!
when i plug in my ipod the computer detects it as an "unknown device" and apparently the problem is that there is no driver installed for my ipod and its also not detected by my Itunes and updater! T_T helpp plz! its killing me and i've downloaded so
-
Albums created on mac not showing on iphone or ipad
I created an album on my mac photo app. How do I get this album to appear on my iphone and ipad? Upload to my photo stream and icloud photo library are active on all of my devices.
-
Non-static method getContentPane() cannot be referenced from a static conte
From this line I'm getting an error Container bmC = getContentPane(); - non-static method getContentPane() cannot be referenced from a static context Aprecciate solution, thx
-
Error in Data activation for ODS data load
We were succesfully loading data (delta load) so far for a CRM ODS. Suddenly, yesterday we are getting am error while trying to activate the data. - "No data packet numbers could be determined for request REQU_48C2T4S91I6GSJ4FNUE727M1Y- Message no. R