To Call Transaction In ALV

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

Tips by : Sujata

Related:

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

Back to ABAP Menu:
ABAP Example Hints and Tips

Return to :-
SAP Hints and Tips on Configuration and ABAP/4 Programming

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.