0% found this document useful (0 votes)
452 views3 pages

54-Radio Buttons in The Output of An ALV

This document describes how to display radio buttons in the output of an ALV (Adaptable List Viewer) grid to allow selection of only one row at a time. It involves: 1) Including icon definitions and declaring an internal table with a radio button field. 2) Defining an event handler class to handle row selection. 3) Implementing logic to deselect the previous radio and select the new one. 4) Updating the internal table and preparing the field catalog for the radio button field. 5) Refreshing the grid when a radio button is selected.

Uploaded by

assign79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
452 views3 pages

54-Radio Buttons in The Output of An ALV

This document describes how to display radio buttons in the output of an ALV (Adaptable List Viewer) grid to allow selection of only one row at a time. It involves: 1) Including icon definitions and declaring an internal table with a radio button field. 2) Defining an event handler class to handle row selection. 3) Implementing logic to deselect the previous radio and select the new one. 4) Updating the internal table and preparing the field catalog for the radio button field. 5) Refreshing the grid when a radio button is selected.

Uploaded by

assign79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Radio Buttons in the output of an ALV

By Khaja Moulali Shaik, Siemens IT Solutions

As per business need there was a scenario for an ALV Report Output, It must have functionality selecting
only one row at a time. It is possible with Radio buttons.  

NOTE: Here we have two types of Radio buttons Icons i.e. icon_wd_radio_button_empty (Empty Radio
Button) and icon_radiobutton (Selected Radio button)  

Below are the steps to display Radio Buttons in the output of an ALV.  

a)     Include ICONS.

INCLUDE <icons>.

b)    Declare an internal table with the required fields and additional field called ‘RADIO’ of type CHAR
of size ‘4’.
c)     Define a class to handle an even ‘HOTSPOT_CLICK’ o trigger when we click on the radio button
icon. Definition as coded below.

* Handles the Even when user clicks on any row.
    METHODS: handle_hotspot_click FOR EVENT hotspot_click 

OF cl_gui_alv_grid
                                 IMPORTING e_row_id.

d)    Do the implementation for the same class to handle the event i.e. if we select a radio button, then
the already selected radio button should be deselect and new radio button should be selected.
Code as follows.

*&--------------------------------------------------------------*
*&  METHOD handle_hotspot_click.
*&--------------------------------------------------------------*
*& On double clicking a particulat row
*&--------------------------------------------------------------*
  METHOD handle_hotspot_click .

    CLEAR : gs_emp.
    READ TABLE gt_emp INTO gs_emp 

WITH KEY radio = icon_radiobutton.
    IF sy-subrc NE 0.
      CLEAR gs_emp .
      READ TABLE gt_emp INTO gs_emp INDEX e_row_id.
      IF gs_emp-radio = icon_radiobutton.
        gs_emp-radio  = icon_wd_radio_button_empty.
        MODIFY gt_emp  INDEX e_row_id FROM gs_emp
                                TRANSPORTING radio.
      ELSE.
        gs_emp-radio  = icon_radiobutton.
        MODIFY gt_emp INDEX e_row_id FROM gs_emp 
TRANSPORTING radio.
      ENDIF.
    ELSE .
      gs_emp-radio = icon_wd_radio_button_empty.
      MODIFY gt_emp INDEX sy-tabix FROM gs_emp
                      TRANSPORTING radio.
      CLEAR gs_emp.
      READ TABLE gt_emp INTO gs_emp INDEX e_row_id .
      IF sy-subrc = 0.
        gs_emp-radio = icon_radiobutton.
        MODIFY gt_emp  INDEX e_row_id FROM gs_emp
                      TRANSPORTING radio.
      ENDIF.
    ENDIF .

    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
    new_code = 'REFRESH'
*      IMPORTING
*        rc       =
        .
   ENDMETHOD.                    "handle_hotspot_click

e)     Update the RADIO button with empty radio button in the internal table. Code as follows.
  LOOP AT gt_emp INTO gs_emp.
    gs_emp-radio = icon_wd_radio_button_empty.
    MODIFY gt_emp FROM gs_emp TRANSPORTING radio.
  ENDLOOP.  
f)     While preparing the field catalogue, Prepare field catalogue for that additional field ‘RADIO’ as
coded below.

  ls_fieldcat-reptext    = 'Radio Button'.
  ls_fieldcat-fieldname  = 'RADIO'.
  ls_fieldcat-ref_table  = 'gt_emp'.
  ls_fieldcat-icon       = 'X'.             "Icons
  ls_fieldcat-hotspot    = 'X'.             "Hotspot(Hand Symbol)
  ls_fieldcat-col_pos    = '1'.

g)    Refresh the grid, Perform REFRESH action when the radio button is selected.

* Define local data
  DATA:ls_stable TYPE lvc_s_stbl.

  ls_stable-row = abap_true.
  ls_stable-col = abap_true.

  CALL METHOD gv_grid->refresh_table_display
    EXPORTING
      is_stable = ls_stable
    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.

h)     Please click here for the demo program  

Output of the Program:  

You might also like