Friday, May 2, 2008

SAP ABAP CALL TRANSACTION from a remote system

SAP ABAP CALL TRANSACTION from a remote system.

You can use the following Remote Function Module to call any of the SAP transactions from a emote system. The following is one of the several ways by which an interface can be achieved.

ABAP4_CALL_TRANSACTION


The remote system can be either SAP or a NON SAP system. Please note that you will need the necessary authorizations in the calling systems before initiating the call. Also if you are using a NON SAP System to make ca call then you need to use the J2EE connector or the .NET connector and call the RFC from the respective systems. The developer who is making the call should have sufficient knowledge of J2EE and/or .NET. The ABAP developer and the NON SAP systems developer need to work closely to make the interface successful.

EXAMPLE of calling an SAP transaction remotely.

The following example skips the first screen by passing the value 'OR' for order type.

REPORT ZEX_ABAB4CALLTRANSACTION .

Data: itab_bdc like BDCDATA occurs 0 with header line,
      itab_SPAGPA like RFC_SPAGPA  occurs 0 with header line ,
      itab_messTab like BDCMSGCOLL occurs 0 with header line.

Data: d_sysubrc like sy-subrc.

move: 'AAT' to itab_SPAGPA-PROGRAM,
      '0101'     to itab_bdc-DYNPRO,
      ' '        to itab_bdc-DYNBEGIN,
      'VBAK-AUART' to itab_bdc-FNAM,
      'TA' to itab_bdc-FVAL.

APPEND itab_bdc.


CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
  EXPORTING
    TCODE                         = 'VA01'
   SKIP_SCREEN                    = 'X'
   MODE_VAL                       = 'A'
   UPDATE_VAL                     = 'A'
 IMPORTING
   SUBRC                          = d_sysubrc
 TABLES
   USING_TAB                      = itab_bdc
   SPAGPA_TAB                     = itab_SPAGPA
   MESS_TAB                       = itab_messTab
 EXCEPTIONS
   CALL_TRANSACTION_DENIED        = 1
   TCODE_INVALID                  = 2
   OTHERS                         = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


The following example does not skip the first screen.

REPORT ZEX_ABAB4CALLTRANSACTION .

Data: itab_bdc like BDCDATA occurs 0 with header line,
      itab_SPAGPA like RFC_SPAGPA  occurs 0 with header line ,
      itab_messTab like BDCMSGCOLL occurs 0 with header line.

Data: d_sysubrc like sy-subrc.

CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
  EXPORTING
    TCODE                         = 'VA01'
   SKIP_SCREEN                    = ' '
   MODE_VAL                       = 'A'
   UPDATE_VAL                     = 'A'
 IMPORTING
   SUBRC                          = d_sysubrc
 TABLES
   USING_TAB                      = itab_bdc
   SPAGPA_TAB                     = itab_SPAGPA
   MESS_TAB                       = itab_messTab
 EXCEPTIONS
   CALL_TRANSACTION_DENIED        = 1
   TCODE_INVALID                  = 2
   OTHERS                         = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


EXAMPLE of calling an SAP transaction remotely.

The following example skips the first screen by passing the value 'OR'  to SPA/GPA

REPORT ZEX_ABAB4CALLTRANSACTION .

Data: itab_bdc like BDCDATA occurs 0 with header line,
      itab_SPAGPA like RFC_SPAGPA  occurs 0 with header line ,
      itab_messTab like BDCMSGCOLL occurs 0 with header line.

Data: d_sysubrc like sy-subrc.

move: 'AAT' to itab_spagpa-PARID,
           'OR'     to itab_spagpa-parval.


APPEND itab_spagpa.


CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
  EXPORTING
    TCODE                         = 'VA01'
   SKIP_SCREEN                    = 'X'
   MODE_VAL                       = 'A'
   UPDATE_VAL                     = 'A'
 IMPORTING
   SUBRC                          = d_sysubrc
 TABLES
   USING_TAB                      = itab_bdc
   SPAGPA_TAB                     = itab_SPAGPA
   MESS_TAB                       = itab_messTab
 EXCEPTIONS
   CALL_TRANSACTION_DENIED        = 1
   TCODE_INVALID                  = 2
   OTHERS                         = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.