‎2007 Dec 28 12:52 PM
Hi ,
I new to ALV tree. There is an Tree ALV displayed in the output. Behind the node there is a check box for each node and also for the each line item of that node. when the user click on the check box of that node all the lineitem of that particular node need to checked and all the line item data has to be captureed. I have added the check box behind the node as well as line item of that node. when user select the node
how the line item will be selected automatically and how do i capture that selected line item, Please suggest me or send me some sample of code.
emmidiate help will be appreciated.
Regards,
Priyaranjan
‎2007 Dec 28 9:07 PM
Hello Priyaranjan
The following coding was used in a modified version of sample report BCALV_TREE_DEMO where I added a checkbox to each displayed line in the ALV tree.
The event handler method HANDLE_CHECKBOX_CHANGE (event CHECKBOX_CHANGE) looks like this:
METHOD handle_checkbox_change.
BREAK-POINT.
DATA: ld_nkey TYPE lvc_nkey.
DATA: lt_nodes TYPE lvc_t_nkey.
DATA: ld_ntext TYPE lvc_value,
ls_item_u TYPE lvc_s_laci,
ls_item TYPE lvc_s_layi,
lt_items TYPE lvc_t_layi.
ld_nkey = node_key.
" Get subtree of selected node (including selected node)
CALL METHOD tree1->get_subtree
EXPORTING
i_node_key = ld_nkey
IMPORTING
et_subtree_nodes = lt_nodes.
LOOP AT lt_nodes INTO ld_nkey.
CALL METHOD tree1->get_outtab_line
EXPORTING
i_node_key = ld_nkey
IMPORTING
E_OUTTAB_LINE =
e_node_text = ld_ntext
et_item_layout = lt_items
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.
LOOP AT lt_items INTO ls_item
WHERE ( class = cl_gui_column_tree=>item_class_checkbox
AND editable = 'X' ).
CLEAR: ls_item_u.
MOVE-CORRESPONDING ls_item TO ls_item_u.
ls_item_u-chosen = checked. " mark checkbox
ls_item_u-u_chosen = 'X'. " do update of checkbox
CALL METHOD tree1->change_item
EXPORTING
i_node_key = ld_nkey
i_fieldname = tree1->c_hierarchy_column_name
i_data = ' '
i_u_data = ' '
is_item_layout = ls_item_u
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.
ENDLOOP. " items of a single node
ENDLOOP. " nodes
update frontend
CALL METHOD tree1->frontend_update.
ENDMETHOD. "handle_checkbox_change
Basically you should be able to Cut&Paste this coding and it will work on your ALV tree (CL_GUI_ALV_TREE).
Do not forget to register the required event and set the event handler:
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.
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 l_event_receiver->handle_checkbox_change FOR tree1.
Regards,
Uwe
‎2007 Dec 31 8:12 AM
Hi Uwe,
Thanks for your immediate response. Now when i check the node of the check box the line items of that node are automatically selected. But when i try to deselect the node it is not working . Kindly Suggest me .
Regards,
Priyaranjan
‎2008 Jan 03 6:51 AM
Hi Uwe,
when the user select the node check box the line items of that node are automatically selected and i could capture the data which has been selected. But i when i try to deselect the node checkbox, only the node check box is deselected not the line items of that node. I have copied your code and paist in my code it is working for selection, not for deselection of the node. Please suggest me asap as it is urgent for me.
Regards,
Priyaranjan
‎2008 Jan 03 3:29 PM
Hi,
Below is my code.
----
CLASS lcl_tree_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_checkbox_change
FOR EVENT checkbox_change OF cl_gui_alv_tree
IMPORTING node_key.
ENDCLASS.
CLASS lcl_tree_event_receiver IMPLEMENTATION.
METHOD handle_checkbox_change.
DATA: ld_nkey TYPE lvc_nkey.
DATA: lt_nodes TYPE lvc_t_nkey.
DATA: ld_ntext TYPE lvc_value,
ls_item_u TYPE lvc_s_laci,
ls_item TYPE lvc_s_layi,
lt_items TYPE lvc_t_layi.
ld_nkey = node_key.
" Get subtree of selected node (including selected node)
CALL METHOD tree1->get_subtree
EXPORTING
i_node_key = ld_nkey
IMPORTING
et_subtree_nodes = lt_nodes.
LOOP AT lt_nodes INTO ld_nkey.
CALL METHOD tree1->get_outtab_line
EXPORTING
i_node_key = ld_nkey
IMPORTING
E_OUTTAB_LINE =
e_node_text = ld_ntext
et_item_layout = lt_items
ES_NODE_LAYOUT =
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT lt_items INTO ls_item
WHERE ( class = cl_gui_column_tree=>item_class_checkbox
AND editable = 'X' ).
CLEAR: ls_item_u.
MOVE-CORRESPONDING ls_item TO ls_item_u.
IF ls_item_u-chosen = ' '.
ls_item_u-chosen = 'X'. " mark checkbox
ls_item_u-u_chosen = ' '. " do update of checkbox
ELSE.
ls_item_u-u_chosen = 'X'.
ls_item_u-u_editable = 'X'.
ENDIF.
CALL METHOD tree1->change_item
EXPORTING
i_node_key = ld_nkey
i_fieldname = tree1->c_hierarchy_column_name
i_data = ' '
i_u_data = 'X'
is_item_layout = ls_item_u
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP. " items of a single node
ENDLOOP. " nodes
gt_nodes[] = lt_nodes[].
REFRESH lt_nodes.
update frontend
CALL METHOD tree1->frontend_update.
ENDMETHOD. "handle_checkbox_change
end of Change-------
ENDCLASS.
Problem:
Here if i check the node the line items of that node are automatically selected, but when i deselect the node, the line items of that node are not deselected, only the node is deselected.
i tried a lot many ways to solve this problem, but not able to do that. Please suggest me to achieve this functionality.
Regards,
Priyaranjan
‎2007 Dec 31 11:26 AM
Hi
You can use the class CL_GUI_ALV_TREE and method SET_TABLE_FOR_FIRST_DISPLAY.
By performing a where used list on this - it would return sample and demo programs.
SAP also provides demo programs as follows:
BCALV_TEST_SIMPLE_TREE
BCALV_TREE_01
BCALV_TREE_02
BCALV_TREE_03
BCALV_TREE_04
BCALV_TREE_05
BCALV_TREE_06
BCALV_TREE_DEMO
BCALV_TREE_DND
They are easy to follow and if you dont have any complications can even reuse exact code from those programs.
Hope this helps.
http://www.sapdev.co.uk/reporting/alv/alvtree.htm
with regards,
Hema Sundara.