Add custom button onto ALV Grid in SAP
Posted by Admin, under ABAP, ALV, TutorialAs an ABAPer, you must have thought of adding your custom button to the standard ALV Grid called in your custom program. Here are the steps for achieving this goal.

TO achieve this you should copy the ‘STANDARD’ GUI status from program SAPLKKBL using transaction SE90 –>Programming SubObjects–> Gui Status.
Steps:
1). Using SE80/SE41 you can copy a GUI status from one program to another. It mentions which one in the FM’s help.
2). Create a form named like so:
Code:
*****************************************************************
* Form Set_pf_status
* Notes: Called by FM REUSE_ALV_GRID_DISPLAY
*****************************************************************
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS ‘ZSTANDARD’.
ENDFORM. “Set_pf_status
In the above case the GUI status copied was named ZSTANDARD and adjusted accordingly, adding and removing the desired buttons. A button was added called ‘%DELETE’.
3). Create the following report:
Code:
*****************************************************************
* Form User_command
* Notes: Called by FM REUSE_ALV_GRID_DISPLAY
* Detects whether the icon/button for
* ‘Return Tag Deletion’ has been pressed. If it has then
* detect whether any rows have been highlighted and then
* set the delete flag.
*****************************************************************
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: li_count TYPE I.
IF r_ucomm EQ ‘%DELETE’.
LOOP AT %g00 WHERE mark EQ ‘X’.
ADD 1 TO li_count.
ENDLOOP.
IF li_count GT 0.
gc_delete_flag = ‘X’.
r_ucomm = ‘&F03′. “Back arraow
ELSE.
MESSAGE W000 WITH ‘Please highlight the rows to be deleted!’.
ENDIF.
ENDIF.
ENDFORM. “User_command
As I’ve added an extra button to indicate which records should be deleted I need to identify a form to be called to process when this button is chosen.
Then when you call the ALV function you to specify the following extra details:
Code:
call function ‘REUSE_ALV_GRID_DISPLAY’
exporting i_callback_program = gc_repid
I_CALLBACK_PF_STATUS_SET = ‘SET_PF_STATUS’
I_CALLBACK_USER_COMMAND = ‘USER_COMMAND’
i_grid_title = lc_grid_title
is_layout = lc_layout
it_fieldcat = gt_fieldcat
it_sort = sort
i_save = l_save
is_reprep_id = l_bbs_id
is_variant = l_variant
tables t_outtab = %g00
exceptions program_error = 1
others = 2.
The parameters in capitals are the extra ones that need to be added.
That should be it!
You might also be interested in these posts:

Post a Comment