cancel
Showing results for 
Search instead for 
Did you mean: 

RFC call from Excel using VBA

Ashutosht09
Participant
0 Kudos

I am trying to do an RFC call from Excel to SAP using VBA. RFC is working fine for most the RFC enabled Function Modules except DDIF_FIELDINFO_GET and DDIF_FIELDLABEL_GET.

What can be the reason for this?

Can someonme please help me with a macro code where these FMs are working.

Also can someone please help me with some tutorial on SAP connection with Excel.

<REMOVED BY MODERATOR - REQUEST OR OFFER POINTS ARE FORBIDDEN>

Edited by: Alvaro Tejada Galindo on Nov 12, 2008 9:14 AM

Accepted Solutions (0)

Answers (3)

Answers (3)

jongilman
Explorer
0 Kudos

Ashutosh,

Did you ever get this to work?  I am having the same problem with adding DDIF_FIELDINFO_GET as a remote function.  It seems to be only an issue in Excel, because other applications can call it via RFC with no issues.

holger_khn
Contributor
0 Kudos

Hello Jon.

DDIF_FIELDINFO_GET is not working for me either. But I have used another FM (/ZOPTION/LIVE_DDIF_FIELDINFO):


Public Sub RFC_FIELDINFO()
   
Dim Func As Object
Dim sapConn As Object
Dim tblFIELDTAB
Dim tblFIXED_VALUES
Dim intRow%
Dim intCol%

'**************************************************************************
'* Sub     : Call FM /ZOPTION/LIVE_DDIF_FIELDINFO                         *
'* Author  : Holger Köhn                                                  *
'* Created : 23.08.2014                                                   *
'* Changed :                                                              *
'**************************************************************************

ThisWorkbook.Sheets("TEST").Activate
Cells.Select
Selection.ClearContents
ThisWorkbook.Sheets("TEST").Range("A1").Select

'**************************************************************************
'* create RFC-Connection                                                  *
'**************************************************************************

Set sapConn = CreateObject("SAP.Functions")
sapConn.Connection.RfcWithDialog = True

If sapConn.Connection.LogOn(1, False) <> True Then
    MsgBox "Cannot Logon to SAP"
    Exit Sub
End If

DoEvents

'**************************************************************************
'* run FM /ZOPTION/LIVE_DDIF_FIELDINFO                                    *
'**************************************************************************

Set Func = sapConn.Add("/ZOPTION/LIVE_DDIF_FIELDINFO")
Func.Exports("TABNAME") = "AUFK"
Set tblFIELDTAB = Func.Tables("FIELDTAB")

If Func.Call = False Then
     MsgBox Func.Exception
     Exit Sub
Else
    Application.ScreenUpdating = False
   
        For intCol = 1 To tblFIELDTAB.ColumnCount
            ThisWorkbook.Sheets("TEST").Cells(1, intCol).Value = tblFIELDTAB.ColumnName(intCol)
        Next
       
        If tblFIELDTAB.RowCount > 0 Then
            For intRow = 1 To tblFIELDTAB.RowCount
                For intCol = 1 To tblFIELDTAB.ColumnCount
                    ThisWorkbook.Sheets("TEST").Cells((intRow + 1), intCol).Value = tblFIELDTAB(intRow, intCol)
                Next
            Next
            ThisWorkbook.Sheets("TEST").Activate
        End If
        Columns.AutoFit
   
    Application.ScreenUpdating = True
End If

'**************************************************************************
'* clear tblFIELDTAB                                                      *
'**************************************************************************

Do Until tblFIELDTAB.RowCount = 0
     Call tblFIELDTAB.Rows.Remove(1)
Loop

Set sapConn = Nothing
Set Func = Nothing
Set tblFIELDTAB = Nothing

End Sub

Former Member
0 Kudos

Hi,

Have you checked this document:

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/608058b4-81b7-2910-4598-8a66dcdb...

If you enable tracing you can check the parameters required to call the RFC Function and especially their order - because it can sometimes be another order that you can read from SAP definitions.

Enable tracing by setting the environment variables:

RFC_TRACE=1

RFC_TRACE_DIR=c:TMP

- or by setting

oBAPICtrl.loglevel = 9

oBAPICtrl.Connection.TraceLevel = 1

regards

Anders

former_member226203
Active Contributor
0 Kudos

Plz chk this link: