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 Help

Former Member
0 Likes
564

Hi,

i wont to now how i add buttons to alv (like export the table to excel and other ...), i use 00 alv like below and i be happy to get some comment to do this better :

Regards

*&      Module  PBO  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE pbo 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.
    gs_layout-grid_title = text-001.
    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_structure_name = 'YHR_EX_T_STR'(002)
        is_layout        = gs_layout
        is_variant       = variant
        i_save           = 'A'
      CHANGING
        it_outtab        = teken_itab
        it_fieldcatalog  = fcat.
  ENDIF.



ENDMODULE.                 " PBO  OUTPUT

MODULE pai INPUT.

  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN OTHERS.
  ENDCASE.
  CLEAR ok_code.


ENDMODULE.                 " PAI  INPUT


FORM exit_program.

*  CALL METHOD G_CUSTOM_CONTAINER->FREE.
*  CALL METHOD CL_GUI_CFW=>FLUSH.

  LEAVE PROGRAM.
ENDFORM.                    "EXIT_PROGRAM

FORM create_field_cat .


  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name       = 'YHR_EX_T_STR'   "STRUCTRE NAME
    CHANGING
      ct_fieldcat            = ct_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
529

Hi,

Please check demo program BCALV_GRID_08 to add buttons using TOOLBAR event of CL_GUI_ALV_GRID.

Also you can check this link for sample program on how to add buttons using FM REUSE_ALV_LIST_DISPLAY.

http://www.sap-basis-abap.com/abap/add-button-to-alv-toolbar-with-reuse-alv-list-display.htm

Regards,

Ferry Lianto

3 REPLIES 3
Read only

former_member194669
Active Contributor
0 Likes
529

" You need to fill variant structure with the following

    variant-report       = sy-repid.
    variant-username     = sy-uname.

    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_structure_name = 'YHR_EX_T_STR'(002)
        is_layout        = gs_layout
        is_variant       = variant
        i_save           = 'A'
      CHANGING
        it_outtab        = teken_itab
        it_fieldcatalog  = fcat.

a®

Read only

Former Member
0 Likes
529

Hi,

For excluding some standard buttons on the toolbar,


FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .

DATA ls_exclude TYPE ui_func.
" for excluding the buttons on the alv toolbar
  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.
" for excluding the menu function
  ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
  APPEND ls_exclude TO pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
  APPEND ls_exclude TO pt_exclude.
ENDFORM .

Here, names beginning with “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. By excluding one from the latter type, you exclude all of the functions under it.

Check the below code for event handler local class.


"Event Handler Class
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 .
ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION .
*Handle Toolbar
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object e_interactive .
ENDMETHOD .
ENDCLASS.

DATA gr_event_handler TYPE REF TO lcl_event_handler .
.. ..
*--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_toolbar FOR gr_alvgrid .

ALV Grid control has an open door letting you to add your own functions triggered by a button press on the ALV toolbar. For this, we mainly utilize two of ALV Grid events. We use the event “toolbar” to add the button and the event “user_command” to implement the new function.

In the method handling the “toolbar” event, we define a new button by filling a structure and appending it to the table attribute “mt_toolbar” of the object to whose reference we can reach via the parameter “e_object” of the event.



FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set .
DATA: ls_toolbar TYPE stb_button.
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO i_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'PER' TO ls_toolbar-function. "#EC NOTEXT
MOVE icon_display_text TO ls_toolbar-icon.
MOVE 'Passenger Info'(201) TO ls_toolbar-quickinfo.
MOVE 'Passenger Info'(201) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'EXCH' TO ls_toolbar-function. "#EC NOTEXT
MOVE 2 TO ls_toolbar-butn_type.
MOVE icon_calculation TO ls_toolbar-icon.
MOVE 'Payment in Other Currencies'(202) TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
ENDFORM .

Hope this helps. Reward points if helpful.

Thanks,

Balaji

Read only

Former Member
0 Likes
530

Hi,

Please check demo program BCALV_GRID_08 to add buttons using TOOLBAR event of CL_GUI_ALV_GRID.

Also you can check this link for sample program on how to add buttons using FM REUSE_ALV_LIST_DISPLAY.

http://www.sap-basis-abap.com/abap/add-button-to-alv-toolbar-with-reuse-alv-list-display.htm

Regards,

Ferry Lianto