Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

How To Use tRFC/qRFC Calls With VBScript Via CCo

I introduced COM Connector (CCo) here. Here now an example how to use transactional RFC calls with VBScript via CCo. The queued RFC calls are commented. You can find more information about the different RFC variants here.

'-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------
    Option Explicit

  '-Constants-----------------------------------------------------------
    Const RFC_OK = 0

  '-Sub Main------------------------------------------------------------
    Sub Main()

      '-Variables-------------------------------------------------------
        Dim SAP, hRFC, rc, TID, hTrans, hFuncDesc, hFunc

      Set SAP = CreateObject("COMNWRFC")
      If Not IsObject(SAP) Then
        Exit Sub
      End If

      hRFC = SAP.RfcOpenConnection("ASHOST=ABAP, SYSNR=00, " & _
        "CLIENT=001, USER=BCUSER")
      If hRFC = 0 Then
        Set SAP = Nothing
        Exit Sub
      End If

      hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "RFC_PING")
      If hFuncDesc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Sub
      End If

      hFunc = SAP.RfcCreateFunction(hFuncDesc)
      If hFunc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Sub
      End If

      If SAP.RfcGetTransactionID(hRFC, TID) <> RFC_OK Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Sub
      End If

      'qRFC
      'hTrans = SAP.RfcCreateTransaction(hRFC, TID, "StefansQueue")

      hTrans = SAP.RfcCreateTransaction(hRFC, TID, "")
      If hTrans = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Set SAP = Nothing
        Exit Sub
      End If

      If SAP.RfcInvokeInTransaction(hTrans, hFunc) = RFC_OK Then
 
        If SAP.RfcSubmitTransaction(hTrans) = RFC_OK Then

          'qRFC
          'MsgBox "Look in TAC SMQ2 (Inbound Queue)"

          MsgBox "Look in table ARFCRSTATE for TID " & TID

          rc = SAP.RfcConfirmTransaction(hTrans)

        End If

      End If

      rc = SAP.RfcDestroyTransaction(hTrans)
      rc = SAP.RfcDestroyFunction(hFunc)
      rc = SAP.RfcCloseConnection(hRFC)
      Set SAP = Nothing

    End Sub

  '-Main----------------------------------------------------------------
    Main()

'-End-------------------------------------------------------------------

Enjoy it.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.