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: 

How to exclude toolbar in ALV dynamically

Former Member
0 Kudos

Hi, Experts

I can exclude some toolbar by passing the internal table lt_exclude when first calling the method as below:

call method g_grid->set_table_for_first_display

EXPORTING

it_toolbar_excluding = lt_exclude

CHANGING

it_fieldcatalog = pt_fieldcat

it_outtab = pt_outtab.

Now, my problem is after that, in runtime, how can change excluding toolbar again?

Thanks a lot.

Tom

7 REPLIES 7

Former Member
0 Kudos

Tom,

I have spent a bit of time on this. It does not appear that you can after instantiating the grid.

It appears that you must release/destroy the grid and re-build with the new toolbar. Hopefully, this is not a common event OR you can leave the buttons on the bar at all times... and trap WHEN it is appropriate. If not appropirate then msg box the user.

0 Kudos

Uwe,

Certainly, you can disable and enable buttons "on the fly." But I think this developer wants buttons to appear and disappear from the screen. Not disable them as in your example.

Tom,

Can you clarify your needs?

0 Kudos

Hello John

If you want the buttons to disappear here is the coding of the event handler (please refer to my previous posting):

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

  METHOD handle_toolbar.
    DATA:
      ls_button    TYPE stb_button.


    ADD 1 TO md_cnt. " a simple counter

<b>*   Simply delete the entries from the toolbar instance</b>
    DO md_cnt TIMES.
      DELETE e_object->mt_toolbar INDEX 1.
    ENDDO.



  ENDMETHOD.                    "handle_toolbar

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION

Regards

Uwe

0 Kudos

Hi Uwe,

Thanks a lot for the code, i'm already gonna need it.

You deserve the 10 points.

Regards,

Eric

uwe_schieferstein
Active Contributor
0 Kudos

Hello Tom

Of course you can change the toolbar dynamically. You have to call method <b>grid->set_toolbar_interactive</b> and an event handler method for <b>event TOOLBAR</b>.

The following sample (modified version of BCALV_GRID_DEMO) shows how to do (my coding is in bold):

[code]PROGRAM test.

DATA: ok_code LIKE sy-ucomm,

gt_sflight TYPE TABLE OF sflight,

g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

<b>----


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

DATA:

ls_button TYPE stb_button.

ADD 1 TO md_cnt. " a simple counter

LOOP AT e_object->mt_toolbar INTO ls_button FROM 1 TO md_cnt.

ls_button-disabled = 'X'.

MODIFY e_object->mt_toolbar FROM ls_button.

ENDLOOP.

ENDMETHOD. "handle_toolbar

ENDCLASS. "lcl_eventhandler IMPLEMENTATION</b>

START-OF-SELECTION.

----


  • MAIN *

----


SELECT * FROM sflight INTO TABLE gt_sflight.

CALL SCREEN 100.

----


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

CREATE OBJECT grid1

EXPORTING i_parent = g_custom_container.

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

it_outtab = gt_sflight.

<b>*$Comment: Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR grid1.</b>

ENDIF.

<b>*$Comment: Toolbar can be modified on-the-fly

grid1->set_toolbar_interactive( ). " raises event TOOLBAR </b>

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[/code]

When you run the program simply push several times the ENTER button. You will see how the buttons of the toolbar are inactivated one by one.

Regards

Uwe

Former Member
0 Kudos

Tom

Try this to make the toolbar invisible:

call method g_grid->set_toolbar_visible

IMPORTING

visible = 0.

Then when you want to make the toolbar visible again then set visible = 1.

Regards

Andy

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hey Tom, did Uwe's solution work for ya? Let us know and if so, please award points accordingly and mark as solved. Thanks.

Regards,

Rich Heilman