cancel
Showing results for 
Search instead for 
Did you mean: 

VBA

Former Member
0 Kudos

First let me apologize for my lack of knowledge .. you SAP folks gota have IQ's off the chart ..

in any case .. our firm is migrating to SAP .. I've been asked to investigate the creation of tools to input data that are familiar to the majority of our users eg. Excel.

I've attempted to create a macro that creates and populates a table without success. see code below .. my issue currently is that though I see the table initiated in my IDE, I can't seem to pass actual data, and I don't see the table created in the SAP environment. Though I would surely appreciate any fixes to the code offered, what I would truely appreciate is a resource to better educate me about SAP, RFC's ... ie a SAP for dummies ....

Private Declare Sub CoFreeUnusedLibraries Lib "OLE32.DLL" () ' Cleaning up memory.

Const SapSystem = "NSP"

Const SapSystemNumber = "00"

Const SapApplicationServer = "questserver"

Const SapClientNumber = "00"

Const SapUserName = "BCUSER"

Const SapUserPassword = "minisap"

Const SapLanguage = "EN"

Public sapConn As Object

Public SapFuncCall As Object

Public TableFactoryCtrl As Object

Public OurTable As Object

Public RetVal As Boolean

Public myData() As Variant

Sub Main()

SapLogon

If RetVal = False Then GoTo Bye

SapBuildObjs

SapCreateTable

SapLogOff

Bye: CleanUp

End Sub

Sub SapLogon()

Set sapConn = CreateObject("SAP.Functions")

sapConn.Connection.System = SapSystem

sapConn.Connection.SystemNumber = SapSystemNumber

sapConn.Connection.ApplicationServer = SapApplicationServer

sapConn.Connection.client = SapClientNumber

sapConn.Connection.user = SapUserName

sapConn.Connection.Password = SapUserPassword

sapConn.Connection.Language = SapLanguage

sapConn.logfilename = "LTSlog.txt"

sapConn.loglevel = 0

RetVal = sapConn.Connection.Logon(0, True)

If RetVal <> True Then

MsgBox ("Logon Failed, program will now exit")

Exit Sub

Else

MsgBox ("Logged on to " & SapApplicationServer & "/" & SapSystem & " as " & SapUserName)

End If

End Sub

Sub SapBuildObjs()

Set SapFuncCall = CreateObject("SAP.Functions")

Set TableFactoryCtrl = CreateObject("SAP.TableFactory.1")

SapFuncCall.Connection = sapConn.Connection

End Sub

Sub SapCreateTable()

Set LTSTable = TableFactoryCtrl.NewTable

Call LTSTable.Create("LTSTests", 100)

Set myRange = ActiveSheet.UsedRange

myRows = myRange.Rows.Count

myColumn = myRange.Columns.Count

For x = 1 To myColumn

LTSTable.Columns.Add

LTSTable.Columns.Item(x).Name = myRange.Cells(1, x)

Next x

ReDim myData(myColumn)

For y = 2 To myRows

Set Row = LTSTable.Rows.Add

For z = 1 To myColumn

myData(z) = myRange.Cells(y, z)

Next z

Row.Data = myData

Next y

LTSTable.Refresh

End Sub

Sub SapLogOff()

sapConn.Connection.Logoff

End Sub

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi David,

Read these. Very helpful articles-

/people/kathirvel.balakrishnan2/blog/2006/05/08/data-upload-into-sap-from-microsoft-excel-150-abap-part

/people/kathirvel.balakrishnan2/blog/2006/05/09/data-upload-into-sap-from-microsoft-excel-150-vba-part

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndcom/html/sapintegration.asp

Regards.

Former Member
0 Kudos

THANKS Jitesh

Not seen that blog as of yet ..

So if I understand this method correctly .. I must first write a RFC to call .. and

this RFC creates the table structure. Is this the only method ? I had hoped to create a utility a bit more dynamic at the client end as Excel column count/headings and created table name etc will be different for users dependant upon their content. Hate to have to write a unique RFC for each.

If I were to follow this course ..

How do I migrate the RFC from my developmental platform to the actual SAP system ? I'm on a network isolated from the SAP box.

THANKS Again

Former Member
0 Kudos

Hi David,

If I understood the requirement correctly then you do not need to create RFCs for each user.

You need to develope only one RFC. You pass the information of the table structure etc through the parameters to the RFC. And write the logic to create table is inside the RFC.

Regarding your second question- You either would have to use transport system provided by SAP (in this case the source and target system has to be part of same system landscape) or you can do the system copy.

If some system admin is watching this thread, please validate second part of my answer (above)

Regards.

Former Member
0 Kudos

THANKS Again Jitesh ..

As I read the blog you referenced .. I was thinking along this course ..

with regard to getting the RFC onto the SAP system .. I suppose I could provide the code to the SAP admin as a txt file and they could impliment it ..

well it's off to learning ADAP ..

Answers (0)