- SAP ABAP Advanced Cookbook
- Rehan Zaidi
- 554字
- 2021-08-05 18:21:56
Adding checkboxes to columns
In this recipe, 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.
Getting ready
For this recipe, we will make a copy of the simple ALV program that was created in the beginning of the chapter. We will then add the checkbox-related coding to this copy.
How to do it...
For adding a checkbox column to your ALV program, follow these steps:
- Add a new field
CHECKBOX
to the typeTY_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. - Then, use the
get_column
method to get access to theCHECKBOX
column. We will set the long , medium, and short texts of this column asCheckbox
. The most important step is to set the cell type of this column to a checkbox using the methodset_cell_type
. The constant static attributecheckbox_hotspot
of the interfaceif_salv_c_cell_type
is passed. - A new class
mycheckbox
is defined, the definition of which contains a static methodon_click_checkbox
defined for thelink_click
event for the ALV events. This method imports the row and column of the user selection. - 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. Theread
statement is used to determine which particular row's checkbox has been clicked. TheIF
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. AMODIFY
statement is used to change the internal tableIT_PA0008
. Finally, therefresh
method of the ALV object is called. - The
SET HANDLER
statement is used to register the static methodon_click_checkbox
method of themycheckbox
class for the ALV events.
How it works...
When the program is run, the set_cell_type
method results in the CHECKBOX
column to be displayed with editable checkboxes. The set_short_text
, set_medium_text
, and set_long_text
methods display the heading of this column as Checkbox.

When the user clicks a particular checkbox, the on_click_checkbox
method is executed. The READ
statement gets the selected row using the parameter row
. If the value of the CHECKBOX
field of the selected row is found to be initial (meaning, checkbox off), it is assigned 'X'
(that is, switched on). Otherwise, if it is already on, the CHECKBOX
field is cleared (that is, switched off).
The table IT_PA0008
that is linked to ALV display is modified in order to reflect the user's selection. Finally, the refresh
method is called to display the new state of the checkboxes on the user screen.
There's more...
Apart from the CHECKBOX
display, there are other possibilities of a particular column. For the set_cell_type
method, the various possible values supplied for the value
parameter and the relevant output is shown as follows:

- 金融保險集團內部審計創新與實踐
- 會計信息化基礎(金蝶版)
- 審計綜合模擬實訓
- 中國特色社會主義國家審計制度研究
- Big Data Visualization
- Salesforce Essentials for Administrators
- 從零開始學房地產會計
- Programming Microsoft Dynamics NAV(Fifth Edition)
- 企業并購審查中的相關市場界定:理論與案例
- Getting Started with Microsoft Lync Server 2013
- 企業內部審計全流程指南
- Business Intelligence Cookbook:A Project Lifecycle Approach Using Oracle Technology
- 內部審計情景案例:理解審計行為,辨析審計決策
- Building Dashboards with Microsoft Dynamics GP 2016(Second Edition)
- QlikView for Developers Cookbook