cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ActiveX Component SAP.Functions with Export Parameter Table of Structure

Stefan-Schnell
Active Contributor
0 Kudos
3,139

I use a VBA program to connect to an SAP system and to execute a FM. The function module has the following interface:

*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(I_RNG_ZSNR) TYPE  /GKV/BP01_TAB_RNG_ZSNR
*"  EXPORTING
*"     VALUE(E_TAB_FKZS) TYPE  /GKV/BP01_TAB_D_FKZS
*"----------------------------------------------------------------------

The importing parameter is a table of a structure:

What is the correct way to set the export parameter I_RNG_ZSNR?

Here my VBA code:

Option Explicit

Sub Test()
  Dim Func As SAPFunctions
  Dim Conn As SAPLogonCtrl.Connection
  Dim f As SAPFunctionsOCX.Function
  Dim X As Object
  Dim row As Object
  Dim Ret As Long
  
  Set Func = CreateObject("SAP.Functions.Unicode")
  If IsObject(Func) Then
    Set Conn = Func.Connection
    
    Conn.Client = "001"
    Conn.User = "BCUSER"
    Conn.Language = "EN"
    Conn.HostName = "NSP"
    Conn.SystemNumber = 0
    
    If Not Conn.Logon(0, False) Then
      Debug.Print "Connection not successful"
    Else
      Debug.Print "Connection successful"
      
      Set f = Func.Add("/GKV/BP01_K_FKZS_MASS_READ")
      If IsObject(f) Then
      
        Set X = f.Exports("I_RNG_ZSNR")
        
        Set row = X.AppendRow
        'Error: Object doesn't support this property or method
        'It not seems to be a table
        row.Cell(1, "SIGN") = "I"
        row.Cell(1, "OPTION") = "EQ"
        row.Cell(1, "LOW") = "10600035"
       
        Ret = f.Call
          
      End If
      
      Conn.Logoff
    End If
  
    Set Func = Nothing
  End If
End Sub

With COMConnector (CCo) it works perfect:

Option Explicit

Sub CCoTest()
  '-Variables-----------------------------------------------------------
    Dim SAP As CCo.COMNWRFC
    Dim hRFC As Long
    Dim rc As Integer
    Dim hFunc As Long
    Dim hFuncDesc As Long
    Dim hTable As Long
    Dim hRow As Long
    Dim hExpTable As Long
    Dim i, RowCount As Long
    Dim charBuffer As String
  Set SAP = CreateObject("COMNWRFC")
  If IsObject(SAP) Then
  
    hRFC = SAP.RFCOPENCONNECTION("ASHOST=NSP, SYSNR=00, " & _
      "CLIENT=001, USER=BCUSER")
    If hRFC Then
        
      hFuncDesc = SAP.RFCGETFUNCTIONDESC(hRFC, "/GKV/BP01_K_FKZS_MASS_READ")
      If hFuncDesc Then
        hFunc = SAP.RFCCREATEFUNCTION(hFuncDesc)
        If hFunc Then
          SAP.RFCGETTABLE hFunc, "I_RNG_ZSNR", hTable
          If hTable Then
            hRow = SAP.RFCAPPENDNEWROW(hTable)
            SAP.RFCSETCHARS hRow, "SIGN", "I"
            SAP.RFCSETCHARS hRow, "OPTION", "EQ"
            SAP.RFCSETCHARS hRow, "LOW", "10600035"
            If SAP.RFCINVOKE(hRFC, hFunc) = RFC_OK Then
              SAP.RFCGETTABLE hFunc, "E_TAB_FKZS", hExpTable
              If hExpTable Then
                SAP.RFCGETROWCOUNT hExpTable, RowCount
                SAP.RFCMOVETOFIRSTROW hExpTable
                For i = 1 To RowCount
                  hRow = SAP.RFCGETCURRENTROW(hExpTable)
                  charBuffer = Space(512)
                  SAP.RFCGETCHARS hRow, "NAME1", charBuffer, 512
                  Debug.Print charBuffer
                  If i < RowCount Then
                     SAP.RFCMOVETONEXTROW hExpTable
                  End If
                Next
              End If
            End If
          End If
          rc = SAP.RFCDESTROYFUNCTION(hFunc)
        End If
      End If
      rc = SAP.RFCCLOSECONNECTION(hRFC)
    End If
    Set SAP = Nothing
  
  End If

End Sub

How can I set the export parameter with SAP ActiveX control?

Thanks for tips and hints.

View Entire Topic
0 Kudos

I’ve had success by allowing VBA to provide structure through return fro SAP.Function call.
Use listobject type variable to hold the range table inputs.
where list object is established similar to how you used cell addresses. Just define that cell range as a ListObject.

Set rngTab = func.exports(function export park name)

Good lick

Mark, Can you porvide the code you used?