Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Catch Checkbox in Heirachycal ALV

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

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

4 REPLIES 4

uwe_schieferstein
Active Contributor
0 Kudos

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

0 Kudos

Thanks a lot Uwe. The code works great.

This thread should be marked as resolved.

0 Kudos

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.

0 Kudos

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.?