Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV list: select all button doesn't work

Former Member
0 Kudos

Hi friends,

I have an alv list which is displayed in a module pool program with check boxes and the selection buttons on the left hand corner of each row. For some reason the selectall button on the top left corner doesn't work while all other in the tool bar like find ,sort work perfectly. earlier individual line selection was possible by using check box. I tried to look into debugging mode but it would never go into the standard class code rather the control goes into the screen's module user- command .

Here is the code. Appreciate if somebody can help me with this.

CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA: g_repid LIKE sy-repid,

cont_on_main TYPE scrfname VALUE 'MAIN_100',

grid1 TYPE REF TO cl_gui_alv_grid,

custom_container1 TYPE REF TO cl_gui_custom_container,

event_receiver TYPE REF TO lcl_event_receiver.

DATA: x_save, "for Parameter I_SAVE

gs_layout TYPE disvariant,"for parameteris_variant

gs_layout1 TYPE disvariant, "for parameteris_variant

gs_toolbar TYPE stb_button.

DATA p_def VALUE 'X'.

*CLASS lcl_event_receiver IMPLEMENTATION.

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm.

METHODS:

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

PRIVATE SECTION.

ENDCLASS. "lcl_event_receiver DEFINITION

METHOD handle_toolbar.

ENDMETHOD. "handle_toolbar

METHOD handle_user_command. .................................> Control never comes here

CLEAR gv_error.

READ TABLE gt_alv_data INTO gt_alv_data2 WITH KEY sel = c_true.

IF sy-subrc NE 0.

CALL METHOD grid1->get_selected_rows

IMPORTING

et_index_rows = gt_rows.

IF gt_rows IS INITIAL.

MESSAGE i000 WITH ' '.

gv_error = c_true.

ENDIF.

CALL METHOD cl_gui_cfw=>flush.

ENDIF.

ENDMETHOD. "HANDLE_USER_COMMAND

METHOD handle_data_changed.

  • PERFORM data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

*

START-OF-SELECTION.

CASE 'X'.

WHEN rb_rad1.

CALL SCREEN 100.

WHEN rb_rad2 .

CALL SCREEN 0200.

END-OF-SELECTION.

*&----

-


*& Module STATUS_0100 OUTPUT

*&----

-


  • text

*----

-


MODULE status_0100 OUTPUT.

SET PF-STATUS 'ZINIT'. " adding few buttons on appl tool bar

SET TITLEBAR 'T100'.

ENDMODULE. " STATUS_0100 OUTPUT

*&----

-


*& Form get_field_catalog_100

*&----

-


FORM get_field_catalog_100 CHANGING p_lt_fcat_grid TYPE lvc_t_fcat.

*TYPE slis_t_fieldcat_alv.

  • Local Data

DATA ls_fieldcat TYPE slis_fieldcat_alv.

DATA: lt_fcat TYPE slis_t_fieldcat_alv,"Field catalog.

ls_fcat_grid TYPE lvc_s_fcat.

  • get the fld cat from FM

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-cprog

i_inclname = sy-cprog

i_internal_tabname = 'GT_ALV_DATA2'

CHANGING

ct_fieldcat = lt_fcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

  • Now modify the Field Cat

LOOP AT lt_fcat INTO ls_fieldcat.

ls_fieldcat-tabname = 'GT_ALV_DATA'.

CASE ls_fieldcat-fieldname.

WHEN 'SEL'. " 0

ls_fieldcat-seltext_s = ls_fieldcat-seltext_m =

ls_fieldcat-seltext_l = ls_fieldcat-reptext_ddic

= space.

ls_fieldcat-edit = c_true.

ls_fieldcat-checkbox = c_true.

ls_fieldcat-outputlen = 1.

WHEN .

.......................

ENDCASE.

MODIFY lt_fcat FROM ls_fieldcat.

ENDLOOP.

LOOP AT lt_fcat INTO ls_fieldcat.

MOVE-CORRESPONDING ls_fieldcat TO ls_fcat_grid.

ls_fcat_grid-seltext = ls_fcat_grid-scrtext_l =

ls_fcat_grid-scrtext_m = ls_fcat_grid-scrtext_s =

ls_fieldcat-seltext_m.

ls_fcat_grid-key = c_true.

APPEND ls_fcat_grid TO p_lt_fcat_grid.

ENDLOOP.

ENDFORM. " get_field_catalog_100

*&----


*

*& Module USER_COMMAND_0100 INPUT

*&----


*

MODULE user_command_0100 INPUT.

CASE sy-ucomm.

WHEN 'CANC'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE TO SCREEN 0.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'PACK'.

READ TABLE gt_alv_data INTO gt_alv_data2 WITH KEY sel = 'X'.

IF sy-subrc = 0.

CALL SCREEN '0201' STARTING AT 3 2 ENDING AT 38 8.

ELSE.

MESSAGE e000(zr) WITH ' Please select atleast single line'.

ENDIF.

WHEN 'PEND'.

CLEAR gv_count.

LOOP AT gt_alv_data INTO gt_alv_data2 WHERE sel = 'X'.

gv_count = gv_count + 1.

CHECK NOT gv_count > 1.

ENDLOOP.

IF gv_count > 1.

MESSAGE e000(zr) WITH ' Please select only a single line'.

ELSEIF gv_count = 0.

MESSAGE e000(zr) WITH ' Please select atleast single line'.

ELSE.

READ TABLE gt_alv_data INTO gt_alv_data2 WITH KEY sel = 'X'.

ENDIF.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&----


*

*& Form GR100_SET_GRID_TOOLBAR

*&----


*

FORM gr100_set_grid_toolbar CHANGING pt_exclude TYPE ui_functions.

DATA ls_exclude TYPE ui_func.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_check.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_sum.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.

APPEND ls_exclude TO pt_exclude.

ls_exclude = cl_gui_alv_grid=>mc_fc_graph.

APPEND ls_exclude TO pt_exclude.

*ls_exclude = cl_gui_alv_grid=>mc_fc_select_all.

*APPEND ls_exclude TO pt_exclude.

ENDFORM. " GR100_SET_GRID_TOOLBAR

*&----


*

*& Form get_basicdata

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM get_basicdata.

ENDFORM. " get_basicdata

*&----


*

*& Form write_basicdatA

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM write_basicdata.

  • Local Data

DATA: lt_fcat_grid TYPE lvc_t_fcat,

ls_layout TYPE lvc_s_layo,

lt_excl_func TYPE ui_functions,

ls_data LIKE LINE OF gt_alv_data,

gv_cnt TYPE i.

CLEAR lt_fcat_grid[].

  • Get Field Catalog

PERFORM get_field_catalog_100 CHANGING lt_fcat_grid.

  • Get Functions to exculde from Screen

PERFORM gr100_set_grid_toolbar CHANGING lt_excl_func.

  • ALV Vairables to be filled

g_repid = sy-repid.

gs_layout-report = g_repid.

gs_layout1-report = g_repid.

  • Color the rows

LOOP AT gt_alv_data INTO ls_data.

gv_cnt = gv_cnt + 1.

ls_data-cnt = gv_cnt .

ls_data-row = 'C202'.

MODIFY gt_alv_data FROM ls_data TRANSPORTING

cnt row sel docsentflg chkrcvflg chkdenflg .

ENDLOOP.

  • Set Layout

ls_layout-sel_mode = ' '.

ls_layout-info_fname = 'ROW'.

ls_layout-cwidth_opt = 'X'.

ls_layout-zebra = 'X'.

  • § 3.Determine Layout saving options.

x_save = 'U'. "Layouts are USer Specific

IF NOT custom_container1 IS INITIAL.

CALL METHOD custom_container1->free.

CALL METHOD cl_gui_cfw=>flush.

ENDIF.

IF custom_container1 IS INITIAL.

CREATE OBJECT custom_container1

EXPORTING

container_name = cont_on_main

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

IF sy-subrc NE 0.

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

titel = g_repid

txt2 = sy-subrc

txt1 = 'The control could not be created'(510).

ENDIF.

CREATE OBJECT grid1

EXPORTING

i_parent = custom_container1.

CALL METHOD grid1->set_table_for_first_display

EXPORTING

is_variant = gs_layout

i_save = x_save

i_default = p_def

is_layout = ls_layout

it_toolbar_excluding = lt_excl_func

CHANGING

it_outtab = gt_alv_data

it_fieldcatalog = lt_fcat_grid.

*Register ENTER to raise event DATA_CHANGED.

CALL METHOD grid1->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

  • Create object to receive events

CREATE OBJECT event_receiver.

SET HANDLER event_receiver->handle_user_command

event_receiver->handle_toolbar FOR ALL INSTANCES.

SET HANDLER event_receiver->handle_data_changed FOR grid1.

CALL METHOD grid1->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

  • raise event TOOLBAR:

CALL METHOD grid1->set_toolbar_interactive.

  • Clear ok Code 100

  • CLEAR ok_code_100.

ELSE.

CALL METHOD grid1->refresh_table_display

  • EXPORTING

  • IS_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.

ENDIF.

*

ENDFORM. " write_basicdate

.

ENDIF.

MODULE get_basicdata OUTPUT.

IF gt_alv_data[] IS INITIAL.

PERFORM get_basicdata.

ENDIF.

ENDMODULE. " get_basicdata OUTPUT

*&----


*

*& Module write_basicdata OUTPUT

*&----


*

  • text

*----


*

MODULE write_basicdata OUTPUT.

IF gt_alv_data[] IS INITIAL.

MESSAGE s000(zp) WITH 'No data found for the selection'.

LEAVE TO SCREEN 0.

ELSE.

PERFORM write_basicdata.

ENDIF.

ENDMODULE. " write_basicdata OUTPUT

*&----


*

*& Module STATUS_0200 OUTPUT

*&----


*

  • text

*----


*

MODULE status_0200 OUTPUT.

  • IF ok_code_100 EQ 'BACK' OR

  • ok_code_100 EQ 'CANC' OR

  • ok_code_100 EQ 'EXIT'.

  • LEAVE TO SCREEN 0.

  • EXIT.

  • ENDIF.

SET PF-STATUS 'ZUSDS'.

SET TITLEBAR 'T200'.

ENDMODULE. " STATUS_0200 OUTPUT

2 REPLIES 2

Former Member
0 Kudos

Can somebody tell if i am missing anything in the code.

DEV

0 Kudos

I think you have missed this:

ls_layout-BOX_FNAME = 'SEL'.  "<< your checkbox field name

Regards,

Naimesh Patel