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: 

Deactivate buttons in ALV GRID being called in subscreen

Former Member
0 Kudos

Hi,

In a screen, when a specific tab is selected (tab strip), the subscreen area is filled with ALV GRID. I need to deactivate few buttons on the ALV GRID. How can that be done??

Advance Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Adarsh,

U have to write the code for deactivating the buttons in the alv at the PBO of the subscreen where the ALV is displayed.

Since u are using alv grid You can use the methods in the class cl

guialv_grid, to hide the buttons.

Regards

Sarath

4 REPLIES 4

uwe_schieferstein
Active Contributor
0 Kudos

Hello Adarsh

It does not matter whether an ALV grid is displayed in a screen or subscreen. The procedure for inactivating toolbar buttons is always the same.

Have a look at my sample report in thread:

Regards

Uwe

Former Member
0 Kudos

Hi Adarsh,

U have to write the code for deactivating the buttons in the alv at the PBO of the subscreen where the ALV is displayed.

Since u are using alv grid You can use the methods in the class cl

guialv_grid, to hide the buttons.

Regards

Sarath

Former Member
0 Kudos

Hello Aadarsh

i have developed a piece of code to deactivate toolbar button 'find', and i commented disabling the remaining buttons part in the below code..

check it once.

REPORT ZCL2.

****program to disable toolbar icon 'find' in the output grid

tables: vbrk.

select-options: s_vbeln for vbrk-vbeln.

class zcl_alvintr definition deferred.

data: int_vbrk type tab_vbrk,

obj type ref to zcl_alvintr,

wa_vbrk type vbrk,

o_cont type ref to cl_gui_custom_container,

o_grid type ref to cl_gui_alv_grid.

data: wa_toolbar type stb_button.

class zcl_alvintr definition.

public section.

methods: constructor ,

handle_toolbar for event toolbar of cl_gui_alv_grid

importing e_object e_interactive,

get_data .

private section.

methods: show_data .

endclass.

class zcl_alvintr implementation.

method constructor.

CREATE OBJECT o_CONT

EXPORTING

CONTAINER_NAME = 'CUST_CONT'

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.

else.

CREATE OBJECT o_GRID

EXPORTING

I_PARENT = o_cont

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.

ENDIF.

endmethod. "constructor

method get_data.

select * from vbrk into table int_vbrk where vbeln in s_vbeln.

if not int_vbrk is initial.

call method me->show_data.

else.

message i000(zck_msg) with 'table entries not found'.

endif.

endmethod. "get_data

method show_data.

CALL METHOD o_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'VBRK'

CHANGING

IT_OUTTAB = int_vbrk[]

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 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.

endmethod. "show_data

****event handler method to handle toolbar

method handle_toolbar .

loop at e_object->mt_toolbar into wa_toolbar.

if wa_toolbar-quickinfo = 'Find' ."or wa_toolbar-quickinfo = 'Print' or wa_toolbar-quickinfo = 'Total' or

  • wa_toolbar-quickinfo = 'Views' or wa_toolbar-quickinfo = 'Export'.

wa_toolbar-disabled = 'X'.

modify e_object->mt_toolbar from wa_toolbar.

clear wa_toolbar.

endif.

endloop.

endmethod.

endclass. "zcl_alvintr IMPLEMENTATION

start-of-selection.

set screen 100.

create object obj.

******setting handler for event of o_grid.

set handler obj->handle_toolbar for o_grid.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MENU'.

call method obj->get_data.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

case sy-ucomm .

when 'BACK'.

leave program.

endcase.

endmodule.

Former Member
0 Kudos

Hi Aadarsh,

Check out the following program.

&----


  • Global data definitions for ALV

&----


  • To allow the declaration of gr_event_handler before the

  • lcl_event_receiver class is defined, decale it as deferred in the

  • start of the program

CLASS lcl_event_handler DEFINITION DEFERRED.

&----


  • Object reference

&----


  • ALV Grid instance reference

DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,

  • Custom container instance reference

gr_ccontainer TYPE REF TO cl_gui_custom_container,

  • Event class reference

gr_event_handler TYPE REF TO lcl_event_handler. "IC210507+

&----


  • Internal Table

&----


  • Field catalog table

DATA: gt_fieldcat TYPE lvc_t_fcat,

  • Internal table holding list data

gt_list TYPE STANDARD TABLE OF sflight,

  • Table to be filled up for excluding some of the standard function

  • buttons

gt_exclude TYPE ui_functions. "IC210507+

&----


  • Work area

&----


  • Layout structure

DATA: gs_layout TYPE lvc_s_layo,

  • Field catalog structure

gs_fcat TYPE lvc_s_fcat,

  • Exclude button structure

gs_exclude TYPE ui_func, "IC210507+

  • Structure to add button in the ALV toolbar

gs_toolbar TYPE stb_button. "IC210507+

&----


  • Variables

&----


DATA: ok_code TYPE sy-ucomm,

save_ok TYPE sy-ucomm,

  • Name of the custom control added on the screen

gv_custom_control_name TYPE scrfname VALUE 'CC_ALV'.

  • Begin of IC210507

&----


  • Local classes

&----


CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION.

METHODS:

  • To add new functional buttons to the ALV toolbar

handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

  • To implement user commands

handle_user_command FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm.

ENDCLASS. "lcl_event_handler DEFINITION

  • End of IC210507

&----


  • Calling the screen where ALV output is displayed

&----


CALL SCREEN 100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • PBO

----


MODULE status_0100 OUTPUT.

  • ALV display

PERFORM display_alv.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • PAI

----


MODULE user_command_0100 INPUT.

save_ok = ok_code.

CLEAR ok_code.

IF save_ok EQ 'EXIT'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form display_alv

&----


  • ALV display

----


FORM display_alv.

PERFORM get_data.

PERFORM create_alv.

ENDFORM. " display_alv

&----


*& Form get_data

&----


  • Fetch data to be displayed in the list

----


FORM get_data.

SELECT * FROM sflight

INTO TABLE gt_list.

ENDFORM. " get_data

&----


*& Form create_alv

&----


  • Create and set or Refresh ALV

----


FORM create_alv.

  • Checking whether an instance of the container (or ALV Grid) exists.

IF gr_alvgrid IS INITIAL.

  • If not, creating and setting ALV for the first display.

  • Creating custom container instance

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = gv_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6.

  • Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5.

  • Begin of IC210507

  • Creating an instance for the event handler

CREATE OBJECT gr_event_handler.

  • Registering handler methods to handle ALV Grid events

SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid.

SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid.

  • End of IC210507

  • Preparing field catalog.

PERFORM prepare_field_catalog CHANGING gt_fieldcat.

  • Preparing layout structure

PERFORM prepare_layout CHANGING gs_layout.

  • Excluding Unwanted Standard Function Buttons

PERFORM exclude_tb_functions CHANGING gt_exclude. "IC210507+

  • Method to display ALV grid

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

is_layout = gs_layout

  • To exclude buttons the exclusion table must be passed to the following

  • field

it_toolbar_excluding = gt_exclude "IC210507+

CHANGING

it_outtab = gt_list

it_fieldcatalog = gt_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

  • To make ALV show our additional buttons, we must call the method

  • “set_toolbar_interactive” for the ALV Grid instance after the instance

  • is created.

CALL METHOD gr_alvgrid->set_toolbar_interactive. "IC210507+

ELSE.

  • If an instance of the container (or ALV Grid) exists, refreshing it.

CALL METHOD gr_alvgrid->refresh_table_display

EXCEPTIONS

finished = 1

OTHERS = 2.

ENDIF.

ENDFORM. " create_alv

&----


*& Form prepare_field_catalog

&----


  • Subroutine to populate field catalog

----


  • <--P_GT_FIELDCAT Table to describe the field catalog

----


FORM prepare_field_catalog CHANGING p_gt_fieldcat TYPE lvc_t_fcat.

  • Generating the field catalog semi automatically

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

ct_fieldcat = p_gt_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

LOOP AT p_gt_fieldcat INTO gs_fcat.

CASE gs_fcat-fieldname.

WHEN 'CARRID'.

gs_fcat-outputlen = '10'.

gs_fcat-coltext = 'Airline Carrier ID'.

MODIFY p_gt_fieldcat FROM gs_fcat.

WHEN 'FLDATE'.

gs_fcat-just = 'C'.

gs_fcat-hotspot = 'X'.

MODIFY p_gt_fieldcat FROM gs_fcat.

ENDCASE.

ENDLOOP.

ENDFORM. " prepare_field_catalog

&----


*& Form prepare_layout

&----


  • Preparing layout structure

----


  • <--P_GS_LAYOUT Layout structure

----


FORM prepare_layout CHANGING p_gs_layout TYPE lvc_s_layo.

p_gs_layout-zebra = 'X' .

p_gs_layout-grid_title = 'Flight Info System'.

p_gs_layout-smalltitle = 'X'.

ENDFORM. " prepare_layout

  • Begin of IC210507

&----


*& Form exclude_tb_functions

&----


  • Excluding Unwanted Standard Function Buttons

----


  • <--P_GT_EXCLUDE Table to be filled up to exclude buttons

----


FORM exclude_tb_functions CHANGING p_gt_exclude TYPE ui_functions.

  • “MC_FC_” are names for functions directly and the names beginning with

  • “MC_MB_” are for the function menus including some subfunctions as menu

  • entries.

  • In this case 'Maximum' and 'Minimum' options under 'Sum' button & 'Print'

  • button are excluded

gs_exclude = cl_gui_alv_grid=>mc_fc_maximum.

APPEND gs_exclude TO p_gt_exclude.

gs_exclude = cl_gui_alv_grid=>mc_fc_minimum.

APPEND gs_exclude TO p_gt_exclude.

gs_exclude = cl_gui_alv_grid=>mc_fc_print.

APPEND gs_exclude TO p_gt_exclude.

ENDFORM. " exclude_tb_functions

&----


*& Class (Implementation) lcl_event_handler

&----


  • Event handler for the ALV Grid instance.

----


CLASS lcl_event_handler IMPLEMENTATION.

  • Handle Toolbar

METHOD handle_toolbar.

PERFORM handle_toolbar USING e_object e_interactive .

ENDMETHOD . "handle_toolbar

  • Handle User Command

METHOD handle_user_command .

PERFORM handle_user_command USING e_ucomm .

ENDMETHOD. "handle_user_command

ENDCLASS. "lcl_event_handler

&----


*& Form handle_toolbar

&----


  • Subroutine called from event handler method for event toolbar.

  • This is to add a new button in the ALV application toolbar

----


  • -->P_E_OBJECT

  • -->P_E_INTERACTIVE

----


FORM handle_toolbar USING p_e_object TYPE REF TO cl_alv_event_toolbar_set

p_e_interactive.

&----


  • Begin of 'Adding a new Button'

&----


CLEAR gs_toolbar.

  • Function code

MOVE 'EXIT' TO gs_toolbar-function.

  • Button type that will be added to the toolbar

gs_toolbar-butn_type = 0.

  • Icon for the button

  • From the type group ICON in SE11, we can get the value to be passed

  • for icon

gs_toolbar-icon = '@2N@'.

  • Quick info for the button

MOVE 'Exit' TO gs_toolbar-quickinfo.

  • Text for the button

MOVE 'Exit' TO gs_toolbar-text.

  • Adds the button as disabled if set to X

MOVE ' ' TO gs_toolbar-disabled.

  • Appending the structure to the table attribute “mt_toolbar” of the object

APPEND gs_toolbar TO p_e_object->mt_toolbar.

&----


  • End of 'Adding a new Button'

&----


&----


  • Begin of 'Disabling an existing standard Button'

&----


LOOP AT p_e_object->mt_toolbar

INTO gs_toolbar

  • Identify which button to disable from the function code

  • In this case disabling the 'Filter' button

WHERE function = '&MB_FILTER'.

  • Set the 'DISABLED' field to disable a button

gs_toolbar-disabled = 'X'.

MODIFY p_e_object->mt_toolbar FROM gs_toolbar.

ENDLOOP.

&----


  • End of 'Disabling an existing standard Button'

&----


ENDFORM. " handle_toolbar

&----


*& Form handle_user_command

&----


  • Implement any new function

----


  • -->P_E_UCOMM text

----


FORM handle_user_command USING p_e_ucomm TYPE syucomm.

IF p_e_ucomm EQ 'EXIT'.

LEAVE PROGRAM.

ENDIF.

ENDFORM. " handle_user_command

  • End of IC210507

Award points if found useful.

Regards

Indrajit.