2013 Aug 27 1:12 PM
Hi Experts,
I have a requirement wherein I want to display Districts as Nodes and their respective Cities as the Child of those nodes. I am able to create whole program by referring SAPTLIST_TREE_CONTROL_DEMO.
But my program is getting hanged just after execution of ENDMODULE statement of PBO and unable to debug beyond that. Below is the development I have undertaken. Please check and let me know where I am mistaken.
Program Details:
1. ZSD_CDTMP is table containing 2 fields City and District
2. CC9403 is Custom Container placed on Screen 100.
*&---------------------------------------------------------------------*
*& Report ZTEST_LISTTREE
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_LISTTREE.
DATA:
GR_CONT9403 TYPE REF TO cl_gui_custom_container,
gr_tree9403 TYPE REF TO cl_gui_list_tree,
gt_node9403 TYPE TREEV_NTAB,
gt_item9403 TYPE STANDARD TABLE OF TREEV_ITEM INITIAL SIZE 0.
CONSTANTS: gcon_cc9403(10) TYPE c VALUE 'CC9403'.
CLASS gcl_event_handler9403 DEFINITION.
PUBLIC SECTION.
methods:
handle_link_click
FOR EVENT link_click of cl_gui_list_tree
IMPORTING node_key item_name.
ENDCLASS.
START-OF-SELECTION.
set SCREEN 100.
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS '0100'.
PERFORM f_display_report9403.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'. LEAVE to SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_REPORT9403
*&---------------------------------------------------------------------*
FORM f_display_report9403 .
data: ls_event TYPE cntl_simple_event,
lt_Events TYPE cntl_simple_events.
if gr_cont9403 is NOT BOUND.
CREATE OBJECT gr_cont9403
EXPORTING
container_name = gcon_cc9403
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.
CREATE OBJECT gr_tree9403
EXPORTING
parent = gr_cont9403
node_selection_mode = CL_GUI_LIST_TREE=>NODE_SEL_MODE_SINGLE
item_selection = 'X'
with_headers = space
EXCEPTIONS
lifetime_error = 1
cntl_system_error = 2
create_error = 3
illegal_node_selection_mode = 4
failed = 5
others = 6.
IF sy-subrc = 0.
CLEAR ls_Event.
ls_event-eventid = cl_gui_list_tree=>eventid_link_click.
ls_event-appl_event = 'X'.
APPEND ls_event to lt_events.
CALL METHOD gr_tree9403->set_registered_events
EXPORTING
events = lt_Events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3
others = 4.
IF sy-subrc = 0.
ENDIF.
PERFORM prepare_tree.
CALL METHOD gr_tree9403->add_nodes_and_items
EXPORTING
node_table = gt_node9403
item_table = gt_item9403
item_table_structure_name = 'ZSD_GENPAR3'
EXCEPTIONS
failed = 1
cntl_system_error = 2
error_in_tables = 3
dp_error = 4
table_structure_name_not_found = 5
others = 6.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
ENDIF.
endif.
ENDFORM. " F_DISPLAY_REPORT9403
*&---------------------------------------------------------------------*
*& Form PREPARE_TREE
*----------------------------------------------------------------------*
FORM prepare_tree .
TYPES: BEGIN OF lty_s_citydist,
district type AD_CITY2,
city TYPE AD_CITY1,
END OF lty_s_citydist.
data: ls_citydist TYPE lty_s_citydist,
lt_citydist TYPE STANDARD TABLE OF lty_s_citydist INITIAL SIZE 0,
ls_item TYPE ZSD_GENPAR3,
lv_root(20) TYPE c,
lv_flag TYPE c.
SELECT * from ZSD_CDTMP INTO CORRESPONDING FIELDS OF TABLE lt_citydist.
IF sy-subrc = 0.
sort lt_citydist by district.
LOOP AT lt_citydist INTO ls_citydist.
at NEW district.
lv_root = ls_citydist-district.
PERFORM create_node USING ls_citydist-district space 'X'.
PERFORM create_item USING ls_citydist-district.
lv_flag = 1.
endat.
if lv_flag = 1.
clear lv_flag.
endif.
PERFORM create_node USING ls_citydist-city lv_root space.
PERFORM create_item USING ls_citydist-city.
ENDLOOP.
ENDIF.
ENDFORM. " PREPARE_TREE
*&---------------------------------------------------------------------*
*& Form CREATE_NODE
*&---------------------------------------------------------------------*
FORM create_node USING uv_key TYPE any
uv_relatkey TYPE any
uv_folder TYPE any.
data ls_node TYPE treev_node.
ls_node-node_key = uv_key.
ls_node-isfolder = uv_folder.
if uv_relatkey IS NOT INITIAL.
ls_node-relatkey = uv_relatkey.
ls_node-relatship = cl_gui_list_tree=>relat_last_child.
endif.
APPEND ls_node to gt_node9403.
ENDFORM. " CREATE_NODE
*&---------------------------------------------------------------------*
*& Form CREATE_ITEM
*&---------------------------------------------------------------------*
FORM create_item USING uv_key TYPE any.
data: ls_item TYPE ZSD_GENPAR3.
ls_item-node_key = uv_key.
ls_item-item_name = '1'.
ls_item-class = CL_GUI_LIST_TREE=>item_class_text.
ls_item-alignment = CL_GUI_LIST_TREE=>align_auto.
ls_item-font = CL_GUI_LIST_TREE=>item_font_prop.
ls_item-text = uv_key.
APPEND ls_item to gt_item9403.
ENDFORM. " CREATE_ITEM
*&---------------------------------------------------------------------*
*& Class (Implementation) gcl_event_handler9403
*&---------------------------------------------------------------------*
CLASS gcl_event_handler9403 IMPLEMENTATION.
METHOD handle_link_click.
ENDMETHOD.
ENDCLASS. "gcl_event_handler9403
2013 Aug 28 6:15 AM
Hi,
Try passing standard structure 'MTREEITM' to item_table_structure_name.
There is no need to create a custom one.
Debug and check content of internal tables gt_node9403 and gt_item9403.
Have to create a Root node FIRST and then add nodes for each District.
There can be only ONE Root node.
** Add root node here (outside loop)
PERFORM create_node USING ls_citydist-district space 'X'.
LOOP AT lt_citydist INTO ls_citydist.
at NEW district.
***** add district node
endat.
at new city.
****** add item
endat.
ENDLOOP
Regards,
Nisha Vengal.
2013 Aug 28 6:15 AM
Hi,
Try passing standard structure 'MTREEITM' to item_table_structure_name.
There is no need to create a custom one.
Debug and check content of internal tables gt_node9403 and gt_item9403.
Have to create a Root node FIRST and then add nodes for each District.
There can be only ONE Root node.
** Add root node here (outside loop)
PERFORM create_node USING ls_citydist-district space 'X'.
LOOP AT lt_citydist INTO ls_citydist.
at NEW district.
***** add district node
endat.
at new city.
****** add item
endat.
ENDLOOP
Regards,
Nisha Vengal.
2013 Aug 28 7:51 AM
Hi Nisha,
Thanks for the solution. It worked with MTREEITM and ONE Root Node.
Additional Requirement: I want to display checkbox against each District Node and their Cities. I found that there is Method to handle check box in CL_GUI_LIST_TREE. But dint understand how can I utilize that to achieve my requirement. Can you please help me with this?
P.S: I was using new custom structure because it's mentioned in SAP sample program to not use MTREEITM and developer should create new structure. Hope we using MTREEITM will not create any issue later.
2013 Aug 28 10:12 AM
Hi,
Similar to how you have appended event LINK_CLICK, you will need to append event CHECKBOX_CHANGE.
You have already called SET_REGISTERED_EVENTS method, as needed.
Then write SET HANDLER statement (It will associate Event class object to Tree object ).
Then write Class method definition & implementation.
Regards,
Nisha Vengal.
2013 Aug 28 10:33 AM
2013 Aug 28 10:36 AM
Hi,
Suppose you need a checkbox against City.
In ITEMS table,
* city
ls_item-node_key = ...
ls_item-item_name = ...
ls_item-class = CL_GUI_LIST_TREE=>item_class_text.
ls_item-alignment = CL_GUI_LIST_TREE=>align_auto.
ls_item-font = CL_GUI_LIST_TREE=>item_font_prop.
ls_item-text = uv_key.
APPEND ls_item to gt_item9403.
* checkbox
clear: ls_item.
ls_item-node_key = ... " same as for city
ls_item-item_name = 'CB' "any name
ls_item-class = CL_GUI_LIST_TREE=>item_class_checkbox. "checkbox
ls_item-editable = 'X'. "editable
APPEND ls_item to gt_item9403.
In CLASS:
DEFINITION:
perform handle_checkbox_change
using node_key item_name.
IMPLEMENTATION:
Data: it_output type standard table of mtreeitm,
lwa_output type mtreeitm.
Read table it_output into lwa_output
with key node_key = node_key
item_name = item_name.
Check the value of lwa_output-chosen and proceed with your logic.
Regards,
Nisha Vengal.
2013 Aug 28 11:44 AM
Hi Manish,
Even if it's for fun, I am putting my efforts in learning new concepts.
To answer your question, I am not building List Tree for fun. But yes, it was fun working with it