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: 

Select all checkboxes in ALV Tree simple

Former Member
0 Kudos

Hi,

We have created ALV Tree report using class "cl_gui_alv_tree_simple" and have one field as a checkbox. Now we are trying to achieve the Select all functionality in the same. However, when we set Checkbox field = ABAP_TRUE in internal table and call method "refresh_table_display" checkbox is not getting selected instead 'X' is showing near the Checkbox. If we try to achieve the deselect all functionality by setting Checkbox = ABAP_FALSE and then we call method "refresh_table_display" all the checkboxes selected get's deselect.

To make that field as a checkbox we are passing parameter "checkbox" = abap_true in field catalog which has type  lvc_s_fcat.

Regards,

Alex

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos

Hi,

the solution for checkboxes is not trivial. You need to call method CHANGE_LAYOUT of CL_GUI_ALV_TREE_SIMPLE to tick the checkbox (using both fields CLASS of value item_class_checkbox and CHOSEN to tick the checkbox), and you must let the field value to space (it's always interpreted as a label of the checkbox). I found the solution here: How to make checkbox to be pre-selected in ALV | SCN

Here is a full working example (first you must generate SBOOK entries using SAPBC_DATA_GENERATOR program):

REPORT.

DATA: gt_sbook TYPE TABLE OF sbook,
      gt_sort    TYPE lvc_t_sort,
      ls_sort    TYPE lvc_s_sort,
      gt_fcat    TYPE lvc_t_fcat,
      gs_fcat    TYPE lvc_s_fcat,
      go_tree    TYPE REF TO cl_gui_alv_tree_simple.
FIELD-SYMBOLS: <ls_sbook> TYPE sbook.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF go_tree IS NOT BOUND.
    SELECT * FROM sbook INTO CORRESPONDING FIELDS OF TABLE gt_sbook UP TO 100 ROWS.
    ls_sort-spos = 1.
    ls_sort-fieldname = 'CARRID'.
    ls_sort-up = 'X'.
    APPEND ls_sort TO gt_sort.
    ls_sort-spos = 2.
    ls_sort-fieldname = 'CONNID'.
    ls_sort-up = 'X'.
    APPEND ls_sort TO gt_sort.
    PERFORM get_fcat USING gt_sbook CHANGING gt_fcat.
    gs_fcat-checkbox = abap_true.
    MODIFY gt_fcat FROM gs_fcat TRANSPORTING checkbox WHERE fieldname = 'SMOKER'.
    CREATE OBJECT go_tree
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    CALL METHOD go_tree->set_table_for_first_display
      CHANGING
        it_sort         = gt_sort
        it_outtab       = gt_sbook
        it_fieldcatalog = gt_fcat.
    DATA ls_item_layout TYPE lvc_s_laci.
    DATA lt_item_layout TYPE lvc_t_laci.
    CLEAR ls_item_layout.
    ls_item_layout-fieldname = 'SMOKER'.
    ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.
    ls_item_layout-u_class = 'X'.
    ls_item_layout-chosen = 'X'.
    ls_item_layout-u_chosen = 'X'.
    APPEND ls_item_layout TO lt_item_layout.
    LOOP AT gt_sbook ASSIGNING <ls_sbook> WHERE smoker = 'X'.
      <ls_sbook>-smoker = ''.
      DATA l_outtab_index TYPE lvc_index.
      l_outtab_index = sy-tabix.
      go_tree->change_layout(
        EXPORTING
          i_outtab_index = l_outtab_index
          it_item_layout = lt_item_layout
        EXCEPTIONS
          node_not_found = 1 ).
      IF sy-subrc <> 0.
        " TODO
      ENDIF.
    ENDLOOP.
  ENDIF.
*
FORM get_fcat CHANGING it_std TYPE STANDARD TABLE et_fcat TYPE lvc_t_fcat.
  DATA lo_table TYPE REF TO cl_salv_table.
  DATA lo_columns TYPE REF TO cl_salv_columns_list.
  DATA lo_agg TYPE REF TO cl_salv_aggregations.
  REFRESH et_fcat.
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = lo_table
    CHANGING
      t_table      = it_std[].
  lo_columns = lo_table->get_columns( ).
  lo_agg = lo_table->get_aggregations( ).
  et_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns = lo_columns r_aggregations = lo_agg ).
ENDFORM.                    "get_fcat

0 Kudos

Hey, Sandra and Alex!

I'm very glad to see my 4 years old task and its solution still can help somebody

Nice example!

As I mentioned before the main rows in it are:

1)

ls_item_layout-u_class = 'X'.

    ls_item_layout-chosen = 'X'.

    ls_item_layout-u_chosen = 'X'.

and 2)

     go_tree->change_layout( ... )

Best regards,

Anton