Multi level tree ALV with CL_GUI_LIST_TREE


DATA :    lr_cust TYPE REF TO cl_gui_custom_container,
lr_list_tree TYPE REF TO cl_gui_list_tree,
lt_flight TYPE TABLE OF scarr,
ls_flight TYPE scarr,
lt_spfli TYPE TABLE OF spfli,
ls_spfli TYPE spfli,
lt_node TYPE  treev_ntab,
ls_node TYPE LINE OF treev_ntab,
lt_item TYPE TABLE OF mtreeitm,
ls_item TYPE mtreeitm .

START-OF-SELECTION.
CALL SCREEN 0001.
*&———————————————————————*
*&      Module  STATUS_0001  OUTPUT
*&———————————————————————*
MODULE status_0001 OUTPUT.
SET PF-STATUS ‘LIST_STATUS’.
ENDMODULE.                 ” STATUS_0001  OUTPUT
*&———————————————————————*
*&      Module  GET_DATA  OUTPUT
*&———————————————————————*
MODULE get_data OUTPUT.
IF lt_flight IS INITIAL.
SELECT FROM scarr INTO TABLE lt_flight.
IF lt_flight IS NOT INITIAL.
SELECT FROM spfli INTO TABLE lt_spfli FOR ALL ENTRIES IN lt_flight
WHERE carrid lt_flightcarrid.
ENDIF.
ENDIF.
ENDMODULE.                 ” GET_DATA  OUTPUT
*&———————————————————————*
*&      Module  BUILD_LIST_TREE  OUTPUT
*&———————————————————————*
MODULE build_list_tree OUTPUT.
IF lr_cust IS NOT BOUND.
CREATE OBJECT lr_cust
EXPORTING
container_name ‘LIST_TREE’
repid          syrepid
dynnr          sydynnr.
ENDIF.

IF lr_list_tree IS NOT BOUND.
CREATE OBJECT lr_list_tree
EXPORTING
parent                      lr_cust
node_selection_mode         cl_gui_list_tree=>node_sel_mode_single
*       hide_selection              =     ” Visibility of Selection
item_selection              ‘X’  ” Can Individual Items be Selected?
with_headers                ‘ ‘    ” ‘X’: With Headers
*       hierarchy_header            =     ” Hierarchy Header
*       list_header                 =     ” List Header
*       name                        =     ” Name
EXCEPTIONS
lifetime_error              1
cntl_system_error           2
create_error                3
illegal_node_selection_mode 4
failed                      5
OTHERS                      6.
ENDIF.

IF lr_list_tree IS BOUND.
* Building Root Node
ls_nodenode_key ‘Flight’.
ls_nodehidden ‘ ‘.
ls_nodehidden ‘ ‘.
ls_nodeisfolder ‘X’.
APPEND ls_node TO lt_node.
* Building sub node and relationship with root node
LOOP AT  lt_flight INTO ls_flight.
ls_nodenode_key ls_flightcarrid.
ls_noderelatkey ‘Flight’.
ls_noderelatship cl_gui_list_tree=>relat_last_child.
ls_nodeisfolder ‘X’.
APPEND ls_node TO lt_node.
LOOP AT lt_spfli INTO ls_spfli WHERE carrid ls_flightcarrid.
ls_nodenode_key ls_spfliconnid.
ls_noderelatkey ls_flightcarrid.
ls_noderelatship cl_gui_list_tree=>relat_last_child.
ls_nodeisfolder ‘X’.
APPEND ls_node TO lt_node.
ENDLOOP.
ENDLOOP.
* Building root Node Text
ls_itemnode_key ‘Flight’.
ls_itemitem_name ‘1’.
ls_itemclass cl_gui_list_tree=>item_class_text.
ls_itemalignment cl_gui_list_tree=>align_auto.
ls_itemfont cl_gui_list_tree=>item_font_prop.
ls_itemtext ‘Flight_Info’.
APPEND ls_item TO lt_item.
* Bulding all Item node text
LOOP AT  lt_flight INTO ls_flight.
ls_itemnode_key ls_flightcarrid.
ls_itemitem_name ‘1’.
ls_itemclass cl_gui_list_tree=>item_class_text.
ls_itemalignment cl_gui_list_tree=>align_auto.
ls_itemfont cl_gui_list_tree=>item_font_prop.
ls_itemtext ls_flightcarrname.
APPEND ls_item TO lt_item.
LOOP AT lt_spfli INTO ls_spfli WHERE carrid ls_flightcarrid.
ls_itemnode_key ls_spfliconnid.
ls_itemitem_name ‘1’.
ls_itemclass cl_gui_list_tree=>item_class_text.
ls_itemalignment cl_gui_list_tree=>align_auto.
ls_itemfont cl_gui_list_tree=>item_font_prop.
CONCATENATE ls_spflicountryfr ‘-‘ ls_spflicityfrom ‘-‘
ls_spflicountryto ‘-‘ ls_spflicityto INTO ls_itemtext.

APPEND ls_item TO lt_item.

ENDLOOP.
ENDLOOP.

CALL METHOD lr_list_tree->add_nodes_and_items
EXPORTING
node_table                     lt_node
item_table                     lt_item
item_table_structure_name      ‘MTREEITM’
EXCEPTIONS
failed                         1
cntl_system_error              2
error_in_tables                3
dp_error                       4
table_structure_name_not_found 5
OTHERS                         6.

ENDIF.
ENDMODULE.                 ” BUILD_LIST_TREE  OUTPUT
*&———————————————————————*
*&      Module  USER_COMMAND_0001  INPUT
*&———————————————————————*
*       text
*———————————————————————-*
MODULE user_command_0001 INPUT.
CASE syucomm.
WHEN ‘BACK’ OR ‘EXIT’ OR ‘CANCEL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.                 ” USER_COMMAND_0001  INPUT


Execute.


 

 

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s