‎2008 Nov 21 9:12 AM
Hallo everybody,
is there a function to display an ALV tree?
(as for alv grid we use REUSE_ALV_GRID_DISPLAY...)
Thank you very much indeed!
Mick
‎2008 Nov 21 9:38 AM
hi,
you can have a look at demo program BCALV_TREE_SIMPLE_DEMO.
also other sample code programs are,
BCALV_TREE_01
BCALV_TREE_02
BCALV_TREE_03
BCALV_TREE_DND_MULTIPLE
thanks,
‎2008 Nov 21 9:17 AM
‎2008 Nov 21 9:20 AM
Hello
There is no exist such function.
Look at reports
BCALV_TREE_01
BCALV_TREE_02
etc
for build tree.
‎2008 Nov 21 9:38 AM
hi,
you can have a look at demo program BCALV_TREE_SIMPLE_DEMO.
also other sample code programs are,
BCALV_TREE_01
BCALV_TREE_02
BCALV_TREE_03
BCALV_TREE_DND_MULTIPLE
thanks,
‎2008 Nov 21 9:48 AM
Hi,
You can reference the following link. It's a sample code. I think it will help you
[https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/callFMtogeneratealvtreeanddealwithuseraction]
Main step are as follows:
1. Get necessary data that you want to display
2. Generate the nodes of alv tree
3. Call FM 'RS_TREE_CONSTRUCT' to construct the tree
4. Define our own gui status. In the following example, I assign a function code 'DOUB' to F2 function key
5. Call FM 'RS_TREE_LIST_DISPLAY'. Here we need 'CALLBACK_USER_COMMAND' to process user action in the subroutine; 'CALLBACK_GUI_STATUS' to display self-defined gui status
6. In the subroutine 'USER_COMMAND', process user action. In the example I only give 3 functions
<1> Use FM 'RS_TREE_EXPAND' to expand the node list where user click
<2> Use FM 'RS_TREE_COMPRESS' to compress the node
<3> When user click the second level node, give a alv list about the detail info.
‎2008 Nov 21 9:53 AM
Hi
If you just want to display ALV tree, not to deal with user command, you can simply call the FM to
implement it. See the following Code
REPORT ZYH_TREE_CALL_LIST_ALV2.
TYPE-POOLS: slis, fibs, stree.
*-----------------------------------------------------------------------
* Explanation of these four tables. The relationship
* scarr Airline
* spfli Airplane
* sflight One Flight Schedule
* sbook Booking Flight
*-----------------------------------------------------------------------
* Type declare
TYPES:
BEGIN OF ty_scarr,
carrid TYPE s_carr_id,
END OF ty_scarr,
BEGIN OF ty_spfli,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
END OF ty_spfli,
BEGIN OF ty_sflight,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
fldate TYPE s_date,
END OF ty_sflight.
* Table type declare
TYPES:
ty_scarr_tab TYPE STANDARD TABLE OF ty_scarr,
ty_spfli_tab TYPE STANDARD TABLE OF ty_spfli,
ty_sflight_tab TYPE STANDARD TABLE OF ty_sflight.
* Define internal table
DATA:
i_scarr TYPE ty_scarr_tab,
i_spfli TYPE ty_spfli_tab,
i_sflight TYPE ty_sflight_tab,
w_node TYPE snodetext,
i_node TYPE STANDARD TABLE OF snodetext,
i_fieldcat TYPE slis_t_fieldcat_alv.
START-OF-SELECTION.
PERFORM get_data.
PERFORM build_tree.
PERFORM display_tree.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* Select data
*----------------------------------------------------------------------*
FORM get_data.
SELECT carrid
FROM scarr
INTO TABLE i_scarr.
SELECT carrid
connid
FROM spfli
INTO TABLE i_spfli
FOR ALL ENTRIES IN i_scarr
WHERE carrid = i_scarr-carrid.
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form build_tree
*&---------------------------------------------------------------------*
* Build Node of Tree
*----------------------------------------------------------------------*
FORM build_tree.
DATA:
w_scarr TYPE ty_scarr,
w_spfli TYPE ty_spfli.
CLEAR: i_node, w_node.
SORT: i_scarr BY carrid,
i_spfli BY carrid connid.
***************************************************************************
* Title node display in header
* node name style
w_node-type = 'T'. "T type
w_node-name = 'Flight Details'.
w_node-tlevel = '01'. "This level is hiberarchy level
w_node-nlength = '15'. "The space that the name of node occupy
w_node-color = '4'. "color of name of node
* node content style
w_node-text = 'Information About Flight(Node Text)'.
w_node-tlength = '50'.
w_node-tcolor = 3.
APPEND w_node TO i_node.
CLEAR w_node.
***************************************************************************
* First level node
LOOP AT i_scarr INTO w_scarr.
w_node-type = 'P'. "P type, real node
w_node-name = 'CARRID'. "Node text that will display
w_node-tlevel = '02'. "Hiberarchy level
w_node-nlength = '8'. "The space that name text will ocupy
w_node-color = '1'. "Node name text color
w_node-text = w_scarr-carrid. "Node content text
w_node-tlength = '20'. "Node content text space.
w_node-tcolor = 4. "Node content color
APPEND w_node TO i_node.
CLEAR w_node.
* Second level node
LOOP AT i_spfli INTO w_spfli WHERE carrid = w_scarr-carrid.
w_node-type = 'P'.
w_node-name = 'CONNID'.
w_node-tlevel = '03'.
w_node-nlength = '8'.
w_node-color = 1.
w_node-text = w_spfli-connid.
w_node-tlength = '20'.
w_node-color = 4.
APPEND w_node TO i_node.
CLEAR w_node.
ENDLOOP.
ENDLOOP.
ENDFORM. "build_tree
*&---------------------------------------------------------------------*
*& Form display_tree
*&---------------------------------------------------------------------*
* Display alv tree
*----------------------------------------------------------------------*
FORM display_tree.
* Construtor
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
nodetab = i_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.
* Display
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
callback_program = sy-repid
use_control = stree_use_list
.
ENDFORM. "display_tree
‎2008 Nov 21 10:27 AM
hi,
check this code
REPORT zdemo_alv_tree.
CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.
DATA tree1 TYPE REF TO cl_gui_alv_tree_simple.
DATA: gt_sflight TYPE sflight OCCURS 0, " Output-Table
gt_fieldcatalog TYPE lvc_t_fcat, " Field Catalog
gt_sort TYPE lvc_t_sort, " Sorting Table
ok_code LIKE sy-ucomm. " OK-Code
END-OF-SELECTION.
CALL SCREEN 100.
&----
*& Form BUILD_FIELDCATALOG
&----
This subroutine is used to build the field catalog for the ALV list
----
FORM build_fieldcatalog.
get fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = gt_fieldcatalog.
&----
*& Module PBO OUTPUT
&----
This subroutine is used to build the ALV Tree
----
MODULE pbo OUTPUT.
IF tree1 IS INITIAL.
PERFORM init_tree.
ENDIF.
SET PF-STATUS 'ZSTATUS'.
ENDMODULE. " PBO OUTPUT
&----
*& Form init_tree
&----
Building the ALV-Tree for the first time display
----
FORM init_tree.
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'.
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.
create tree control
CREATE OBJECT tree1
EXPORTING
i_parent = l_custom_container
i_node_selection_mode =
cl_gui_column_tree=>node_sel_mode_multiple
i_item_selection = 'X'
i_no_html_header = ''
i_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.
create hierarchy
CALL METHOD tree1->set_table_for_first_display
EXPORTING
it_list_commentary = lt_list_commentary
i_logo = l_logo
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
CHANGING
it_sort = gt_sort
it_outtab = gt_sflight
it_fieldcatalog = gt_fieldcatalog.
expand first level
CALL METHOD tree1->expand_tree
EXPORTING
i_level = 1.
optimize column-width
CALL METHOD tree1->column_optimize
EXPORTING
i_start_column = tree1->c_hierarchy_column_name
i_end_column = tree1->c_hierarchy_column_name.
ENDFORM. " init_tree
for more check this
saptechnical.com/Tutorials/ALV/ALVTreeDemo/ALVTreeDemo.htm
regards
Sachin