Adding checkboxes to columns in ALV
In this post, we will see how we can display checkboxes in a column in the ALV output.
The user may select a checkbox and switch it on or off. Then, based on his or her selection,
a button may be pressed and function executed. The primary emphasis of this recipe will be the display of checkboxes within a column and the coding to set it as on or off.
For this recipe, we will make a copy of the simple ALV program that was created in the following post
For adding a checkbox column to your ALV program, follow these steps:
1.Add a new field CHECKBOX to the type TY_PA0008 defined in your program.
The position of the field will determine the position of this column in the ALV
display. We will place it at the end.
2)Then, use the get_column method to get access to the CHECKBOX column. We will set the long , medium, and short texts of this column as Checkbox. The most important step is to set the cell type of this column to a checkbox using the method set_cell_type. The constant static attribute checkbox_hotspot of the interface if_salv_c_cell_type is passed.
3.A new class mycheckbox is defined, the definition of which contains a static method on_click_checkbox defined for the link_click event for the ALV events. This method imports the row and column of the user selection
4.Next, the implementation of the mycheckbox method is created. As already mentioned, this method is triggered when the user clicks on a particular checkbox for any row of the displayed ALV table. The read statement is used to determine which particular row’s checkbox has been clicked. The IF statement checks whether the checkbox field of the row in consideration is already on or off (meaning equal to ‘X’ or space). Depending on the current value, the value of the checkbox field is changed. A MODIFY statement is used to change the internal table IT_PA0008. Finally, the refresh method of the ALV object is called.
5)The SET HANDLER statement is used to register the static method on_click_checkbox method of the mycheckbox class for the ALV events.