ABAP How to get ALV events

  Report Program

Over View

Let’s explain how to change to another screen when double-clicking the displayed ALV.
It is possible to transition to the standard transaction or display another ALV as in the sample below.
This time, some excerpts are described, so refer to here if you want to check the creation of ALV.

Sample Code

FORM call_alv.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      i_callback_user_command = 'USER_COMMAND'
      it_fieldcat             = it_fieldcat
    TABLES
      t_outtab                = it_data
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

ENDFORM.


FORM user_command USING ucomm    LIKE sy-ucomm
                        selfield TYPE slis_selfield.

  CASE ucomm.
*   Double Click
    WHEN '&IC1'.

      READ TABLE it_data INTO wa_data
      INDEX selfield-tabindex.

      IF selfield-fieldname = 'BANFN'.
        SET PARAMETER ID 'BAN' FIELD wa_data-banfn.
        CALL TRANSACTION 'ME53N' AND SKIP FIRST SCREEN.

      ELSEIF selfield-fieldname = 'EBELN'.
          SET PARAMETER ID 'BES' FIELD wa_data-ebeln.
          CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
        ENDIF.

      ENDIF.
  ENDCASE.

ENDFORM.

Description

Function module: Let’s set i_callback_program and i_callback_user_command when using REUSE_ALV_GRID_DISPLAY.
For general ALV reports, specify your own program name for i_callback_program and the FORM name you want to execute for i_callback_user_command.
In this example, FORM: USER_COMMAND is executed when ALV is double clicked. Check ucomm argument and only when ‘& IC1’ (double click)
Let the process run. FORM: USER_COMMAND was not executed by single click, but it is recommended to check it just in case.
Next, selfield-tabindex contains the selected row number, so let’s use that value to get the value from the internal table we passed to ALV.
* Even if it is sorted or filtered, there is no problem just by checking INDEX.
The selected column name is entered in selfield-fieldname, so check it if you want to change the processing depending on the selected column.
Please see here for the basic method of making an ALV
Please see here to change the ALV header text