Mark checkboxes in ALV output grid as selected

E. Meco picture E. Meco · Sep 25, 2017 · Viewed 7.8k times · Source

I am creating an ALV output grid using class cl_gui_alv_grid. One of the columns of the output table is defined as a checkbox by using the corresponding record of the fieldcatalog:

ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.

enter image description here

For all the records of the column that contains the checkboxes, they are all set as unselected. My question is what logic can I implement in order that for some of the rows, the checkboxes to be set as selected when I display the ALV.

Answer

futu picture futu · Sep 25, 2017

If you want to set the checkbox according to initially shown data in the alv grid, just fill your outtab checkbox field with abap_true (='X') if condition is matched. If you would not use the checkbox parameter of the fieldcatalog you would just see 'X' for checked and ' ' for not checked.

If you want to set the checkbox according to user input, after they edited some fields in the alv grid, use the following alv grid events to change outtab:

METHODS:
      handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING er_data_changed,

      handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid, "executed only if no errors, outtab holds changed data

I also found some comments I made, when I had to deal with these events

*&---------------------------------------------------------------------*
*&      Method  handle_data_changed
*&---------------------------------------------------------------------*
*      raised when at least one cell is modified in the ALV
*     - modified entries are not stored in gt_outtab yet, but er_data_changed object
*     - mt_good_cells holds every changed field thats valid according to type declaration
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Method  handle_data_changed_finished
*&---------------------------------------------------------------------*
*      - raised when data validation is valid
*      - NOW outtab holds valid changed data
*----------------------------------------------------------------------*