Alv Grid List Using Radio Buttons
Alv Grid List Using Radio Buttons
Summary
The program shows how to define radio buttons in ALV grid lists.
Author(s): Uwe Schieferstein
Company: Cirrus Consulting AG, Switzerland
Created on: 11 January 2007
Author Bio
Uwe Schieferstein has 8 years of SAP experience has worked as technical consultant and
developer in Switzerland (Public Sector, Banking; SAP Authorization, Transport Management).
Uwe has a MS in Biochemistry from Eberhard Karls Universitt Tbingen (Germany) and
received a PhD in Molecular Biology from Swiss Federal Institute of Technology Zurich
(Switzerland). He is currently working for Cirrus Consulting AG (Switzerland).
Table of Contents
Applies to: ........................................................................................................................................ 1
Summary.......................................................................................................................................... 1
Author Bio ........................................................................................................................................ 1
Report ZALVGRID_WITH_RADIOBUTTONS ................................................................................. 3
Related Content............................................................................................................................. 11
Disclaimer and Liability Notice....................................................................................................... 12
Report ZALVGRID_WITH_RADIOBUTTONS
The following screen shot shows how the ALV grid list looks like when using radiobuttons. The radiobuttons
are not a genuine feature of ALV grid lists but are simulated using the corresponding icons and the
HOTSPOT_CLICK event.
*&---------------------------------------------------------------------*
*& Report ZALVGRID_WITH_RADIOBUTTONS
*&
*&---------------------------------------------------------------------*
*& This program shows how to realize radiobuttons in ALV grid lists
*& using event HOTSPOT_CLICK.
*&
*&---------------------------------------------------------------------*
*& Screen 100:
*& - Flow logic
*&
*&
PROCESS BEFORE OUTPUT.
*&
MODULE PBO.
*&*
*&
PROCESS AFTER INPUT.
*&
MODULE PAI.
*&
*& - Screen elements: none
*& - ok-code field -> gd_okcode
*&
*& GUI Status MAIN100:
*& - F3 = 'BACK', Shift+F3 = 'EXIT', F12 = 'CANC'
*&---------------------------------------------------------------------*
PROGRAM zalvgrid_with_radiobuttons.
TYPE ui_func,
TYPE REF TO cl_gui_docking_container,
TYPE REF TO cl_gui_alv_grid.
*---------------------------------------------------------------------*
*
CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS.
"lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
* define local data
FIELD-SYMBOLS:
<ls_entry>
TYPE ty_s_sflight,
<ld_fld>
TYPE ANY.
READ TABLE gt_sflight ASSIGNING <ls_entry> INDEX es_row_no-row_id.
CHECK ( <ls_entry> IS ASSIGNED ).
*
*
*
"unselected"
icon_wd_radio_button_empty.
icon_wd_radio_button_empty.
icon_wd_radio_button_empty.
icon_wd_radio_button_empty.
ENDCLASS.
"handle_hotspot_click
"lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
MAIN
*
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM select_data.
PERFORM init_controls.
PERFORM build_fieldcatalog.
PERFORM set_layout.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
*
i_structure_name = 'SFLIGHT'
is_layout
= gs_layout
CHANGING
it_fieldcatalog = gt_fcat
it_outtab
= gt_sflight.
* Link docking container to dynpro
CALL METHOD go_docking->link
EXPORTING
repid
= syst-repid
dynnr
= '0100'
CONTAINER
=
EXCEPTIONS
cntl_error
= 1
cntl_system_error
= 2
lifetime_dynpro_dynpro_link = 3
OTHERS
= 4.
IF sy-subrc <> 0.
*
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*
*---------------------------------------------------------------------*
*
MODULE PBO OUTPUT
*
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
ENDMODULE.
"PBO OUTPUT
*---------------------------------------------------------------------*
*
MODULE PAI INPUT
*
*---------------------------------------------------------------------*
MODULE pai INPUT.
* Leave report
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
*
WHEN OTHERS.
do nothing
ENDCASE.
CLEAR gd_okcode.
ENDMODULE.
*
"PAI INPUT
*&---------------------------------------------------------------------*
*&
Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
*
*
*
*
*
*
*
*
*
*
*
*
*
ls_fcat-fieldname = 'BUTTON3'.
ls_fcat-coltext
= ls_fcat-fieldname.
INSERT ls_fcat INTO gt_fcat INDEX 5.
ls_fcat-fieldname = 'BUTTON2'.
ls_fcat-coltext
= ls_fcat-fieldname.
INSERT ls_fcat INTO gt_fcat INDEX 5.
ls_fcat-fieldname = 'BUTTON1'.
ls_fcat-coltext
= ls_fcat-fieldname.
INSERT ls_fcat INTO gt_fcat INDEX 5.
ENDFORM.
" BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&
Form SELECT_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM select_data .
* define local data
DATA:
ls_sflight
TYPE ty_s_sflight.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
ls_sflight-button1 = icon_wd_radio_button. " selected radiobutton
ls_sflight-button2 = icon_wd_radio_button_empty.
ls_sflight-button3 = icon_wd_radio_button_empty.
ls_sflight-button4 = icon_wd_radio_button_empty.
* Alternatively: create icons using function module 'ICON_CREATE'
* on SAP releases where these icons are not available.
" SELECT_DATA
*&---------------------------------------------------------------------*
*&
Form INIT_CONTROLS
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM init_controls .
CHECK ( go_docking IS NOT BOUND ).
ENDFORM.
" INIT_CONTROLS
*&---------------------------------------------------------------------*
*&
Form REFRESH_DISPLAY
*&---------------------------------------------------------------------*
*
Refresh table display after switching the radiobuttons
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM refresh_display .
* define local data
DATA:
ls_stable
TYPE lvc_s_stbl.
ls_stable-row = abap_true.
ls_stable-col = abap_true.
CALL METHOD go_grid->refresh_table_display
EXPORTING
is_stable
= ls_stable
*
I_SOFT_REFRESH =
EXCEPTIONS
finished
= 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.
ENDFORM.
" REFRESH_DISPLAY
*&---------------------------------------------------------------------*
*&
Form SET_LAYOUT
*&---------------------------------------------------------------------*
*
Set layout for ALV list
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM set_layout .
CLEAR: gs_layout.
gs_layout-cwidth_opt = abap_true.
gs_layout-zebra
= abap_true.
ENDFORM.
" SET_LAYOUT
Related Content
Adding Multiple check boxes to ALV and should select only one