We have added search box. Key in SAP issue keyword to search
TopBottom

Announcement: wanna exchange links? contact me at sapchatroom@gmail.com.

Re: [sap-dev] RFC Call VBA Excel AFVV Table Problems

Posted by Admin at
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

Reply from Pierre_Richer on Aug 3 at 9:49 AM
Hi Pietro,

Here is a code sample of an RFC Call from VBA. Maybe you can inspire
your's from this.

Class clsRFC

Option Explicit
Private msapRFC As Object
Private msapRFCC As Object

Private Sub Class_Initialize()

Set msapRFCC = CreateObject("SAP.Functions")

End Sub

Private Sub Class_Terminate()

Set msapRFCC = Nothing

End Sub

Public Sub Add(strRFCName As String)

Set msapRFC = msapRFCC.Add(strRFCName)

End Sub

Public Function SetParams(strVrsio, strVkorg, strVtweg, strSaisjLow,
strSaisjHigh) As Object

Dim I_VRSIO As Object
Dim I_VKORG As Object
Dim I_VTWEG As Object
Dim I_SAISJ_FROM As Object
Dim I_SAISJ_TO As Object
Dim E_RETURN As Object
Dim E_MESSAGE As Object
Dim T_TURNOVER As Object

Set I_VRSIO = msapRFC.Exports("I_VRSIO")
Set I_VKORG = msapRFC.Exports("I_VKORG")
Set I_VTWEG = msapRFC.Exports("I_VTWEG")
Set I_SAISJ_FROM = msapRFC.Exports("I_SAISJ_FROM")
Set I_SAISJ_TO = msapRFC.Exports("I_SAISJ_TO")
Set E_RETURN = msapRFC.Imports("E_RETURN")
Set E_MESSAGE = msapRFC.Imports("E_MESSAGE")
Set T_TURNOVER = msapRFC.Tables("T_TURNOVER")

I_VRSIO.Value = strVrsio
I_VKORG.Value = strVkorg
I_VTWEG.Value = strVtweg
I_SAISJ_FROM.Value = strSaisjLow
I_SAISJ_TO.Value = strSaisjHigh

msapRFC.Call

Set SetParams = T_TURNOVER

Set I_VRSIO = Nothing
Set I_VKORG = Nothing
Set I_VTWEG = Nothing
Set I_SAISJ_FROM = Nothing
Set I_SAISJ_TO = Nothing
Set E_RETURN = Nothing
Set E_MESSAGE = Nothing
Set T_TURNOVER = Nothing

End Function

EndClass

Sheet1 Button "Get Data"

Private Sub btnGet_Click()
On Error GoTo ErrTrap
Dim record As Object
Dim sapColumn As Object
Dim intRowCount As Long
Dim intColCount As Integer
Dim blnCancel As Boolean

Set mobjRFC = New clsRFC

mobjRFC.Add "Z_MAP_TURNOVER"
Set record = mobjRFC.SetParams(Sheet1.Cells(1, 9), Sheet1.Cells(2, 7),
Sheet1.Cells(1, 7), Sheet1.Cells(3, 7), Sheet1.Cells(3, 8))

'Sheet1.range(Cells(6, 1), Cells(205, 32)).Delete

For intRowCount = 1 To record.RowCount
For intColCount = 1 To record.ColumnCount
Sheet1.Cells(intRowCount + 5, intColCount) = record.Rows
(intRowCount).Value(intColCount)
Next
Next
Set sapColumn = Nothing

Exit Sub
ErrTrap:
MsgBox Err.Description

End Sub


If you want the function SetParams to return more than one array or other
kind of objects, change it's type to a collection.


Regards,
Pierre

---------------Original Message---------------
From: pietro_cantoni
Sent: Friday, August 03, 2012 9:13 AM
Subject: RFC Call VBA Excel AFVV Table Problems

Hi to Everyone.
I'm trying to download to Excel some data from AFVV table usign RFC via VBA.
Hereafter my code.
Can you help me to catch the possible issues within my code?
Thanks in advance
Dim LogonControl
Dim conn
Dim funcControl
Dim TableFactoryCtrl
Dim RFC_READ_TABLE
Dim eQUERY_TAB
Dim TOPTIONS
Dim TDATA
Dim TFIELDS

Private Sub command1_CLICK()


Set LogonControl = CreateObject("SAP.LogonControl.1")
Set funcControl = CreateObject("SAP.Functions")
Set conn = LogonControl.NewConnection


conn.System = "010"
conn.Client = "02 - PAP - [R/3 PRODUCTION SYSTEM] - HP"
conn.Language = "IT"
conn.User = "user"
conn.Password = "pwd"
retcd = conn.LOGON(0, False)
If retcd <> True Then
MsgBox " Cannot log on! "
MsgBox retcd
Stop
Else
End If
funcControl.Connection = conn


command3_click

End Sub


Private Sub command3_click()
Const attachpath = "C:\Query.CSV"

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject" ;)
Set filOutput = objFileSystemObject.CreateTextFile(attachpath, True)

Set RFC_READ_TABLE = funcControl.Add("RFC_READ_TABLE")
Set strExport1 = RFC_READ_TABLE.Exports("QUERY_TABLE")
Set strExport2 = RFC_READ_TABLE.Exports("DELIMITER")
Set tbloptions = RFC_READ_TABLE.Tables("OPTIONS")
Set tblData = RFC_READ_TABLE.Tables("DATA")
Set tblFields = RFC_READ_TABLE.Tables("FIELDS")


strExport1.Value = "AFVV"
strExport2.Value = ","

tbloptions.Rows.Add
tbloptions.Value(1, "TEXT") = "AUFPL EQ '0000168029'"

tblFields.AppendRow
tblFields(1, "FIELDNAME") = "AUFPL"

If RFC_READ_TABLE.Call = True Then
If tblData.RowCount > 0 Then
For intRow = 1 To tblData.RowCount
filOutput.WriteLine tblData(intRow, "WA")
Next
Else
MsgBox "No records returned"
End If
Else
MsgBox "ERROR CALLING SAP REMOTE FUNCTION CALL"
End If
End Sub

 
Reply to this email to post your response.
 
__.____._
Manage Settings | Unsubscribe | Create FAQ | Send Feedback
  
Copyright © 2012 Toolbox.com and message author.
Toolbox.com 4343 N. Scottsdale Road Suite 280, Scottsdale, AZ 85251
Pierre_Richer  
Senior SAP System Analyst
achievements
 
Mark as helpful
View this online
Ask a new question
 
In the Spotlight
Have an SAP Question? Ask Your Peers at Toolbox for IT

_.____.__

0 comments:

Post a Comment

T r a n s l a t e to your language