You are on page 1of 4

Radio Buttons in the output of an ALV

1 of 4

http://www.saptechnical.com/Tutorials/ALV/Radio/Program.htm

Hom e T ip s T utor ials F or um s N E W Cer tificatio n Q' s Interv iew Q' s Jo bs T estimo n ials Co n tact Us

Radio Buttons in the output of an ALV


Click here for the tutorial

Document Categories:
ABAPTM
Adobe Forms
ABAP-HR
ALE & IDocs
ALV
BAPI
BASIS
BSP
Business Workflow
CRM NEW
LSMW
SAP Script/Smart Forms
BI/BW
eXchange Infrastructure (XI)
Enterprise Portals (EP)
eCATT
Object Oriented Programming
SAP Query
Userexits/BADIs
WebDynpro for Java/ABAPTM
Others

What's New?
Enable the selection options for the
data source fields (more than one
field at a time) in the extract
structure
Is JavaScript enabled on your
browser?
Assistance class in Web Dynpro
ABAP
Step-by-step tutorial on using
Step-loops
Triggering IDOC using BTE when
Material is changed in MM02
Transaction
SAP Data Archiving
Salt Apps for SAP
Modify Standard Purchasing Report
Output of ME2N
Procedure to configure change
documents for PA and OM Infotypes
BDC using CALL TRANSACTION
method
Uploading Customer Master
Extended Address using BAPI
method
BDC using Session Method
Basic configuration in SAP FI to
create GL accounts
Resolving the truncation of
multi-byte characters in DMEE File
Uploading Customer Master data
using Direct Input Method
Procedure for uploading employee
photos into SAP-HR IT002
Demo on Search help exit for the
material
Using the view created in one Web
Dynpro component as a pop-up view
in another component
Creating smartform for the
pre-printed stationary
Executing Function Modules
sequentially using SE37 Transaction
Mass Uploading employee photos

*&---------------------------------------------------------------------*
*& Report ZALV_RADIO
*
*&
*
*&---------------------------------------------------------------------*
*& Displays the Radio Button Icons in the output of a an ALV
*
*&
*
*&---------------------------------------------------------------------*
REPORT zalv_radio.
INCLUDE <icons>.
TABLES : pa2001 .
*******************************************************
**Types Declaration
*******************************************************
TYPES: BEGIN OF gty_emp,
pernr TYPE persno ,
subty TYPE subty ,
begda TYPE begda ,
endda TYPE endda ,
abwtg TYPE abwtg ,
radio(4) TYPE c,
END OF gty_emp.
*******************************************************
**Data Declaration
*******************************************************
DATA: go_container TYPE REF TO cl_gui_custom_container.
DATA: ls_layout
ls_fieldcat
lt_fieldcat

TYPE lvc_s_layo ,
TYPE lvc_s_fcat ,
TYPE lvc_t_fcat .

DATA : gv_grid
grid_name

TYPE REF TO cl_gui_alv_grid ,


TYPE REF TO cl_gui_alv_grid .

DATA: gt_emp TYPE STANDARD TABLE OF gty_emp ,


gs_emp TYPE gty_emp.
DATA: repid TYPE sy-repid.
*----------------------------------------------------------------------*
*
CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION FINAL .
PUBLIC SECTION.
* 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 .
ENDCLASS.

"lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
*
CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
*&---------------------------------------------------------------------*
*& 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.

4/24/2012 12:13 AM

Radio Buttons in the output of an ALV

2 of 4

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 .

ABAP Quiz HOT

Contribute?
Sample Specs
What's Hot?
Web Dynpro for ABAP Tutorials

Join the Mailing List


Enter name and email address below:
Name:
Email:

Subscribe

http://www.saptechnical.com/Tutorials/ALV/Radio/Program.htm

Unsubscribe

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 .
***To Get data from the database table
PERFORM get_details.
***To Set the empty Radio Button
PERFORM set_empty_radio .

"Object for event handler

*********************************************************
**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 = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 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

4/24/2012 12:13 AM

Radio Buttons in the output of an ALV

3 of 4

http://www.saptechnical.com/Tutorials/ALV/Radio/Program.htm

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'.
ls_fieldcat-hotspot
= 'X'.
ls_fieldcat-col_pos
= '1'.
APPEND ls_fieldcat TO lt_fieldcat.
CLEAR: ls_fieldcat.

"Icons
"Hotspot(Hand Symbol)

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.

4/24/2012 12:13 AM

Radio Buttons in the output of an ALV

4 of 4

http://www.saptechnical.com/Tutorials/ALV/Radio/Program.htm

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

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM


Home Contribute About Us Privacy Terms Of Use Disclaimer Safe Companies: Advertise on SAPTechnical.COM | Post Job Contact Us
2006-2007 SAPTechnical.COM. All rights reserved.
All product names are trademarks of their respective companies. SAPTechnical.COM is in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are registered trademarks of SAP AG in Germany and in several other countries.
Every effort is made to ensure content integrity. Use information on this site at your own risk.

Graphic Design by Round the Bend Wizards

4/24/2012 12:13 AM

You might also like