Tuesday, December 21, 2010
Use one filed radbut( type CHAR4) in the internal table that is displayed using REUSE_ALV_LIST_DISPLAY.  Pass radbut = icon_radiobutton for first record and for remaining records pass icon_wd_radio_button_empty to radbut. USER_COMMAND event to handle action when radio button is selected.

REPORT ztest_notepad.
DATA: BEGIN OF it_t100 OCCURS 0,
        radbut   TYPE char4,
        arbgb    LIKE t100-arbgb,
        msgnr    LIKE t100-msgnr,
        text     LIKE t100-text,
      END OF it_t100.
TYPE-POOLS: icon.
DATA:program TYPE sy-repid VALUE sy-repid.
TYPE-POOLS slis.
DATA:
      it_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fieldcat LIKE LINE OF it_fieldcat.
DEFINE fieldcatalog.
  wa_fieldcat-fieldname = &1.
  wa_fieldcat-tabname   = 'IT_T100'.
  wa_fieldcat-icon      = &2.
  wa_fieldcat-hotspot   = &3.
  wa_fieldcat-seltext_m = &4.
  append wa_fieldcat to it_fieldcat.
  clear  wa_fieldcat.
END-OF-DEFINITION.

START-OF-SELECTION.
  SELECT * FROM t100 INTO TABLE it_t100 UP TO 100 ROWS where SPRSL eq sy-langu.
  LOOP AT it_t100.
    IF sy-tabix = 1.
      it_t100-radbut = icon_radiobutton.
    ELSE.
      it_t100-radbut = icon_wd_radio_button_empty.
    ENDIF.
    MODIFY it_t100 INDEX sy-tabix TRANSPORTING radbut.
  ENDLOOP.
  fieldcatalog: 'RADBUT' 'X' 'X' 'CHECKBOX',
  'ARBGB'    ''  ''  'ARBGB'   ,
  'MSGNR'    ''  ''  'MSGNR'   ,
  'TEXT'     ''  ''  'TEXT'    .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program      = program
      i_callback_user_command = 'USER_COMMAND'
      it_fieldcat             = it_fieldcat
    TABLES
      t_outtab                = it_t100.
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM user_command USING ucomm TYPE sy-ucomm selfield TYPE slis_selfield.
  IF ucomm = '&IC1'.
    READ TABLE it_t100 INDEX selfield-tabindex.
    CASE selfield-fieldname.
      WHEN 'RADBUT'.
        IF it_t100-radbut NE icon_radiobutton.
          READ TABLE it_t100 WITH KEY radbut = icon_radiobutton.
          IF sy-subrc EQ 0.
            it_t100-radbut = icon_wd_radio_button_empty.
            MODIFY it_t100 INDEX sy-tabix.
            it_t100-radbut = icon_radiobutton.
            MODIFY it_t100 INDEX selfield-tabindex TRANSPORTING radbut.
          ENDIF.
        ENDIF.
    ENDCASE.
    selfield-refresh = 'X'.
  ENDIF.
ENDFORM.                    "user_command
  • Output

1 comment:

  1. Hi,
    please go through this program to add radio button and its functionality in alv report.

    TYPE-POOLS: SLIS.
    INCLUDE .
    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,
    RADIO(4),"Radio button
    END OF IT_ALV_FLIGHT.

    SELECT CARRID CONNID FROM SFLIGHT
    INTO TABLE IT_ALV_FLIGHT
    UP TO 1000 ROWS.
    DELETE ADJACENT DUPLICATES FROM IT_ALV_FLIGHT COMPARING CARRID.
    LOOP AT IT_ALV_FLIGHT.

    IT_ALV_FLIGHT-RADIO = ICON_WD_RADIO_BUTTON_EMPTY.
    MODIFY IT_ALV_FLIGHT.
    ENDLOOP.

    WA_FCAT-FIELDNAME = 'RADIO'.
    WA_FCAT-TABNAME = 'IT_ALV_FLIGHT'.
    WA_FCAT-SELTEXT_L = 'RADIO'.
    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
    *&---------------------------------------------------------------------*
    * text
    *----------------------------------------------------------------------*
    * -->UCOMM text
    * -->SELFIELD text
    *----------------------------------------------------------------------*
    FORM USER_COMMAND USING UCOMM TYPE SY-UCOMM
    SELFIELD TYPE SLIS_SELFIELD.
    CASE UCOMM.
    WHEN '&IC1'.
    LOOP AT IT_ALV_FLIGHT.
    IF IT_ALV_FLIGHT-RADIO = ICON_RADIOBUTTON.
    IT_ALV_FLIGHT-RADIO = ICON_WD_RADIO_BUTTON_EMPTY.
    MODIFY IT_ALV_FLIGHT.
    ENDIF.
    ENDLOOP.

    READ TABLE IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX.

    CASE SELFIELD-FIELDNAME.

    WHEN 'RADIO'.
    IF IT_ALV_FLIGHT-RADIO = ICON_RADIOBUTTON.
    IT_ALV_FLIGHT-RADIO = ICON_WD_RADIO_BUTTON_EMPTY.
    MODIFY IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX
    TRANSPORTING RADIO.
    ELSE.
    IT_ALV_FLIGHT-RADIO = ICON_RADIOBUTTON.
    MODIFY IT_ALV_FLIGHT INDEX SELFIELD-TABINDEX
    TRANSPORTING RADIO.
    ENDIF.
    ENDCASE.
    ENDCASE.
    SELFIELD-REFRESH = 'X'.

    ENDFORM. "USER_COMMAND

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.