Quantcast
Channel: SCN : Document List - Scripting Languages
Viewing all articles
Browse latest Browse all 100

ActiveX Component SAP.Functions with Export Parameter String

$
0
0

Hello community,

 

I use a VBS program with the SAP ActiveX components to connect to an SAP system and to execute a FM. Here the function module:


FUNCTION ZRFCINTERFACETEST.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  EXPORTING

*"     VALUE(E_RETURN) TYPE  STRING

*"----------------------------------------------------------------------

 

  E_RETURN = 'This is a test'.

 

ENDFUNCTION.


The function module has one export parameter from the type string. Here the VBS program:


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

 

  '-Directives----------------------------------------------------------

    Option Explicit

 

  '-Variables-----------------------------------------------------------

    Dim rfcFunc, rfcCon, Func

 

  '-Sub Main------------------------------------------------------------

    Sub Main()

 

      Set rfcFunc = CreateObject("SAP.Functions")

      'Set rfcFunc = CreateObject("SAP.Functions.Unicode")

      If Not IsObject(rfcFunc) Then

        Exit Sub

      End If

 

      Set rfcCon = rfcFunc.Connection

 

      rfcCon.ApplicationServer = "BCP"

      rfcCon.System = "BCP"

      rfcCon.SystemNumber = "65"

      rfcCon.User = "HUGO"

      rfcCon.Client = "099"

      rfcCon.Language = "EN"

 

      If Not rfcCon.Logon(0, False) Then

        Exit Sub

      End If

 

      Set Func = rfcFunc.Add("ZRFCINTERFACETEST")

      '-Error here: SAP data type not supported

 

      If Func.Call Then

        MsgBox Func.Imports("E_RETURN")

      Else

        MsgBox Func.Exception

      End If

 

      rfcCon.Logoff

 

      Set rfcCon = Nothing

 

    End Sub

 

  '-Main----------------------------------------------------------------

    Main

 

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


If the interpreter reaches the line Set Func = rfcFunc.Add("ZRFCINTERFACETEST") I get the following error:


DataTypeNotSupported.jpg

The SAP ActiveX components doesn't support string parameters. Also it doesn't support table parameters - look here. I think the ActiveX components are phased out. You can find an unanswered question about the future of ActiveX components here.


With the COM Connector (CCo) it works perfect without any errors:


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

 

  '-Directives----------------------------------------------------------

    Option Explicit

 

  '-Constants-----------------------------------------------------------

    Const RFC_OK = 0

 

  '-Variables-----------------------------------------------------------

    Dim SAP, hRFC, rc, hFuncDesc, hFunc, charBuffer, strLen

 

  '-Main----------------------------------------------------------------

    Set SAP = CreateObject("COMNWRFC")

    If IsObject(SAP) Then

      hRFC = SAP.RfcOpenConnection("ASHOST=ABAP, SYSNR=00, " & _

        "CLIENT=001, USER=BCUSER")

      If hRFC Then

        hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "ZRFCINTERFACETEST")

        If hFuncDesc Then

          hFunc = SAP.RfcCreateFunction(hFuncDesc)

          If hFunc Then

            If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then

              rc = SAP.RfcGetString(hFunc, "E_RETURN", charBuffer, _

                255, strLen)

              MsgBox charBuffer

            End If

          rc = SAP.RfcDestroyFunction(hFunc)

          End If

        End If

        rc = SAP.RfcCloseConnection(hRFC)

      End If

      Set SAP = Nothing

    End If

 

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


Good scripting.


Cheers

Stefan


Viewing all articles
Browse latest Browse all 100

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>