Register Login

How to Call Transaction In ALV

Updated May 18, 2018

In my report, I am using ALV grid display to display purchase order number, material docu. number.  If I click on purchasing docu number it has to call transaction ME23N for the purchase order number that I have clicked and if I click material document number it has to  call trainsaction MIGO for the corresponding material document number. How can I do it in ALV?

Check out the following code that may help:

*&---------------------------------------------------------------------*
*& Report  Z_TEST001
*&
*&---------------------------------------------------------------------*

REPORT  Z_TEST001.
TYPE-POOLS:  slis.
tables: rseg.

DATA: begin of TAB_ARSEG occurs 0.
        INCLUDE STRUCTURE RSEG.
DATA: END OF TAB_ARSEG.
DATA: T_FIELDCAT TYPE slis_t_fieldcat_alv.
DATA: c_user_command TYPE slis_formname VALUE 'USER_COMMAND'.

START-OF-SELECTION.

*********  <<<  YOUR CODE  >>> ***********************
select * from rseg into table tab_arseg where BELNR = '5300000022'.

END-OF-SELECTION.

perform build_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
    i_buffer_active                   = space
    i_callback_program                = sy-repid
   I_CALLBACK_USER_COMMAND            = c_user_command
*   I_STRUCTURE_NAME                  =
*   IS_LAYOUT                         =
   IT_FIELDCAT                        = T_FIELDCAT[]
  TABLES
    T_OUTTAB                          = TAB_ARSEG
 EXCEPTIONS
   PROGRAM_ERROR                      = 1
   OTHERS                             = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

**&------------------------------------------------------------------
---*
**&      Form  USER_COMMAND
**&------------------------------------------------------------------
---*
FORM USER_COMMAND USING F_UCOMM LIKE SY-UCOMM
                I_SELFIELD TYPE SLIS_SELFIELD.

  DATA: F_SUBRC LIKE SY-SUBRC,
        s_arseg like tab_arseg.
  READ TABLE tab_arseg INDEX i_selfield-tabindex INTO s_arseg.

    CASE F_UCOMM.
        WHEN '&IC1'.
        CASE i_SELFIELD-SEL_TAB_FIELD.
        WHEN 'TAB_ARSEG-BELNR'.
          CHECK NOT S_ARSEG-BELNR IS INITIAL.
          SET PARAMETER ID 'RBN' FIELD S_ARSEG-BELNR.
          SET PARAMETER ID 'GJR' FIELD S_ARSEG-GJAHR.
          CALL TRANSACTION 'MIR4' AND SKIP FIRST SCREEN.
        ENDCASE.
    ENDCASE.
ENDFORM.

**&------------------------------------------------------------------
---*
**&      Form  build_fieldcat
**&------------------------------------------------------------------
---*

FORM build_fieldcat .
 DATA: FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  CLEAR FIELDCAT.
  FIELDCAT-FIELDNAME     = 'BELNR'.
  FIELDCAT-TABNAME       = 'TAB_ARSEG'.
  FIELDCAT-REF_TABNAME   = 'RSEG'.
  FIELDCAT-REF_FIELDNAME = 'BELNR'.
  fieldcat-hotspot   = 'X'.
  FIELDCAT-COL_POS       = 1.
  APPEND FIELDCAT TO t_fieldcat.

  CLEAR FIELDCAT.
  FIELDCAT-FIELDNAME     = 'GJAHR'.
  FIELDCAT-TABNAME       = 'TAB_ARSEG'.
  FIELDCAT-REF_TABNAME   = 'RSEG'.
  FIELDCAT-REF_FIELDNAME = 'GJAHR'.
  FIELDCAT-COL_POS       = 2.
  APPEND FIELDCAT TO t_fieldcat.

ENDFORM.                    " build_fieldcat


×