Sample Code of Radio Button in Alv Report
Sample Code of Radio Button in Alv Report
Sample Code of Radio Button in Alv Report
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.
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
ENDCLASS .
"lcl_event_handler IMPLEMENTATION
*******************************************************
**Initialization Declaration
*******************************************************
INITIALIZATION .
repid = sy-repid.
DATA: go_handler
TYPE REF TO lcl_event_handler .
"Object
for event handler
***To Get data from the database table
PERFORM get_details.
***To Set the empty Radio Button
PERFORM set_empty_radio .
*********************************************************
**Create object alv container
*********************************************************
IF go_container IS INITIAL .
CREATE OBJECT go_container
EXPORTING
container_name = 'GC_CON'.
*********************************************************
**Create object alv Grid
*********************************************************
CREATE OBJECT gv_grid
EXPORTING
i_parent = go_container.
***Perform to design field catalog
PERFORM fieldcatatalog.
ls_layout-cwidth_opt = 'X' .
CREATE OBJECT go_handler .
SET HANDLER:
go_handler->handle_hotspot_click FOR gv_grid .
*********************************************************
**Call method set table for first display
*********************************************************
CALL METHOD gv_grid->set_table_for_first_display
EXPORTING
is_layout
= ls_layout
CHANGING
it_outtab
= gt_emp[]
it_fieldcatalog
= lt_fieldcat[]
EXCEPTIONS
invalid_parameter_combination
program_error
too_many_lines
OTHERS
=
=
=
=
1
2
3
4.
ENDIF.
*&---------------------------------------------------------------------*
*&
Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_2000 OUTPUT.
SET PF-STATUS 'RADIO'.
SET TITLEBAR 'RADIO'.
ENDMODULE.
" STATUS_2000 OUTPUT
*******************************************************
**Start-of-selection Declaration
*******************************************************
START-OF-SELECTION.
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*&
Form GET_DETAILS
*&---------------------------------------------------------------------*
*
To get the data from th database table pa2001
*----------------------------------------------------------------------*
FORM get_details .
SELECT pernr
subty
begda
endda
abwtg
FROM pa2001
INTO TABLE gt_emp
UP TO 10 ROWS.
IF sy-subrc = 0.
SORT gt_emp ASCENDING BY pernr.
ENDIF.
ENDFORM.
" GET_DETAILS
*&---------------------------------------------------------------------*
*&
Form FIELDCATATALOG
*&---------------------------------------------------------------------*
*
Building Fieldcatlog for ALV
*----------------------------------------------------------------------*
FORM fieldcatatalog .
REFRESH: lt_fieldcat.
CLEAR: ls_fieldcat.
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'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-reptext
= 'PERNR'.
ls_fieldcat-fieldname = 'PERNR'.
ls_fieldcat-ref_table = 'gt_emp'.
ls_fieldcat-outputlen = '20'.
ls_fieldcat-col_pos
= '2'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-reptext
= 'SUBTY'.
ls_fieldcat-fieldname = 'SUBTY'.
ls_fieldcat-ref_table = 'gt_emp'.
ls_fieldcat-outputlen = '20'.
ls_fieldcat-col_pos
= '3'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-reptext
= 'BEGDA'.
ls_fieldcat-fieldname = 'BEGDA'.
ls_fieldcat-ref_table = 'WT_CUST'.
ls_fieldcat-outputlen = '10'.
ls_fieldcat-fix_column = 'X'.
ls_fieldcat-key
= 'X'.
ls_fieldcat-col_pos
= '4'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR: ls_fieldcat.
ls_fieldcat-reptext
= 'ENDDA '.
ls_fieldcat-fieldname = 'ENDDA'.
ls_fieldcat-ref_table = 'WT_CUST'.
ls_fieldcat-outputlen = '30'.
ls_fieldcat-fix_column = 'X'.
ls_fieldcat-key
= 'X'.
ls_fieldcat-col_pos
= '5'.
APPEND ls_fieldcat TO lt_fieldcat.
ls_fieldcat-reptext
= 'ABWTG'.
ls_fieldcat-fieldname = 'ABWTG' .
ls_fieldcat-ref_table = 'gt_emp'.
ls_fieldcat-outputlen = '20'.
ls_fieldcat-col_pos
= '6'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR: ls_fieldcat.
ENDFORM.
" FIELDCATATALOG
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM .
WHEN 'CANCEL'.
LEAVE PROGRAM .
WHEN 'EXIT'.
LEAVE PROGRAM .
WHEN 'REFRESH' .
grid_name = gv_grid .
PERFORM refresh_alv USING grid_name .
ENDCASE.
ENDMODULE.
" USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*&
Form SET_EMPTY_RADIO
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM set_empty_radio .
LOOP AT gt_emp INTO gs_emp.
gs_emp-radio = icon_wd_radio_button_empty.
MODIFY gt_emp FROM gs_emp TRANSPORTING radio .
ENDLOOP.
ENDFORM.
" SET_EMPTY_RADIO
*&---------------------------------------------------------------------*
*&
Form REFRESH_ALV
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_GRID_NAME text
*----------------------------------------------------------------------*
FORM refresh_alv USING p_grid_name TYPE REF TO cl_gui_alv_grid..
* define local data
DATA:ls_stable TYPE lvc_s_stbl.
ls_stable-row = abap_true.
ls_stable-col = abap_true.
CALL METHOD p_grid_name->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.
ENDFORM.
" REFRESH_ALV