‎2005 Jun 27 3:30 PM
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
‎2005 Jun 29 9:08 PM
Hi Gaurav,
Try BCALV_TREE_* and BCALVTREEGRID and you will get many examples.I am implementing the same which has got tree and grid combination.These examples will help you.
Regards,
Vijay
‎2005 Jun 27 3:37 PM
Hi Gaurav,
Below r the links which helps u in detail for creating a alv report using oops.
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://www.sapgenie.com/abap/controls/alvgrid.htm#Refresh%20grid%20display
sample example on alv tree....<b>BCALV_GRID_DND_TREE_SIMPLE</b>
REPORT BCALV_GRID_DND_TREE_SIMPLE.
* global data, tables, Constants, types
INCLUDE GRID_DND_TREE_SIMPLE_TOP.
* icons
INCLUDE <ICON>.
* event receiver ALV grid
INCLUDE GRID_DND_TREE_SIMPLE_01.
* event receiver ALV tree simple
INCLUDE GRID_DND_TREE_SIMPLE_02.
* forms for BCALV_GRID_DND_TREE_SIMPLE
INCLUDE GRID_DND_TREE_SIMPLE_F01.
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM INIT_DRAGDROP.
* table SPFLI
REFRESH GT_SPFLI.
SELECT * FROM SPFLI INTO TABLE GT_SPFLI.
* table SCARR
REFRESH GT_SCARR.
SELECT * FROM SCARR INTO TABLE GT_SCARR.
*
END-OF-SELECTION.
G_REPID = SY-REPID.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS '100'.
SET TITLEBAR '100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS '200'.
SET TITLEBAR '200'.
ENDMODULE. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module TREE_AND_DOCKING OUTPUT
*&---------------------------------------------------------------------*
MODULE TREE_AND_DOCKING OUTPUT.
IF CONTROLS_CREATED IS INITIAL.
* docking control
PERFORM CREATEDOCKINGCONTROL.
* tree control
PERFORM CREATETREECONTROL.
CONTROLS_CREATED = SELECTED.
ENDIF.
ENDMODULE. " TREE_AND_DOCKING OUTPUT
*&---------------------------------------------------------------------*
*& Module ALV_DISPLAY OUTPUT
*&---------------------------------------------------------------------*
MODULE ALV_DISPLAY OUTPUT.
IF G_CUSTOM_CONTAINER IS INITIAL.
* create container for ALV grid
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = 'CUSTOM_CONTROL'.
ENDIF.
IF GRID IS INITIAL.
* create Event Receiver
CREATE OBJECT EVENT_RECEIVER.
* build sort_tab_grid
PERFORM BUILD_SORT_TAB_GRID.
* create ALV grid
CREATE OBJECT GRID
EXPORTING
I_APPL_EVENTS = SELECTED "application event
I_PARENT = G_CUSTOM_CONTAINER.
* Dummy entry for D'n'D
CLEAR GT_SFLIGHT.
APPEND GT_SFLIGHT.
* opt. col. width
GS_LAYOUT_ALV-CWIDTH_OPT = SELECTED.
* handle for D'n'D
GS_LAYOUT_ALV-S_DRAGDROP-ROW_DDID = G_HANDLE_ALV.
* handler for ALV grid
SET HANDLER EVENT_RECEIVER->HANDLE_TOOLBAR_SET FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_USER_COMMAND FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_CONTEXT_MENU FOR GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_ONDROP FOR GRID.
* first call with dummy entry
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT_ALV
CHANGING IT_SORT = GT_SORT_GRID[]
IT_OUTTAB = GT_SFLIGHT[].
* flush
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
IF FLG_NEW = SELECTED.
CLEAR FLG_NEW.
* first call with data
GS_LAYOUT_ALV-GRID_TITLE = SCARR-CARRNAME.
CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT_ALV
CHANGING IT_SORT = GT_SORT_GRID[]
IT_OUTTAB = GT_SFLIGHT[].
* reset fields on screen 100
CLEAR SAPLANE.
* flush
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
ENDMODULE. " ALV_DISPLAY OUTPUT
*&---------------------------------------------------------------------*
*& Module OK_CODE INPUT
*&---------------------------------------------------------------------*
MODULE OK_CODE INPUT.
SAVE_OK_CODE = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK_CODE.
* Exit program
WHEN FCODE_BACK OR
FCODE_END OR
FCODE_ESC.
CALL METHOD GRID->FREE.
CALL METHOD TREE1->FREE.
CALL METHOD G_CUSTOM_CONTAINER->FREE.
LEAVE PROGRAM.
WHEN OTHERS.
CALL METHOD CL_GUI_CFW=>DISPATCH.
ENDCASE.
ENDMODULE. " OK_CODE INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
SAVE_OK_CODE = OK_CODE.
CLEAR OK_CODE.
* leave screen 200
IF SAVE_OK_CODE = FCODE_ENTR OR
SAVE_OK_CODE = FCODE_ESC.
SET SCREEN 0. LEAVE SCREEN.
ENDIF.
ENDMODULE. " USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
*& Module HIDE_SAPLANE OUTPUT
*&---------------------------------------------------------------------*
MODULE HIDE_SAPLANE OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'F01' AND SAPLANE IS INITIAL.
SCREEN-ACTIVE = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMODULE. " HIDE_SAPLANE OUTPUT
regards,
venu.
‎2005 Jun 27 4:24 PM
Some ALV tree sample for you in the OO way.
try to find the sap sample program BCALV_TREE_XX
These are serial samples for ALV tree.
Hope it will be helpful
‎2005 Jun 27 6:58 PM
Hi Zhenglin,
Do I need populate data myself as the examples you have mentioned show the basic structure without any data.
Thanks,
Gaurav
‎2005 Jun 28 3:10 AM
Hi, I just mean you can reference those sample code to understand how to create, initial and register event handle of the ALV_TREE.
The ALV_TREE has some difference between the ALV_GRID in OO programming, especially in some of the GUI effect.
‎2005 Jun 28 5:23 AM
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.
‎2005 Jun 29 9:08 PM
Hi Gaurav,
Try BCALV_TREE_* and BCALVTREEGRID and you will get many examples.I am implementing the same which has got tree and grid combination.These examples will help you.
Regards,
Vijay
‎2005 Jun 29 9:43 PM
‎2005 Jun 30 5:08 AM
Hi,
If u have found solution please reward points and close the thread. Hope the documents that i sent through mail might be helpful.
Thanks & Regards,
Judith.
‎2014 Dec 11 7:10 AM
Hello.
Answering your question, that post you refer to, have two things missing:
1. Sentence "CALL METHOD obj_tree->frontend_update." of the ALV Tree class, after calling "CALL METHOD cl_gui_cfw=>flush." (please create proper module and forms to do this).
2. Structure name on the corresponding "set_table_for_first_display" method of tree object (thus, this is not mandatory).
I know its a very old post, but I guess people still read it, you did not share the answer, but just emailed it (not very nice of you guys).
I hope my late reply does help others with this same problem.
By the way, the post Im talking about, is this one (the one from the original post):
http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htm
See you around.