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: 

Disable Button

Former Member
0 Kudos

Hi All,

How to disable button in ALV Grid Display..

5 REPLIES 5

former_member188685
Active Contributor
0 Kudos

using the parameter it_excluding it is possible.

>*" REFERENCE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL

find the function code , and appedn to it_excluding table and pass it to the parameter.

ex:

APPEND 'FCODE' to it_excluding. "fcode is the button functioncode.

pass this table to the alv function parameter.

uwe_schieferstein
Active Contributor

Hello Anil

Assuming you mean buttons of the ALV grid toolbar you may have a look at the following sample report ZUS_SDN_ALV_EVT_TOOLBAR.

Choose either P_INACT (= inactivate toolbar buttons) or P_DELE (= delete toolbar buttons), run the report and push repeatedly the ENTER button.


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALV_EVT_TOOLBAR
*&
*&---------------------------------------------------------------------*
*& Thread: Disable Button
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1016773"></a>
*&---------------------------------------------------------------------*
*& This sample report explains the handling of event TOOLBAR in order
*% to activate or inactive buttons of the ALV toolbar.
*&
*& Based on: BCALV_GRID_DEMO
*&
*& Procedure: Copy BCALV_GRID_DEMO and replace entire coding  OR
*             copy screen '0100' and GUI status 'MAIN100' from
*             BCALV_GRID_DEMO to this report.
*&---------------------------------------------------------------------*

REPORT  zus_sdn_alv_evt_toolbar.


TYPE-POOLS: abap, cntb, icon.


DATA:
  ok_code                TYPE ui_func,
  gt_sflight             TYPE TABLE OF sflight,
*
  g_container        TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
  g_grid1               TYPE REF TO cl_gui_alv_grid,
  g_custom_container    TYPE REF TO cl_gui_custom_container.



PARAMETERS:
  p_inact    RADIOBUTTON GROUP grp1  DEFAULT 'X',  " delete buttons
  p_dele     RADIOBUTTON GROUP grp1.               " inactivate buttons


PARAMETERS:
  p_newbut   AS CHECKBOX  DEFAULT ' ',  " add new button
  p_newddm   AS CHECKBOX  DEFAULT 'X'.  " add dropdown menu

*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.

  PUBLIC SECTION.

    CLASS-DATA:
      md_cnt    TYPE i.

    CLASS-METHODS:
      handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING
          e_object
          e_interactive
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_toolbar.
* § 2.In event handler method for event TOOLBAR: Append own functions
*   by using event parameter E_OBJECT.
    DATA:
      ls_toolbar  TYPE stb_button,
      ls_menu     type STB_BTNMNU.
*....................................................................
* E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.
* This class has got one attribute, namly MT_TOOLBAR, which
* is a table of type TTB_BUTTON. One line of this table is
* defined by the Structure STB_BUTTON (see data deklaration above).
*

* A remark to the flag E_INTERACTIVE:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*         'e_interactive' is set, if this event is raised due to
*         the call of 'set_toolbar_interactive' by the user.
*         You can distinguish this way if the event was raised
*         by yourself or by ALV
*         (e.g. in method 'refresh_table_display').
*         An application of this feature is still unknown... :-)

    ADD 1 TO md_cnt. " a simple counter


*   (1.a) Inactivate toolbar buttons
    IF ( p_inact = abap_true ).
      LOOP AT e_object->mt_toolbar INTO ls_toolbar FROM 1 TO md_cnt.
        ls_toolbar-disabled = 'X'.
        MODIFY e_object->mt_toolbar FROM ls_toolbar.
      ENDLOOP.

*   (1.b) Delete toolbar buttons
    ELSE.
      DO md_cnt TIMES.
        DELETE e_object->mt_toolbar INDEX 1.
      ENDDO.
    ENDIF.


*   (2) Add new button
    IF ( p_newbut = abap_true ).
*     Add separator to separate default and new buttons
      CLEAR: ls_toolbar.
      ls_toolbar-butn_type = cntb_btype_sep.  " separator
      APPEND ls_toolbar TO e_object->mt_toolbar.

*     Add new button "DETAIL"
      CLEAR: ls_toolbar.
      ls_toolbar-function  = 'DETAIL'.
      ls_toolbar-icon      = icon_detail.
      ls_toolbar-quickinfo = 'QuickInfo'.
      ls_toolbar-butn_type = cntb_btype_button.
      ls_toolbar-disabled  = abap_false.
      ls_toolbar-text      = 'Details'.
*      ls_toolbar-checked = ' '.
      APPEND ls_toolbar TO e_object->mt_toolbar.
    ENDIF.



*   (3) Add new dropdown menu
    IF ( p_newddm = abap_true ).
*     Add separator to separate default and new buttons
      CLEAR: ls_toolbar.
      ls_toolbar-butn_type = cntb_btype_sep.  " separator
      APPEND ls_toolbar TO e_object->mt_toolbar.

*     Add new dropdown menu "DETAIL"
      CLEAR: ls_toolbar.
      ls_toolbar-function  = 'DDMENU'.
      ls_toolbar-icon      = icon_detail.
      ls_toolbar-quickinfo = 'QuickInfo'.
      ls_toolbar-butn_type = cntb_btype_dropdown.
      ls_toolbar-disabled  = abap_false.
      ls_toolbar-text      = 'DD-Menu'.
*      ls_toolbar-checked = ' '.
      APPEND ls_toolbar TO e_object->mt_toolbar.

    ENDIF.

  ENDMETHOD.                    "handle_toolbar

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION



START-OF-SELECTION.
*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*

  SELECT * FROM sflight INTO TABLE gt_sflight.
  CALL SCREEN 100.

END-OF-SELECTION.







*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.

  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
           EXPORTING container_name = g_container.

*   Instantiate ALV grid control
    CREATE OBJECT g_grid1
           EXPORTING i_parent = g_custom_container.
    CALL METHOD g_grid1->set_table_for_first_display
      EXPORTING
        i_structure_name = 'SFLIGHT'
      CHANGING
        it_outtab        = gt_sflight.

*   Set event handler for event TOOLBAR
    SET HANDLER:
      lcl_eventhandler=>handle_toolbar FOR g_grid1.
  ENDIF.

* $Comment: Toolbar can be modified on-the-fly
  g_grid1->set_toolbar_interactive( ).

ENDMODULE.                    "PBO OUTPUT

*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
*   to react on oi_custom_events:
  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.

    WHEN OTHERS.
*     do nothing
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "PAI INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
*  CALL METHOD G_CUSTOM_CONTAINER->FREE.
*  CALL METHOD CL_GUI_CFW=>FLUSH.
  LEAVE PROGRAM.
ENDFORM.                    "EXIT_PROGRAM

Regards

Uwe

Former Member
0 Kudos

Hi Anil,

refer to the link below:

http://www.saptechies.com/disable-some-standard-buttons-from-alv-display/

With luck,

Pritam.

narin_nandivada3
Active Contributor
0 Kudos

Hi Anil,

Please check this solved thread for Enabling and Disabling the Button..

Hope this would help you.

Good luck

Narin

Former Member
0 Kudos

Hi,

If you want to disable the whole tool bar then you can write NO_TOOLBAR in the layout as below

and pass this in the 'set_table_for_first_display'

form layout .

i_layout-zebra = 'X'.

i_layout-grid_title = 'PO Details'.

I_LAYOUT-NO_TOOLBAR = 'X'.

endform. " LAYOUT

or if you want to disable only particular buttons then:

data ls_func type ui_func.

data: ta_func type ui_functions.

form exclude_tb_functions.

ls_func = cl_gui_alv_grid=>mc_fc_loc_copy_row.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_append_row.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_insert_row.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_move_row.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_delete_row.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_copy.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_cut.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_paste.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.

append ls_func to ta_func.

ls_func = cl_gui_alv_grid=>mc_fc_loc_undo.

append ls_func to ta_func.

endform.

call method cl_grid->set_table_for_first_display

exporting

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME = 'I_EKPO'

  • IS_VARIANT =

i_save = 'X'

  • I_DEFAULT = 'X'

is_layout = i_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

it_toolbar_excluding = ta_func

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

changing

it_outtab = i_ekpo

it_fieldcatalog = i_fldcat

it_sort = i_sort

  • IT_FILTER =

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.

Regards,

Sireesha