0% found this document useful (0 votes)
231 views5 pages

Example: Managing ALV Toolbar (Adding Custom Buttons, Enabling / Disabling Standard ALV Toolbar Buttons)

This document describes how to customize the ALV toolbar in ABAP by adding custom buttons and enabling/disabling standard buttons. It creates an ALV grid to display sales order data, generates the field catalog and layout, and registers an event handler class to modify the toolbar by adding two custom buttons and disabling the search button.

Uploaded by

Gaurav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
231 views5 pages

Example: Managing ALV Toolbar (Adding Custom Buttons, Enabling / Disabling Standard ALV Toolbar Buttons)

This document describes how to customize the ALV toolbar in ABAP by adding custom buttons and enabling/disabling standard buttons. It creates an ALV grid to display sales order data, generates the field catalog and layout, and registers an event handler class to modify the toolbar by adding two custom buttons and disabling the search button.

Uploaded by

Gaurav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Example: Managing ALV Toolbar (Adding Custom Buttons,

Enabling / disabling standard ALV toolbar buttons)


REPORT Z730ALV11.

data v_vbeln type vbak-vbeln.
select-OPTIONS so_vbeln for v_vbeln DEFAULT '4980' to '4985'.

data : o_cust_cont type ref to cl_gui_custom_container,
       o_grid type ref to cl_gui_alv_grid.

types : begin of ty_sales,
             vbeln type vbak-vbeln,
             erdat type vbak-erdat,
             erzet type vbak-erzet,
             ernam type vbak-ernam,
        end of ty_sales.

data t_sales type table of ty_sales.

data wa_layo type lvc_s_layo.

data : t_fcat type lvc_t_fcat,
      wa_fcat type lvc_s_fcat. "normal work area

FIELD-SYMBOLS <abc> like line of t_fcat. "field  symbol work area

class lcl_eventreceiver DEFINITION.
  PUBLIC SECTION.
      methods handle_toolbar
                for event toolbar of cl_gui_alv_grid
                    importing e_object.
endclass.

class lcl_eventreceiver IMPLEMENTATION.
  method handle_toolbar.
*      message 'Toolbar  event' type 'I'.
    data wa_button type STB_BUTTON.

*  logic  for  disabling/enabling  std.alv  toolbar buttons


    clear wa_button.
    wa_button-disabled = 'X'.
    modify e_object->mt_toolbar from wa_button
              TRANSPORTING disabled
               where function = cl_gui_alv_grid=>mc_fc_find.

*  logic  for  adding custom buttons


*  prepare  work  area for adding  custom  buttons
    clear wa_button.
    wa_button-function = 'F1'.
    wa_button-icon = '@15@'.
    wa_button-quickinfo = 'Display Sales Items'.
    wa_button-butn_type = 0. "normal button
    wa_button-text = 'Sales Items'.
    append wa_button to e_object->mt_toolbar.

    clear wa_button.
    wa_button-butn_type = 3. "separator
    append wa_button to e_object->mt_toolbar.

    clear wa_button.
    wa_button-function = 'F2'.
    wa_button-icon = '@16@'.
    wa_button-quickinfo = 'Navigate to Transactions'.
    wa_button-butn_type = 2. "menu  button
    wa_button-text = 'Transactions'.
    append wa_button to e_object->mt_toolbar.
  endmethod.
endclass.

data ob type ref to lcl_eventreceiver.

START-OF-SELECTION.
  call screen 100.
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'ABC'.

*  link custom container  with custom control
CREATE OBJECT O_CUST_CONT
  EXPORTING
    CONTAINER_NAME              = 'CUSTCTRL'.

*  link alv grid  with custom container
CREATE OBJECT O_GRID
  EXPORTING
    I_PARENT          = o_cust_cont.

*  get sales  orders
  perform getsalesorders.
  if t_sales is not INITIAL.
*  generate  fieldcatalog
    perform fldcat.
*  generate  layout
    perform layout.
*  register  handlers
    perform reghandlers.
*  display  sales orders
     perform displaysalesorders.
  endif.
ENDMODULE.                 " STATUS_0100   OUTPUT

FORM GETSALESORDERS .
  select vbeln erdat erzet ernam
         from vbak
        into table t_sales
            where vbeln in so_vbeln.
ENDFORM.                    "  GETSALESORDERS

FORM DISPLAYSALESORDERS .
 CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
   EXPORTING
     IS_LAYOUT                     = wa_layo
   CHANGING
     IT_OUTTAB                     = t_sales
     IT_FIELDCATALOG               = t_fcat.

ENDFORM.                    "  DISPLAYSALESORDERS

MODULE USER_COMMAND_0100 INPUT.
  case sy-ucomm.
      when 'FC1'.
          leave PROGRAM.
  endcase.
ENDMODULE.                 " USER_COMMAND_0100   INPUT

FORM FLDCAT .
  clear wa_fcat.
  wa_fcat-fieldname = 'VBELN'.
  wa_fcat-col_pos = 1.
  wa_fcat-coltext = 'Sales Document'.
  wa_fcat-outputlen = 15.
  wa_fcat-tooltip = 'Sales Document Number'.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERDAT'.
  wa_fcat-col_pos = 2.
  wa_fcat-coltext = 'Creation Date'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERZET'.
  wa_fcat-col_pos = 3.
  wa_fcat-coltext = 'Creation Time'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.
  clear wa_fcat.
  wa_fcat-fieldname = 'ERNAM'.
  wa_fcat-col_pos = 4.
  wa_fcat-coltext = 'Name of Person Created Sales Doc'.
  wa_fcat-outputlen = 40.
  append wa_fcat to t_fcat.
ENDFORM.                    "  FLDCAT

FORM REGHANDLERS .
  create object ob.
  set handler ob->handle_toolbar for o_grid.
ENDFORM.                    "  REGHANDLERS

FORM LAYOUT .
  clear wa_layo.
  wa_layo-sel_mode = 'A'. "multiple  selection
ENDFORM.                    "  LAYOUT

You might also like