04-13-2007 6:00 PM
Hi All
I am Displaying my output in Heirachycal ALV. It has checkbox at header and item level. I need a functionality that is user selects checkbox at header, all the line item checkboxes should get selected.
I need a event or something to catch the checkbox selection. Because checkbox selection doesnt fire user command..
Could you please hepl me on this issue.
Thanks.
04-13-2007 8:32 PM
Hello Sachin
The following coding shows how to mark/unmark checkboxes in an ALV tree (<b>CL_GUI_ALV_TREE</b>). The method handles event <b>CHECKBOX_CHANGE</b>.
METHOD handle_checkbox_change .
* define local data
DATA:
lw_child TYPE lvc_nkey,
lt_children TYPE lvc_t_nkey,
*
l_wa_outtab_line TYPE zfr_calc_marge_detail,
l_wa_item_layout TYPE lvc_s_layi,
lt_item_layout TYPE lvc_t_layi,
l_wa_item_layout_c TYPE lvc_s_laci,
lt_item_layout_c TYPE lvc_t_laci.
" The user marks or unmarks a checkbox on the ALV tree. The status
" (marked / unmarked) is "inherited" to the child nodes.
" Get sub-tree of selected node (i.e. the node where the checkbox was changed)
CALL METHOD sender->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_children.
" NOTE: the sender is the ALV tree instance
LOOP AT lt_children INTO lw_child.
REFRESH: lt_item_layout.
CLEAR: l_wa_outtab_line.
* Knoten und Item-Layout lesen
CALL METHOD sender->get_outtab_line
EXPORTING
i_node_key = lw_child
IMPORTING
e_outtab_line = l_wa_outtab_line
* E_NODE_TEXT =
et_item_layout = lt_item_layout
* 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.
READ TABLE lt_item_layout INTO l_wa_item_layout
WITH KEY fieldname = cl_gui_alv_tree=>c_hierarchy_column_name
class = cl_gui_column_tree=>item_class_checkbox.
IF ( syst-subrc = 0 ).
l_wa_item_layout-chosen = checked. " 'status' of changed checkbox
MODIFY lt_item_layout FROM l_wa_item_layout INDEX syst-tabix.
REFRESH: lt_item_layout_c.
LOOP AT lt_item_layout INTO l_wa_item_layout.
MOVE-CORRESPONDING l_wa_item_layout TO l_wa_item_layout_c.
l_wa_item_layout_c-u_chosen = 'X'. " update CHOSEN field
APPEND l_wa_item_layout_c TO lt_item_layout_c.
ENDLOOP.
CALL METHOD sender->change_node
EXPORTING
i_node_key = lw_child
i_outtab_line = l_wa_outtab_line
* IS_NODE_LAYOUT =
it_item_layout = lt_item_layout_c
* I_NODE_TEXT =
* I_U_NODE_TEXT =
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.
ENDIF.
ENDLOOP.
" Sending changes to the frontend
CALL METHOD sender->frontend_update.
ENDMETHOD.
Regards
Uwe
04-13-2007 8:32 PM
Hello Sachin
The following coding shows how to mark/unmark checkboxes in an ALV tree (<b>CL_GUI_ALV_TREE</b>). The method handles event <b>CHECKBOX_CHANGE</b>.
METHOD handle_checkbox_change .
* define local data
DATA:
lw_child TYPE lvc_nkey,
lt_children TYPE lvc_t_nkey,
*
l_wa_outtab_line TYPE zfr_calc_marge_detail,
l_wa_item_layout TYPE lvc_s_layi,
lt_item_layout TYPE lvc_t_layi,
l_wa_item_layout_c TYPE lvc_s_laci,
lt_item_layout_c TYPE lvc_t_laci.
" The user marks or unmarks a checkbox on the ALV tree. The status
" (marked / unmarked) is "inherited" to the child nodes.
" Get sub-tree of selected node (i.e. the node where the checkbox was changed)
CALL METHOD sender->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_children.
" NOTE: the sender is the ALV tree instance
LOOP AT lt_children INTO lw_child.
REFRESH: lt_item_layout.
CLEAR: l_wa_outtab_line.
* Knoten und Item-Layout lesen
CALL METHOD sender->get_outtab_line
EXPORTING
i_node_key = lw_child
IMPORTING
e_outtab_line = l_wa_outtab_line
* E_NODE_TEXT =
et_item_layout = lt_item_layout
* 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.
READ TABLE lt_item_layout INTO l_wa_item_layout
WITH KEY fieldname = cl_gui_alv_tree=>c_hierarchy_column_name
class = cl_gui_column_tree=>item_class_checkbox.
IF ( syst-subrc = 0 ).
l_wa_item_layout-chosen = checked. " 'status' of changed checkbox
MODIFY lt_item_layout FROM l_wa_item_layout INDEX syst-tabix.
REFRESH: lt_item_layout_c.
LOOP AT lt_item_layout INTO l_wa_item_layout.
MOVE-CORRESPONDING l_wa_item_layout TO l_wa_item_layout_c.
l_wa_item_layout_c-u_chosen = 'X'. " update CHOSEN field
APPEND l_wa_item_layout_c TO lt_item_layout_c.
ENDLOOP.
CALL METHOD sender->change_node
EXPORTING
i_node_key = lw_child
i_outtab_line = l_wa_outtab_line
* IS_NODE_LAYOUT =
it_item_layout = lt_item_layout_c
* I_NODE_TEXT =
* I_U_NODE_TEXT =
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.
ENDIF.
ENDLOOP.
" Sending changes to the frontend
CALL METHOD sender->frontend_update.
ENDMETHOD.
Regards
Uwe
05-30-2011 4:24 PM
Thanks a lot Uwe. The code works great.
This thread should be marked as resolved.
08-07-2011 5:54 PM
Thank you very much..the given code (with a small modification on the program specific types defined by you) works same as what I am looking for.
09-30-2011 2:49 PM
Hello Uwe , Im sorry but what does the variable checked means in your program , I moved a 'X' to it but once i click the check and is marked i can´t unmark the checkbox. could you help me please.?