02-09-2009 2:22 PM
Hi There,
I have developed a report using ALV tree with 3 level nodes. I have introduced checkbox in one of the column in the node..
By this I can select the checkbox individually. I have got the requirement to select all the checkboxes simultaneously using a button. I tried several things but no help..
Please help me with this..I have used class 'cl_gui_alv_tree' for designing the Tree.
02-09-2009 4:12 PM
Hi,
You need to add a button to the toolbar manually, when the button is pressed loop at all the nodes that have a checkbox and update the checkbox field.
Something like....
data: go_tree1 type ref to cl_gui_alv_tree,
go_toolbar type ref to cl_gui_toolbar
*-----------------------------------------------------------------------
* Add buttons to the toolbar
*-----------------------------------------------------------------------
call method go_tree1->get_toolbar_object
importing
er_toolbar = go_toolbar.
check go_toolbar is not initial.
call method go_toolbar->add_button
exporting
fcode = 'SELALL'
icon = icon_select_all
butn_type = cntb_btype_button
text = ''
quickinfo = 'Select All'.
*-----------------------------------------------------------------------
* Define an event handler
*-----------------------------------------------------------------------
data: go_receiver type ref to lcl_event_receiver.
class lcl_event_receiver definition.
public section.
methods:
function_selected for event function_selected of cl_gui_toolbar
importing fcode.
endclass.
class lcl_event_receiver implementation.
method function_selected.
case fcode.
when 'SELALL'.
perform select_all.
endmethod.
*-----------------------------------------------------------------------
* Register the event
*-----------------------------------------------------------------------
create object go_receiver.
set handler go_receiver->function_selected for go_toolbar.
form select_all.
data: lv_field type lvc_fname.
*-----------------------------------------------------------------------
* Update the checkbox on each node of the ALV tree
*-----------------------------------------------------------------------
lv_field = 'CHECK'. "Whatever you've called the checkbox
call method go_tree1->change_item
exporting
i_node_key = node_key "<-- loop at the nodes and repeat for each one with a checkbox
i_fieldname = lv_field
i_data = ' '
exceptions
node_not_found = 1
others = 2.
call method go_tree1->frontend_update. "call this onces all updates have been made
endform.
Regards,
Darren
02-09-2009 4:12 PM
Hi,
You need to add a button to the toolbar manually, when the button is pressed loop at all the nodes that have a checkbox and update the checkbox field.
Something like....
data: go_tree1 type ref to cl_gui_alv_tree,
go_toolbar type ref to cl_gui_toolbar
*-----------------------------------------------------------------------
* Add buttons to the toolbar
*-----------------------------------------------------------------------
call method go_tree1->get_toolbar_object
importing
er_toolbar = go_toolbar.
check go_toolbar is not initial.
call method go_toolbar->add_button
exporting
fcode = 'SELALL'
icon = icon_select_all
butn_type = cntb_btype_button
text = ''
quickinfo = 'Select All'.
*-----------------------------------------------------------------------
* Define an event handler
*-----------------------------------------------------------------------
data: go_receiver type ref to lcl_event_receiver.
class lcl_event_receiver definition.
public section.
methods:
function_selected for event function_selected of cl_gui_toolbar
importing fcode.
endclass.
class lcl_event_receiver implementation.
method function_selected.
case fcode.
when 'SELALL'.
perform select_all.
endmethod.
*-----------------------------------------------------------------------
* Register the event
*-----------------------------------------------------------------------
create object go_receiver.
set handler go_receiver->function_selected for go_toolbar.
form select_all.
data: lv_field type lvc_fname.
*-----------------------------------------------------------------------
* Update the checkbox on each node of the ALV tree
*-----------------------------------------------------------------------
lv_field = 'CHECK'. "Whatever you've called the checkbox
call method go_tree1->change_item
exporting
i_node_key = node_key "<-- loop at the nodes and repeat for each one with a checkbox
i_fieldname = lv_field
i_data = ' '
exceptions
node_not_found = 1
others = 2.
call method go_tree1->frontend_update. "call this onces all updates have been made
endform.
Regards,
Darren
02-10-2009 11:31 AM
Hi Darren,
Thansk for the reply and the code for select all checkbox..This code is really getting closer to the solution..
Now I have got the select all toolbar in ALV tree..I have added the code for the form select all as below:
I have captured all the node keys in the g_node_key and looping in it..But if debugged inside the call method, one of the table IS_ITEM_LAYOUT is empty becoz of which checkbox is not checked..
Please assist..
FORM select_all .
DATA: lv_field TYPE lvc_fname.
DATA: ld_nkey TYPE lvc_nkey.
*----
Update the checkbox on each node of the ALV tree
*----
lv_field = 'REVIEWED'. "Whatever you've called the checkbox
LOOP AT g_node_key INTO ld_nkey.
CALL METHOD g_alv_tree->change_item
EXPORTING
i_node_key = ld_nkey "<-- loop at the nodes and repeat for each one with a checkbox
i_fieldname = lv_field
i_data = ' '
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
CALL METHOD g_alv_tree->frontend_update. "call this onces all updates have been made
ENDLOOP.
ENDFORM. " SELECT_ALL
02-10-2009 11:58 AM
Hi Darren,
The select all checkbox worked well..Thankyou very much...
Now need help on deselect all..I have added the button in the toolbar...added the code but somehow it doesnt work..
02-10-2009 1:15 PM
Hi Arif,
I'm glad it was useful.
What part of the deselect isn't working?
Does it call the event when you press the button?
Darren
02-10-2009 2:49 PM
Hi Darren,
Yes it calls the event for deselect all..I have changed the chosen to space. However, when debugged, the code goes inside the method 'change_item' and again assigns the chosen as 'X' becoz the internal table 'mt_checked_items' has the check box values saved..
Please tell me if any other method to be used to make it work..
LOOP AT g_node_key INTO ld_nkey.
ls_item_layout-fieldname = 'REVIEWED'.
ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.
ls_item_layout-editable = ''.
ls_item_layout-alignment = cl_gui_column_tree=>align_center.
ls_item_layout-chosen = ''.
ls_item_layout-u_chosen = ''. " update field
CALL METHOD g_alv_tree->change_item.
EXPORTING
i_node_key = ld_nkey "<-- loop at the nodes and repeat for each one with a checkbox
i_fieldname = lv_field
i_data = ' '
is_item_layout = ls_item_layout
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
CALL METHOD g_alv_tree->frontend_update. "call this onces all updates have been made
ENDLOOP.
02-11-2009 4:21 PM
09-29-2010 12:41 PM
Hi arif,
I need your help on this.
Can you please help me
With Regards,
Sumodh.P
09-09-2014 3:02 PM
Hi!
I give same problem that solved included this small code:
CALL METHOD tree1->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subnodes.
LOOP AT lt_subnodes ASSIGNING <subnode>.
tree1->get_outtab_line( EXPORTING i_node_key = <subnode>
IMPORTING e_outtab_line = wa_new_outtab
et_item_layout = lt_item_layout ).
READ TABLE lt_item_layout INTO wa_item_layout INDEX 1.
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_item_layout TO wa_new_item_layout.
IF checked IS NOT INITIAL.
wa_new_item_layout-chosen = checked.
wa_new_item_layout-u_chosen = abap_true. <== determinate update flag
APPEND wa_new_item_layout TO lt_new_item_layout.
tree1->change_node( i_node_key = <subnode>
it_item_layout = lt_new_item_layout
i_outtab_line = wa_new_outtab ).
ELSE.
wa_new_item_layout-chosen = checked.
wa_new_item_layout-u_chosen = abap_true. <== determinate update flag
APPEND wa_new_item_layout TO lt_new_item_layout.
tree1->change_node( i_node_key = <subnode>
it_item_layout = lt_new_item_layout
i_outtab_line = wa_new_outtab ).
ENDIF.
ENDIF.
REFRESH lt_new_item_layout.
REFRESH lt_item_layout.
CLEAR: wa_new_item_layout, wa_item_layout.
ENDLOOP.