cancel
Showing results for 
Search instead for 
Did you mean: 

Extract data from SAP using VBScript

Former Member
0 Kudos

Hi,

I am trying to extract data out of SAP using VBScript. I remember this worked earlier, but ever since we upgraded to VB7, I am getting an error. Can you please look into this?

code:

Dim R3, MyFunc, App, objFileSystemObject, filOutput, objmessage As Object

Dim nTotalRecords As Long

' Define the objects to hold IMPORT parameters

Dim QUERY_TABLE As Object

Dim DELIMITER As Object

Dim NO_DATA As Object

Dim ROWSKIPS As Object

Dim ROWCOUNT As Object

' Define the objects to hold the EXPORT parameters

' None for RFC_TABLE_READ

' Define the objects to hold the TABLES parameters

' Where clause

Dim OPTIONS As Object

' Fill with fields to return. After function call will hold

' detailed information about the columns of data (start position

' of each field, length, etc.

Dim FIELDS As Object

' Holds the data returned by the function

Dim tDATA As Object

' Use to write out results

Dim ROW As Object

Dim Result As Boolean

Dim iRow, iColumn, iStart, iStartRow, iField, iLength As Integer

Dim var_return As String

Public Function RFC_READ_TABLE_MARA()

'**********************************************

'Create Server object and Setup the connection

'**********************************************

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject"

attachpath1 = "C:\Extracts\MARA.rtf"

Set R3 = CreateObject("SAP.Functions")

R3.Connection.system = "xxx"

R3.Connection.SystemNumber = "xxx"

R3.Connection.client = "xxx"

R3.Connection.User = "xxx"

R3.Connection.Password = "XXX"

R3.Connection.language = "EN"

R3.Connection.applicationserver = "XXX"

If R3.Connection.logon(0, True) <> True Then

MsgBox "No connection to R3!"

var_return = " has Failed"

sendmessage (var_return)

Exit Function

End If

'*****************************************************

'Call RFC function RFC_READ_TABLE

'*****************************************************

Set MyFunc = R3.Add("RFC_READ_TABLE")

ERROR RECEIVED IS:

Run-time error '-2147352568'

Bad variant type

Thank you

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hi Sheetal,

Good evening. I am not sure if you have succeeded in extracting the data or gave up.

The key thing is on the code above:

If you have a VBscript with the code - that is standalone - then you cannot define the variables

as follows:

Dim R3Logon         As object

Dim MyFunc As object

which should be just:

Dim R3

Dim MyFunc

then when you actually want to instantiate them as objects then:

Set MyFunc = CreateObject("SAP.Functions")

Set R3Logon = CreateObject("SAP.LogonControl.1")

etc.

Check out my video - where i have extracted the SAP table headers and SAP table data

and also bypassed the limit of 512 byte, which exist in the RFC function.

https://youtu.be/BYgx3SogEjE

Let me know if you need any help?

Thanks

Ram.S

0 Kudos

Hi,

Please give me access the video it is marked private. I am also looking to get an RFC working from VBScript.

Ken

0 Kudos

I need your personal email address?

Thanks

Ram.S

my Email : ramkis2002 AT gmail.com

0 Kudos

Thanks,

Lukongodo AT gmail.com

Cheers

0 Kudos

Hi Kenneth,

Good morning.

You would have now received access to 7 or 8 videos in all.

Thanks & Let me know if you need more info. I have kept them private since i had been receiving a ton of emails to help in coding & other similar engagements and wanted to limit those.


Ram.S

0 Kudos

Thanks I definitely will,

Cheers

Ken

0 Kudos

I had managed to get the data from SAP and was stuck at converting this into excel, will definitely continue researching not that I know it is possible.

Ken

thomas_brutigam2
Active Participant
0 Kudos

Hi sheetal,

First of all: your Declarations right at the Beginning:

Example:

Dim R3, MyFunc, App, objFileSystemObject, filOutput, objmessage As Object

This only "Dims" objmessage as an object not the other ones:

better like that:

Dim R3 as Object

Dim Myfunc as Object

Dim App as Object

'and so on ...

and so on ...

But General- on which line does the Error appear ?