ABAP – Refresh ALV Grid

Home / SAP / ABAP Coding / ABAP – Refresh ALV Grid

I recently had to go through and add a button to refresh ALV grid in a custom transaction.  I initially expected this to be easy.  And looking back, it actually is pretty easy, if you kept your program modular.  However, I had to handle things differently than I expected.

I thought I would need to do something with the refresh button that comes with the standard ALV grid.  However, after a some extensive google digging, I couldn’t find anything that told me how I could do that.  Everyone else took care of the issue by creating their own button.  Here’s the basic steps to do it yourself.

You will need to setup the following 2 handlers.  I created a local class to house these methods.  You can take care of it anyway you prefer.

DATA: l_event_receiver_grid TYPE REF TO lcl_event_receiver.
(where lcl_event_receiver is the local class)

SET HANDLER l_event_receiver_grid->on_toolbar_add_button
FOR grid.
SET HANDLER l_event_receiver_grid->on_user_command
FOR grid.

For the add_button:

DATA: ls_toolbar TYPE stb_button.
MOVE ‘ZRFO’ TO ls_toolbar-function.
MOVE ICON_REFRESH TO ls_toolbar-icon.
MOVE ‘Refresh’ to ls_toolbar-quickinfo.
MOVE ‘ ‘ TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
this adds a button that looks exactly like the standard refresh button.  You can feel free to play around with the look and feel, but this will get your started.

In the on_user_command, you will need to look at sy-ucomm, and find when it matches ZRFO (in this example).

refresh grid table.
rebuild the grid table

then call the display method.  For me, I uised the set_table_for_first_display method.  So updating the grid table and calling this is enough to perform the refresh.

This will give you a great start if you want to add a refresh button your custom transaction.

I hope you find this helpful.

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *