SAP ALV Tutorial – Add button to ToolBar
In this ALV tutorial serial, we have already learned how to handle event. This article will show you how to add your custom button to the toolbar of alv. As usual, we will introduce it both in object-oriented method and the function module method. You can choose the method you like.
Function Module Method
Because the function module method default use the full screen and the ALV button is implemented using GUI Status. If you want to add your own button to tool bar, what you want to do is just copy the standard GUI status out and make your own modification.
Step 1. Copy standard ALV GUI status to your own program from program SAPLKKBL GUI Status STANDARD_FULLSCREEN.
Go to this program and select status, click on GUI Status -> Copy, then enter your Z program and the name you want for the new status.
Step 2. Add or delete buttons in the z-veriosn of your GUI status.
Step 3. There are two way to use your own GUI status in the ALV. A simple way is that pass the status name to function module as a parameter.
call function 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = 'ZSDBOLST_REPORT' i_callback_pf_status_set = 'STANDARD' i_callback_user_command = 'USER_COMMAND' i_structure_name = 'I_BOLACT' i_grid_title = 'BOL Action Report'(031) is_layout = gs_layout it_fieldcat = gt_fieldcat[] i_save = 'A' is_variant = v_variant TABLES t_outtab = i_bolact EXCEPTIONS program_error = 1 others = 2.
Another way is that register an subroutine for event ‘PF_STATUS_SET’. In the routine, you use statement “SET PF-STATUS ‘STANDARD’.”.
Step 4. This is an optional step, but we also need to register event ‘USER_COMMAND’ to handle your custom function code.
At last, also it is not an common requirement, but we can exclude some button from standard ALV toolbar without copying it out.
First, we need to define an internal table to contain excluded function code.
DATA : it_exclude TYPE slis_t_extab, wa_exclude TYPE slis_extab.
Then, add the excluded button from ALV toolbar and pass this internal table to the funciton module ‘REUSE_ALV_GRID_DISPLAY’.
wa_exclude-fcode = '&;OUP'. APPEND wa_exclude TO it_exclude. CLEAR wa_exclude. wa_exclude-fcode = '&;ODN'. APPEND wa_exclude TO it_exclude. … CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = rep_id i_callback_user_command = 'COMMAND' i_callback_top_of_page = 'TOP' i_grid_title = wa_title is_layout = wa_layout it_fieldcat = it_field it_excluding = it_exclude "excule buttons
Object Oriented Method
For object oriented method, SAP has alreay provide some example code for developer to reference. Report ‘BCALV_GRID_08′ is a good start for adding your own button to ALV. Because the tool bar is part of custom control, you must use method provide by class ‘CL_GUI_GRID’ to add your own toolbar. If you can access SAP system, you can find a very detailed comments in the code, and it is also easy to use.