Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Vijay Babu Dudla
Submitted: 14.09.2008

Description

Usage of Radio buttons in ALV Report output.

Steps involved.

1. Add an extra field for Radiobutton of type char with length 4.

2. Populate the values for Radiobuttons

   To display Selected Radiobutton then need to use  icon_radiobutton

    if empty radiobutton then use icon_wd_radio_button_empty . Modify the internal  table with the value.

3. Fieldcatalog Population

   For the Radiobutton field mark the ICON = 'X' and HOTSPOT = 'X'.

4. Handling of the Radiobuttons in the Runtime can be done using the USER_COMMAND event.

Complete coding

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT  ztest_alv_radio.
TYPE-POOLS: slis.
INCLUDE <icons>.
DATA: it_fcat TYPE slis_t_fieldcat_alv ,
      wa_fcat LIKE LINE OF it_fcat.
DATA: BEGIN OF it_alv_flight OCCURS 0,
       carrid TYPE sflight-carrid,
       connid TYPE sflight-connid,
       radio1(4),                            "Radio button
       radio2(4),
      END OF it_alv_flight.
SELECT carrid connid FROM sflight
INTO TABLE it_alv_flight
UP TO 20 ROWS.
LOOP AT it_alv_flight.
  it_alv_flight-radio1 = icon_wd_radio_button_empty.  "Empty Radio Buttons
  it_alv_flight-radio2 =  icon_wd_radio_button_empty..
  MODIFY it_alv_flight.
ENDLOOP.
wa_fcat-fieldname = 'RADIO1'.
wa_fcat-tabname = 'IT_ALV_FLIGHT'.
wa_fcat-seltext_l = 'RADIO1'.
wa_fcat-outputlen = 6.
wa_fcat-icon = 'X'.                     "Icons
wa_fcat-hotspot = 'X'.               "Interactive Handling
APPEND wa_fcat TO it_fcat.
wa_fcat-fieldname = 'RADIO2'.
wa_fcat-tabname = 'IT_ALV_FLIGHT'.
wa_fcat-seltext_l = 'RADIO2'.
wa_fcat-icon = 'X'.
wa_fcat-outputlen = 6.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'CARRID'.
wa_fcat-tabname = 'IT_ALV_FLIGHT'.
wa_fcat-seltext_l = 'Carrid'.
wa_fcat-outputlen = 7.
APPEND wa_fcat TO it_fcat.
wa_fcat-fieldname = 'CONNID'.
wa_fcat-tabname = 'IT_ALV_FLIGHT'.
wa_fcat-seltext_l = 'Carrid'.
wa_fcat-outputlen = 7.
APPEND wa_fcat TO it_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_callback_program      = sy-repid
    i_callback_user_command = 'USER_COMMAND'
    it_fieldcat             = it_fcat
  TABLES
    t_outtab                = it_alv_flight
  EXCEPTIONS
    program_error           = 1.

FORM user_command USING ucomm TYPE sy-ucomm
selfield TYPE slis_selfield.
  CASE ucomm.
    WHEN '&IC1'.
      READ TABLE it_alv_flight INDEX selfield-tabindex.
      CASE selfield-fieldname.
        WHEN 'RADIO1'.
          IF it_alv_flight-radio1 = icon_radiobutton.
            it_alv_flight-radio1 = icon_wd_radio_button_empty.
            MODIFY it_alv_flight  INDEX selfield-tabindex
                                      TRANSPORTING radio1.
          ELSE.
            it_alv_flight-radio1 = icon_radiobutton..
            MODIFY it_alv_flight INDEX selfield-tabindex
                                      TRANSPORTING radio1.
          ENDIF.
        WHEN 'RADIO2'.
          IF it_alv_flight-radio2 = icon_radiobutton.
            it_alv_flight-radio2 = icon_wd_radio_button_empty.
            MODIFY it_alv_flight  INDEX selfield-tabindex
            TRANSPORTING radio2.
          ELSE.
            it_alv_flight-radio2 = icon_radiobutton..
            MODIFY it_alv_flight  INDEX selfield-tabindex
            TRANSPORTING radio2.
          ENDIF.
      ENDCASE.
  ENDCASE.
  selfield-refresh = 'X'.
ENDFORM.                    "USER_COMMAND

Output

3 Comments

  1. Hi,

     I modified the program in order to simulate radio button groups. Have Fun, Hendrik

    *&---------------------------------------------------------------------*
    *& Report ZHGEDICKE
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*

    REPORT ZHGEDICKE.

    TYPE-POOLS: slis, icon.

    DATA: it_fcat TYPE slis_t_fieldcat_alv ,
    wa_fcat LIKE LINE OF it_fcat.
    DATA: BEGIN OF it_alv_flight OCCURS 0,
    carrid TYPE sflight-carrid,
    connid TYPE sflight-connid,
    radio1(4), "Radio button
    radio2(4),
    END OF it_alv_flight.
    SELECT carrid connid FROM sflight
    INTO TABLE it_alv_flight
    UP TO 20 ROWS.
    LOOP AT it_alv_flight.
    it_alv_flight-radio1 = icon_wd_radio_button_empty. "Empty Radio Buttons
    it_alv_flight-radio2 = icon_wd_radio_button_empty..
    MODIFY it_alv_flight.
    ENDLOOP.
    wa_fcat-fieldname = 'RADIO1'.
    wa_fcat-tabname = 'IT_ALV_FLIGHT'.
    wa_fcat-seltext_l = 'RADIO1'.
    wa_fcat-outputlen = 6.
    wa_fcat-icon = 'X'. "Icons
    wa_fcat-hotspot = 'X'. "Interactive Handling
    APPEND wa_fcat TO it_fcat.
    wa_fcat-fieldname = 'RADIO2'.
    wa_fcat-tabname = 'IT_ALV_FLIGHT'.
    wa_fcat-seltext_l = 'RADIO2'.
    wa_fcat-icon = 'X'.
    wa_fcat-outputlen = 6.
    APPEND wa_fcat TO it_fcat.
    CLEAR wa_fcat.
    wa_fcat-fieldname = 'CARRID'.
    wa_fcat-tabname = 'IT_ALV_FLIGHT'.
    wa_fcat-seltext_l = 'Carrid'.
    wa_fcat-outputlen = 7.
    APPEND wa_fcat TO it_fcat.
    wa_fcat-fieldname = 'CONNID'.
    wa_fcat-tabname = 'IT_ALV_FLIGHT'.
    wa_fcat-seltext_l = 'Carrid'.
    wa_fcat-outputlen = 7.
    APPEND wa_fcat TO it_fcat.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = sy-repid
    i_callback_user_command = 'USER_COMMAND'
    it_fieldcat = it_fcat
    TABLES
    t_outtab = it_alv_flight
    EXCEPTIONS
    program_error = 1.

    FORM user_command USING ucomm TYPE sy-ucomm
    selfield TYPE slis_selfield.
    CASE ucomm.
    WHEN '&IC1'.
    READ TABLE it_alv_flight INDEX selfield-tabindex.
    CASE selfield-fieldname.
    WHEN 'RADIO1'.
    IF it_alv_flight-radio1 = icon_radiobutton.
    it_alv_flight-radio1 = icon_wd_radio_button_empty.
    it_alv_flight-radio2 = icon_wd_radio_button.
    MODIFY it_alv_flight INDEX selfield-tabindex
    TRANSPORTING radio1 radio2.
    ELSE.
    it_alv_flight-radio1 = icon_radiobutton.
    it_alv_flight-radio2 = icon_wd_radio_button_empty.
    MODIFY it_alv_flight INDEX selfield-tabindex
    TRANSPORTING radio1 radio2.
    ENDIF.
    WHEN 'RADIO2'.
    IF it_alv_flight-radio2 = icon_radiobutton.
    it_alv_flight-radio2 = icon_wd_radio_button_empty.
    it_alv_flight-radio1 = icon_wd_radio_button.
    MODIFY it_alv_flight INDEX selfield-tabindex
    TRANSPORTING radio1 radio2.
    ELSE.
    it_alv_flight-radio2 = icon_radiobutton.
    it_alv_flight-radio1 = icon_wd_radio_button_empty.
    MODIFY it_alv_flight INDEX selfield-tabindex
    TRANSPORTING radio1 radio2.
    ENDIF.
    ENDCASE.
    ENDCASE.
    selfield-refresh = 'X'.
    ENDFORM. "USER_COMMAND

  2. sorry - double post

  3. Very cool idea, thanks Hendrik. I just changed it slightly by always changing the other radio button and transporting that as well to make it work like a radio button group.

    *&---------------------------------------------------------------------*
    *&      Form  user_command
    *&---------------------------------------------------------------------*
    FORM USER_COMMAND USING UCOMM TYPE SY-UCOMM
    SELFIELD TYPE SLIS_SELFIELD.
      CASE UCOMM.
        WHEN '&IC1'.
          READ TABLE IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX.
          CASE SELFIELD-FIELDNAME.
            WHEN 'RADIO1'.
              IF IT_ALV_FLIGHT-RADIO1 ICON_RADIOBUTTON.
                IT_ALV_FLIGHT-RADIO1 ICON_WD_RADIO_BUTTON_EMPTY.
                IT_ALV_FLIGHT-RADIO2 ICON_RADIOBUTTON.
                MODIFY IT_ALV_FLIGHT  INDEX SELFIELD-TABINDEX
                               TRANSPORTING RADIO1 RADIO2.
              ELSE.
                IT_ALV_FLIGHT-RADIO1 ICON_RADIOBUTTON.
                IT_ALV_FLIGHT-RADIO2 ICON_WD_RADIO_BUTTON_EMPTY.
                MODIFY IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX
                              TRANSPORTING RADIO1 RADIO2.
              ENDIF.
            WHEN 'RADIO2'.
              IF IT_ALV_FLIGHT-RADIO2 ICON_RADIOBUTTON.
                IT_ALV_FLIGHT-RADIO1 ICON_RADIOBUTTON.
                IT_ALV_FLIGHT-RADIO2 ICON_WD_RADIO_BUTTON_EMPTY.
                MODIFY IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX
                              TRANSPORTING RADIO1 RADIO2.
              ELSE.
                IT_ALV_FLIGHT-RADIO1 ICON_WD_RADIO_BUTTON_EMPTY.
                IT_ALV_FLIGHT-RADIO2 ICON_RADIOBUTTON.
                MODIFY IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX
                              TRANSPORTING RADIO1 RADIO2.
              ENDIF.
          ENDCASE.
      ENDCASE.
      SELFIELD-REFRESH 'X'.
    ENDFORM.                    "USER_COMMAND
    *