Code: Alles auswählen.
REPORT.
PARAMETERS p_Test.
INCLUDE <cl_alv_control>.
INITIALIZATION.
data(fcat) = value lvc_t_fcat(
( fieldname = 'DEMO' outputlen = 20 )
( fieldname = 'FLAG' outputlen = 3 ) ).
types: begin of _struc,
demo type c length 20,
flag type c LENGTH 1,
style type lvc_t_styl,
END OF _struc,
_tab type STANDARD TABLE OF _struc with DEFAULT KEY.
data(outtab) = value _tab(
( demo = 'no checkbox' flag = abap_false style = value #( ( fieldname = 'FLAG' style = alv_style_checkbox_no ) ) )
( demo = 'checkbox X' flag = abap_True style = value #( ( fieldname = 'FLAG' style = alv_style_checkbox_checked + alv_style_enabled ) ) )
( demo = 'checkbox space' flag = abap_True style = value #( ( fieldname = 'FLAG' style = alv_style_checkbox_not_checked ) ) ) ).
data(grid) = new cl_gui_alv_grid( i_parent = new cl_gui_docking_Container( ratio = 80 side = 1 ) ).
grid->set_table_for_first_display(
EXPORTING
is_layout = value #( stylefname = 'STYLE' )
CHANGING
it_outtab = outtab
it_fieldcatalog = fcat
EXCEPTIONS
others = 4 ).
Code: Alles auswählen.
REPORT.
PARAMETERS p_test.
CLASS app DEFINITION.
PUBLIC SECTION.
METHODS go.
PRIVATE SECTION.
INCLUDE <cl_alv_control>.
TYPES: BEGIN OF _struc,
demo TYPE c LENGTH 20,
flag TYPE c LENGTH 1,
style TYPE lvc_t_styl,
END OF _struc,
_tab TYPE STANDARD TABLE OF _struc WITH DEFAULT KEY.
METHODS on_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_column_id e_row_id sender.
DATA outtab TYPE _tab.
ENDCLASS.
CLASS app IMPLEMENTATION.
METHOD go.
DATA(fcat) = VALUE lvc_t_fcat(
( fieldname = 'DEMO' outputlen = 20 )
( fieldname = 'FLAG' outputlen = 3 hotspot = abap_true ) ).
outtab = VALUE #(
( demo = 'no checkbox' flag = abap_false style = VALUE #( ( fieldname = 'FLAG' style = alv_style_checkbox_no ) ) )
( demo = 'checkbox X' flag = abap_true style = VALUE #( ( fieldname = 'FLAG' style = alv_style_checkbox_checked ) ) )
( demo = 'checkbox space' flag = abap_false style = VALUE #( ( fieldname = 'FLAG' style = alv_style_checkbox_not_checked ) ) ) ).
DATA(grid) = NEW cl_gui_alv_grid( i_parent = NEW cl_gui_docking_container( ratio = 80 side = 1 ) ).
grid->set_table_for_first_display(
EXPORTING
is_layout = VALUE #( stylefname = 'STYLE' )
CHANGING
it_outtab = outtab
it_fieldcatalog = fcat
EXCEPTIONS
OTHERS = 4 ).
SET HANDLER on_click FOR grid.
ENDMETHOD.
METHOD on_click.
ASSIGN outtab[ e_row_id ] TO FIELD-SYMBOL(<outline>).
IF sy-subrc = 0.
<outline>-flag = SWITCH #( <outline>-flag WHEN abap_true THEN abap_false ELSE abap_true ).
<outline>-style = VALUE #( (
fieldname = 'FLAG'
style = SWITCH #( <outline>-flag
WHEN abap_true THEN alv_style_checkbox_checked
ELSE alv_style_checkbox_not_checked ) ) ).
sender->refresh_table_display(
is_stable = VALUE #( row = abap_true col = abap_true )
i_soft_refresh = abap_true ).
ENDIF.
ENDMETHOD.
ENDCLASS.
INITIALIZATION.
NEW app( )->go( ).