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

Dynamic button on ALV toolbar

Former Member
0 Likes
5,549

Hi all,

I have developed an ALV Grid with two buttons SAVE and EXIT.

The list that is displayed in ALV is SAVED to the ZTABLE when the user clicks the SAVE button based on some conditions.....

My requirement is after SAVING to the ZTABLE ,a 3rd Button has to appear on ALV GRID TOOLBAR.

How this can be achieved........?

Any input is greatly appreciated....will be rewarded by points....

Thanks

SE-

Hi all,

I have developed an ALV Grid with two buttons SAVE and EXIT.

The list that is displayed in ALV is SAVED to the ZTABLE when the user clicks the SAVE button based on some conditions.....

My requirement is after SAVING to the ZTABLE ,a 3rd Button has to appear on ALV GRID TOOLBAR.

How this can be achieved........?

Any input is greatly appreciated....will be rewarded by points....

Thanks

SE-

4 REPLIES 4
Read only

Former Member
0 Likes
2,070

hi se,

pls see the below links.they may help you.

erpgenie.com/abaptips/index.php?option=com_content&task=view&id=437&Itemid=61&bsb_midx=-1 - 66k

www.erpgenie.com/abaptips/content/view/141/33/ - 101k

www.blogtoplist.com/software/blogdetails-14026.html - 28k

www.topblogarea.com/sitedetails_11929.html - 29k

abap-gallery.blogspot.com/2007/07/add-toolbar-on-selection-screen.html - 58k -

www.abap4.it/download/ALV.pdf

regards

karthikeya.

reward me points if it helps you

Read only

Former Member
0 Likes
2,070

On the toolbar event of your alv grid, all the button as shown in the code below.



FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set .
DATA: ls_toolbar TYPE stb_button.

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


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 .


"On saving, Call the refresh_table_display method.

Hope this helps.

Thanks,

Balaji

Read only

0 Likes
2,070

Hi Balaji,

Thanks for the reply......

I know how to create the button on the ALV Toolbar......I have created two buttons already on the ALV toolbar.....

BUT MY REQUIREMENT IS 3 rd BUTTON has to appear dynamically only if SAVE BUTTON IS CLICKED and the data is saved to the database..

IF the USER CLICKS THE CANCEL BUTTON THIS 3 rd BUTTON should NOT BE VISIBLE on the ALV TOOLBAR.....

Is it possible or feasible to do this way?

Any input is greatly appreciated.....

Thanks,

SE.

Read only

0 Likes
2,070

Hello

Bascially the previous answers have described the solution. Below you see sample report ZUS_SDN_ALV_EVT_TOOLBAR_1 which may be useful. The crucial parts are:


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

  PUBLIC SECTION.

    CLASS-DATA:
      md_okcode type ui_func.  " store ok_code 'SAVE'


    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... :-)

*   (3) Add new dropdown menu
    IF ( md_okcode = 'SAVE' ).

*     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


*---------------------------------------------------------------------*
*       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.

  TRANSLATE ok_code to UPPER CASE.

  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.

    WHEN 'SAVE'.
      lcl_eventhandler=>md_okcode = ok_code.


    WHEN OTHERS.
*     do nothing
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "PAI INPUT

And here is the entire coding:


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALV_EVT_TOOLBAR_1
*&
*&---------------------------------------------------------------------*
*& 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_1.


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.




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

  PUBLIC SECTION.

    CLASS-DATA:
      md_okcode type ui_func.  " store ok_code 'SAVE'


    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... :-)

*   (3) Add new dropdown menu
    IF ( md_okcode = 'SAVE' ).

*     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.

  TRANSLATE ok_code to UPPER CASE.

  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.

    WHEN 'SAVE'.
      lcl_eventhandler=>md_okcode = ok_code.


    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