• No results found

ALV List with Radio Buttons

N/A
N/A
Protected

Academic year: 2021

Share "ALV List with Radio Buttons"

Copied!
12
0
0

Loading.... (view fulltext now)

Full text

(1)

ALV List with Radio Buttons

Applies to:

Application Server ABAP 6.40

Summary

The program shows how to define radio buttons in ALV grid lists.

Author(s):

Uwe Schieferstein

Company:

Cirrus Consulting AG, Switzerland

Created on:

11 January 2007

Author Bio

Uwe Schieferstein has 8 years of SAP experience has worked as technical consultant and

developer in Switzerland (Public Sector, Banking; SAP Authorization, Transport Management).

Uwe has a MS in Biochemistry from Eberhard Karls Universität Tübingen (Germany) and

received a PhD in Molecular Biology from Swiss Federal Institute of Technology Zurich

(Switzerland). He is currently working for Cirrus Consulting AG (Switzerland).

(2)

Table of Contents

Applies to: ... 1

Summary... 1

Author Bio ... 1

Report ZALVGRID_WITH_RADIOBUTTONS ... 3

Related Content... 11

(3)

Report ZALVGRID_WITH_RADIOBUTTONS

The following screen shot shows how the ALV grid list looks like when using radiobuttons. The radiobuttons

are not a genuine feature of ALV grid lists but are simulated using the corresponding icons and the

HOTSPOT_CLICK event.

*&---* *& Report ZALVGRID_WITH_RADIOBUTTONS

*&

*&---* *& This program shows how to realize radiobuttons in ALV grid lists *& using event HOTSPOT_CLICK.

*&

*&---* *& Screen 100:

*& - Flow logic *&

*& PROCESS BEFORE OUTPUT. *& MODULE PBO.

(4)

*&*

*& PROCESS AFTER INPUT. *& MODULE PAI.

*&

*& - Screen elements: none *& - ok-code field -> gd_okcode *&

*& GUI Status MAIN100:

*& - F3 = 'BACK', Shift+F3 = 'EXIT', F12 = 'CANC'

*&---*

PROGRAM zalvgrid_with_radiobuttons.

TYPE-POOLS: abap, icon. " INCLUDE <icon>. for releases < 6.20 TYPES: BEGIN OF ty_s_sflight.

INCLUDE TYPE sflight.

TYPES: button1 TYPE iconname. TYPES: button2 TYPE iconname. TYPES: button3 TYPE iconname. TYPES: button4 TYPE iconname. TYPES: END OF ty_s_sflight. DATA:

gt_sflight TYPE STANDARD TABLE OF ty_s_sflight,

*

gs_layout TYPE lvc_s_layo, gt_fcat TYPE lvc_t_fcat. DATA:

gd_okcode TYPE ui_func,

go_docking TYPE REF TO cl_gui_docking_container, go_grid TYPE REF TO cl_gui_alv_grid.

*---* * CLASS lcl_eventhandler DEFINITION

*---* *

*---*

CLASS lcl_eventhandler DEFINITION. PUBLIC SECTION.

CLASS-METHODS:

handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING

e_row_id e_column_id es_row_no sender.

ENDCLASS. "lcl_eventhandler DEFINITION

*---* * CLASS lcl_eventhandler IMPLEMENTATION

(5)

*---* *

*---*

CLASS lcl_eventhandler IMPLEMENTATION. METHOD handle_hotspot_click.

* define local data FIELD-SYMBOLS:

<ls_entry> TYPE ty_s_sflight, <ld_fld> TYPE ANY.

READ TABLE gt_sflight ASSIGNING <ls_entry> INDEX es_row_no-row_id. CHECK ( <ls_entry> IS ASSIGNED ).

* Set all radio buttons "unselected"

<ls_entry>-button1 = icon_wd_radio_button_empty. <ls_entry>-button2 = icon_wd_radio_button_empty. <ls_entry>-button3 = icon_wd_radio_button_empty. <ls_entry>-button4 = icon_wd_radio_button_empty.

ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE <ls_entry> TO <ld_fld>.

IF ( <ld_fld> IS ASSIGNED ).

* Set selected radio button "selected". <ld_fld> = icon_wd_radio_button. ENDIF.

* Force PAI followed by refresh of table display in PBO CALL METHOD cl_gui_cfw=>set_new_ok_code

EXPORTING new_code = 'REFRESH' * IMPORTING * RC = . ENDMETHOD. "handle_hotspot_click

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

*---* * MAIN * *---* START-OF-SELECTION. PERFORM select_data. PERFORM init_controls. PERFORM build_fieldcatalog. PERFORM set_layout.

CALL METHOD go_grid->set_table_for_first_display EXPORTING * i_structure_name = 'SFLIGHT' is_layout = gs_layout CHANGING it_fieldcatalog = gt_fcat it_outtab = gt_sflight. * Link docking container to dynpro CALL METHOD go_docking->link EXPORTING

(6)

dynnr = '0100' * CONTAINER = EXCEPTIONS cntl_error = 1 cntl_system_error = 2 lifetime_dynpro_dynpro_link = 3 OTHERS = 4. IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

CALL SCREEN 100. END-OF-SELECTION.

*---* * MODULE PBO OUTPUT * *---*

MODULE pbo OUTPUT.

SET PF-STATUS 'MAIN100'. SET TITLEBAR 'MAIN100'.

ENDMODULE. "PBO OUTPUT

*---* * MODULE PAI INPUT * *---*

MODULE pai INPUT. * Leave report CASE gd_okcode. WHEN 'BACK' OR 'EXIT' OR 'CANC'.

SET SCREEN 0. LEAVE SCREEN. * Refresh table display

WHEN 'REFRESH'. PERFORM refresh_display. WHEN OTHERS. * do nothing ENDCASE. CLEAR gd_okcode.

ENDMODULE. "PAI INPUT

*&---* *& Form BUILD_FIELDCATALOG

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM build_fieldcatalog .

(7)

* define local data DATA:

ls_fcat TYPE lvc_s_fcat. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING * I_BUFFER_ACTIVE = i_structure_name = 'ICON' * I_CLIENT_NEVER_DISPLAY = 'X' * I_BYPASSING_BUFFER = * I_INTERNAL_TABNAME = CHANGING ct_fieldcat = gt_fcat EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

DELETE gt_fcat WHERE ( fieldname <> 'NAME' ). * NOTE: field ICON-NAME has data element ICONNAME. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING * I_BUFFER_ACTIVE = i_structure_name = 'SFLIGHT' * I_CLIENT_NEVER_DISPLAY = 'X' * I_BYPASSING_BUFFER = * I_INTERNAL_TABNAME = CHANGING ct_fieldcat = gt_fcat EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

READ TABLE gt_fcat INTO ls_fcat WITH KEY fieldname = 'NAME'. IF ( syst-subrc = 0 ).

DELETE gt_fcat INDEX syst-tabix. ENDIF.

ls_fcat-fieldname = 'BUTTON4'.

ls_fcat-coltext = ls_fcat-fieldname. ls_fcat-icon = 'X'.

ls_fcat-hotspot = 'X'.

INSERT ls_fcat INTO gt_fcat INDEX 5. *

ls_fcat-fieldname = 'BUTTON3'.

ls_fcat-coltext = ls_fcat-fieldname. INSERT ls_fcat INTO gt_fcat INDEX 5. *

ls_fcat-fieldname = 'BUTTON2'.

ls_fcat-coltext = ls_fcat-fieldname. INSERT ls_fcat INTO gt_fcat INDEX 5.

(8)

*

ls_fcat-fieldname = 'BUTTON1'.

ls_fcat-coltext = ls_fcat-fieldname. INSERT ls_fcat INTO gt_fcat INDEX 5. * Renumbering of the columns

LOOP AT gt_fcat INTO ls_fcat. ls_fcat-col_pos = syst-tabix.

MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix. ENDLOOP.

ENDFORM. " BUILD_FIELDCATALOG

*&---* *& Form SELECT_DATA

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM select_data . * define local data DATA:

ls_sflight TYPE ty_s_sflight.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight. ls_sflight-button1 = icon_wd_radio_button. " selected radiobutton ls_sflight-button2 = icon_wd_radio_button_empty.

ls_sflight-button3 = icon_wd_radio_button_empty. ls_sflight-button4 = icon_wd_radio_button_empty.

* Alternatively: create icons using function module 'ICON_CREATE' * on SAP releases where these icons are not available.

MODIFY gt_sflight FROM ls_sflight

TRANSPORTING button1 button2 button3 button4 WHERE ( carrid IS NOT INITIAL ).

ENDFORM. " SELECT_DATA

*&---* *& Form INIT_CONTROLS

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM init_controls .

(9)

* Create docking container CREATE OBJECT go_docking EXPORTING parent = cl_gui_container=>screen0 * REPID = * DYNNR = * SIDE = DOCK_AT_LEFT * EXTENSION = 50 * STYLE = * LIFETIME = lifetime_default * CAPTION = * METRIC = 0 ratio = 90 * NO_AUTODEF_PROGID_DYNNR = * NAME = EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * Size of container = full screen size CALL METHOD go_docking->set_extension EXPORTING extension = 99999 EXCEPTIONS cntl_error = 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. * Create ALV grid instance CREATE OBJECT go_grid EXPORTING * I_SHELLSTYLE = 0 * I_LIFETIME = i_parent = go_docking * I_APPL_EVENTS = space * I_PARENTDBG = * I_APPLOGPARENT = * I_GRAPHICSPARENT = * I_NAME = * I_FCAT_COMPLETE = SPACE EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

(10)

* Set event handler for event HOTSPOT_CLICK

SET HANDLER:

lcl_eventhandler=>handle_hotspot_click FOR go_grid. ENDFORM. " INIT_CONTROLS

*&---* *& Form REFRESH_DISPLAY

*&---* * Refresh table display after switching the radiobuttons

*---* * --> p1 text

* <-- p2 text

*---*

FORM refresh_display . * define local data DATA:

ls_stable TYPE lvc_s_stbl. ls_stable-row = abap_true. ls_stable-col = abap_true.

CALL METHOD go_grid->refresh_table_display EXPORTING is_stable = ls_stable * I_SOFT_REFRESH = 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_DISPLAY

*&---* *& Form SET_LAYOUT

*&---* * Set layout for ALV list

*---* * --> p1 text * <-- p2 text *---* FORM set_layout . CLEAR: gs_layout.

gs_layout-cwidth_opt = abap_true. " optimize column width gs_layout-zebra = abap_true.

(11)

Related Content

Adding Multiple check boxes to ALV and should select only one

Events of Class CL_GUI_ALV_GRID

(12)

Disclaimer and Liability Notice

This document may discuss sample coding or other information that does not include SAP official interfaces

and therefore is not supported by SAP. Changes made based on this information are not supported and can

be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods

suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of

this technical article or code sample, including any liability resulting from incompatibility between the content

within this document and the materials and services offered by SAP. You agree that you will not hold, or

seek to hold, SAP responsible or liable with respect to the content of this document.

References

Related documents

• Multiple cooling system (if applicable); e.g., redundant systems • Impact of obstructions to both under-floor and above-floor airflows • Placement and cooling potential of

Occasion for gospel of douglas moo new testament books, this product is a standard commentary series in my ministry and other.. What commentary on the new dispensation, review

Objectives We sought to investigate whether genetic effects on response to TnF inhibitors (TnFi) in rheumatoid arthritis (ra) could be localised by considering known

President – Kristen Strasser President Elect – Chelle Carey Secretary – Darlene Dardy Treasurer – Merilyn Overton Director – April Barker Director – Sharon Jude Director

INDEX WORDS: Language learning, Identity, Identity construction, Investment, Motivation, Second language literacy, Heritage languages, Heritage language learners, Critical

We demonstrated that children of migrant parents, including both current-LBC and previous-LBC, are significantly more likely to report higher levels of emotional symptoms, higher

(a) The Republic of Guatemala formally confirms reservations I and III which it formulated upon signing the [said Convention], to the effect, respectively, that

In order to fulfil these varied tasks and to improve performance, NGOs need to learn from other NGOs and to share information with others.. With the emphasis on “farmer first” that