Add User command functionality to ALVgrid report

In order to add user command functioality to the ALV grid you need to perform the following steps:

1. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include 'USER_COMMAND' FORM
2. Create 'USER_COMMAND' FORM


 call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_repid
            i_callback_top_of_page   = 'TOP-OF-PAGE'
            I_callback_user_command = 'USER_COMMAND'   "see FORM 
            is_layout               = gd_layout
            it_fieldcat             = fieldcatalog[]
            i_save                  = 'X'
       tables
            t_outtab                = it_ekko
       exceptions
            program_error           = 1
            others                  = 2.

*----------------------------------------------------------*
*       FORM USER_COMMAND                                  *
*----------------------------------------------------------*
*       --> R_UCOMM                                        *
*       --> RS_SELFIELD                                    *
*----------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.
* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
    IF rs_selfield-fieldname = 'EBELN'.
*     Read data table, using index of row user clicked on
      READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
*     Set parameter ID for transaction screen field
      SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
      CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDCASE.
ENDFORM.

Related Articles

ALV grid display - Example code and information for creating ALV grids using Function modules
Add User command functionality to ALVgrid report
ALV totals text
Display traffic light icon on ALV grid report
ALV grid display (inc. column total)
SAP ALV consistancy check
Change colour of individual SAP ALV cells within an ALV grid report
SAP ALV row colour change and making each individual row a different color
Make all or individual fields of an ALV grid editable
Add Footer functionality to ALVgrid report
Enhanced ALV grid display
Add Event functionality to ALVgrid report
Example Output from ALV grid display
Example Output from ALV grid display with report heading
Add User command functionality to ALVgrid report
Add Title heading to ALV Grid incluing image or logo
Row selection of ALV grid
Add Default Sorting to ALVgrid report
ALV list display
ALV list display(ALV_LIST)
Example ALV report output
Internal table structure required for FM 'REUSE_ALV_FIELDCATALOG_MERGE'
Multiple ALV list display
Various ways to build an ALV Fieldcatalog within SAP
Add image to ALV report using OAOR tcode, without replacing the enjoy SAP logo
Transport an ALV variant with SAP