Application Development and Automation 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: 
Read only

alv

Former Member
0 Likes
597

hai sir

i want deactivate,,,,,some fuctions in alv grid...tel me how...

hai sir

i want deactivate,,,,,some fuctions in alv grid...tel me how...

4 REPLIES 4
Read only

Former Member
0 Likes
548

Hi,

Follow the below steps,

1. Declare a handler method for the event TOOLBAR of class cl_gui_alv_grid

2. For the above event you will have e_object as importing parameter.

3. In that e_object you will have mt_toolbar as a attribute which is a internal table.

4. In this internal table you will have details of all the buttons of toolbar.

5. Loop that internal table with the ICON name and modify the field disabled = 'X'.

Go through the standard program BCALV_GRID_05 for reference in which the functionality of adding a new button is present.

reward if helpful

Regards,

preet

Read only

Former Member
0 Likes
548

Hello,

To exclude buttons, you fill a table of type UI_FUNCTIONS and pass it to the parameter IT_TOOLBAR_EXCLUDING of the method set_table_for_first_display. The function codes for the buttons may be acquired by inspecting the constant attributes of the class cl_gui_alv_grid or putting a break point into a method, like the event-handling method of the event after_user_command, which deals with the ALV command.

Follow an example:


FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
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_sum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
ENDFORM .

Reward if helpfull,

Regards,

Read only

uwe_schieferstein
Active Contributor
0 Likes
548

Hello Venu

Have a look at my sample report ZUS_SDN_ALV_EVT_TOOLBAR. Execute the report and push the ENTER button repeatedly.

If you have choosen P_INACT = 'X' the toolbar functions are inactivated.

If you have chhosen P_DELE = 'X' the toolbar functions are deleted.


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALV_EVT_TOOLBAR
*&
*&---------------------------------------------------------------------*
*& 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

Read only

Former Member
0 Likes
548

Hi,

Try this code for reference

want deactivate,,,,,some fuctions in alv grid...tel me how...

REPORT ZEDIT_ONE_CELL_OOPS.

*Essential steps (search for '§')

  • ~~~~~~~~~~~~~~~

  • 1.Extend your output table for a field, e.g., CELLTAB, that holds

  • information about the edit status of each cell for the

  • corresponding row (the table type is SORTED!).

  • 2.After selecting data, set edit status for each row in a loop

  • according to field SEATSMAX.

  • 2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell

  • to status "editable".

  • 2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell

  • to status "non-editable".

  • 2c.Copy your celltab to the celltab of the current row of gt_outtab.

  • 3.Provide the fieldname of the celltab field by using field

  • STYLEFNAME of the layout structure.

*for reference BCALV_EDIT_02

TABLES: VBAK.

TYPE-POOLS: ICON.

*&----


*

*& Declaration Section for the Internal Tables *

*&----


*

DATA: BEGIN OF GT_OUTTAB OCCURS 0.

  • vbeln TYPE vbak-vbeln,

  • erdat TYPE vbak-erdat,

  • erzet TYPE vbak-erzet,

  • ernam TYPE vbak-ernam,

  • netwr TYPE vbak-netwr,

INCLUDE STRUCTURE ZVBAK_INTERNAL1.

DATA: CELLTAB TYPE LVC_T_STYL.

DATA: END OF GT_OUTTAB.

DATA: IT_VBAK TYPE TABLE OF ZVBAK_INTERNAL1 WITH HEADER LINE.

DATA: OK_CODE LIKE SY-UCOMM,

SAVE_OK LIKE SY-UCOMM,

G_CONTAINER TYPE SCRFNAME VALUE 'GRID_CONTROL',

GRID1 TYPE REF TO CL_GUI_ALV_GRID,

G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

GS_LAYOUT TYPE LVC_S_LAYO,

I_FCAT TYPE LVC_T_FCAT,

W_FCAT TYPE LVC_S_FCAT.

CALL SCREEN 200.

*&----


*

*& Module STATUS_0200 OUTPUT

*&----


*

  • text

*----


*

MODULE STATUS_0200 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = G_CONTAINER.

CREATE OBJECT GRID1

EXPORTING

I_PARENT = G_CUSTOM_CONTAINER.

PERFORM SELECT_DATA_AND_INIT_STYLE.

*§3.Provide the fieldname of the celltab field by using field

  • STYLEFNAME of the layout structure.

GS_LAYOUT-STYLEFNAME = 'CELLTAB'.

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'ZVBAK_INTERNAL1'

IS_LAYOUT = GS_LAYOUT

  • ls_fieldcat = it_fieldcatalog

CHANGING

IT_OUTTAB = GT_OUTTAB[]

IT_FIELDCATALOG = I_FCAT.

ENDIF.

ENDMODULE. " STATUS_0200 OUTPUT

*&----


*

*& Module USER_COMMAND_0200 INPUT

*&----


*

  • text

*----


*

MODULE USER_COMMAND_0200 INPUT.

SAVE_OK = OK_CODE.

CLEAR OK_CODE.

CASE SAVE_OK.

WHEN 'EXIT'.

PERFORM EXIT_PROGRAM.

WHEN 'SWITCH'.

PERFORM SWITCH_EDIT_MODE.

WHEN OTHERS.

  • do nothing

ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

*&----


*

*& Form exit_program

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM EXIT_PROGRAM .

LEAVE PROGRAM.

ENDFORM. " exit_program

*&----


*

*& Form select_data_and_init_style

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM SELECT_DATA_AND_INIT_STYLE.

DATA: LT_CELLTAB TYPE LVC_T_STYL,

L_INDEX TYPE I.

SELECT VBELN

ERDAT

ERZET

ERNAM

NETWR UP TO 100 ROWS

FROM VBAK

INTO TABLE IT_VBAK.

  • move corresponding fields from lt_sflight to gt_outtab

LOOP AT IT_VBAK.

MOVE-CORRESPONDING IT_VBAK TO GT_OUTTAB.

APPEND GT_OUTTAB.

ENDLOOP.

*§2.After selecting data, set edit status for each row in a loop

  • according to field NETWR.

LOOP AT GT_OUTTAB.

L_INDEX = SY-TABIX.

REFRESH LT_CELLTAB.

IF GT_OUTTAB-VBELN EQ '0000000080'.

PERFORM FILL_CELLTAB USING 'RW'

CHANGING LT_CELLTAB.

ELSE.

PERFORM FILL_CELLTAB USING 'RO'

CHANGING LT_CELLTAB.

ENDIF.

*§2c.Copy your celltab to the celltab of the current row of gt_outtab.

INSERT LINES OF LT_CELLTAB INTO TABLE GT_OUTTAB-CELLTAB.

MODIFY GT_OUTTAB INDEX L_INDEX.

ENDLOOP.

  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

  • EXPORTING

  • input = input

  • IMPORTING

  • output = output.

*

ENDFORM. " select_data_and_init_style

*END-OF-SELECTION.

*&----


*

*& Form fill_celltab

*&----


*

  • text

*----


*

  • -->P_0194 text

  • <--P_LT_CELLTAB text

*----


*

FORM FILL_CELLTAB USING VALUE(P_MODE)

CHANGING P_LT_CELLTAB TYPE LVC_T_STYL.

DATA: LS_CELLTAB TYPE LVC_S_STYL,

L_MODE TYPE RAW4.

  • This forms sets the style of column 'PRICE' editable

  • according to 'p_mode' and the rest to read only either way.

IF P_MODE EQ 'RW'.

*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell

  • to status "editable".

L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.

ELSE. "p_mode eq 'RO'

*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell

  • to status "non-editable".

L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

ENDIF.

LS_CELLTAB-FIELDNAME = 'VBELN'.

LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'ERDAT'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'ERZET'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'ERNAM'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'NETWR'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

ENDFORM. " fill_celltab

*&----


*

*& Form switch_edit_mode

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM SWITCH_EDIT_MODE.

IF GRID1->IS_READY_FOR_INPUT( ) EQ 0.

  • set edit enabled cells ready for input

CALL METHOD GRID1->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ELSE.

  • lock edit enabled cells against input

CALL METHOD GRID1->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 0.

ENDIF.

ENDFORM. " switch_edit_mode

*&----


*

*& Form build_field_cat

*&----


*

FORM BUILD_FIELD_CAT.

CLEAR I_FCAT.

W_FCAT-COL_POS = '1'.

W_FCAT-FIELDNAME = 'VBELN'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Sales and Distribution'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '2'.

W_FCAT-FIELDNAME = 'ERDAT'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Date'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '3'.

W_FCAT-FIELDNAME = 'ERZET'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Entry time'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '4'.

W_FCAT-FIELDNAME = 'ERNAM'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Name of Person'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '5'.

W_FCAT-FIELDNAME = 'NETWR'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Net Value'.

W_FCAT-CFIELDNAME = 'NETWR_AK'.

APPEND W_FCAT TO I_FCAT.

ENDFORM. " build_field_cat

Reward points if usefull to you

Regards

Fareedas