Hi All,
Can anyone please brief me about that how is integration between Visual Basic and SAP is done.I need to read data from SAP tables and also write some data back to the SAP tables...
Can anyone give me some solution...
Thanks
Javed
Printable View
Hi All,
Can anyone please brief me about that how is integration between Visual Basic and SAP is done.I need to read data from SAP tables and also write some data back to the SAP tables...
Can anyone give me some solution...
Thanks
Javed
hi,
I only know about some of the older technologies for this... (i'm aware that new processes/function exist within sap these days)
you could look at sap business connector but I think that this is being replaced by a new technology soon and requires an install on sap.
you could also look at the dcom connector (found usually on the gui cd!) - i believe that the .net version is quite good although I have only used the older version.
or similar to the dcom connector you could use the sap gui functions if U need something quick & dirty.
eg- heres an old piece of code - copy into a .vbs and dclick (having got up the logon information within the script)
what this is doing is calling a sap function (BAPI_COSTCENTER_GETLIST) via the gui function and returning data into a string
eg
VB Code:
' ' some more stuff ' Option Explicit Const ForReading = 1, ForWriting = 2 '--main r3 object Dim ObjR3 '--parameter to abap object Dim ObjPrm1 Dim ObjPrm2 Dim ObjPrm3 Dim ObjPrm4 Dim ObjPrm5 Dim ObjPrm6 Dim ObjPrm7 Dim ObjPrm8 Dim ObjPrm9 Dim ObjPrm10 Dim ObjPrm11 Dim ObjPrm12 '--parameter from abap (return) object Dim ObjParmin '--abap function to use object Dim ObjR3Func '--return code for abap call Dim result '--abap table returned object Dim Objudextab Dim Strout, intidx logon_to_sap read_data strout = "" Do intidx = intidx + 1 on error resume next if ObjUdextab(intidx, 1) = "" then exit do end if '-----gav whatever U want goes ere strout = strout & ObjUdextab(intidx, 1) & _ " - " & _ ObjUdextab(intidx, 2) & _ " - " & _ ObjUdextab(intidx, 3) & _ vbcrlf Loop on error goto 0 set Objudextab = nothing Wscript.Echo strout sub read_data '--address the set abap function Set ObjR3Func = ObjR3.Add("BAPI_COSTCENTER_GETLIST") '--and the paramters we will send Set ObjPrm1 = ObjR3Func.exports("CONTROLLINGAREA") Set ObjPrm2 = ObjR3Func.exports("CONTROLLINGAREA_TO") Set ObjPrm3 = ObjR3Func.exports("COMPANYCODE") Set ObjPrm4 = ObjR3Func.exports("COMPANYCODE_TO") Set ObjPrm5 = ObjR3Func.exports("COSTCENTER") Set ObjPrm6 = ObjR3Func.exports("COSTCENTER_TO") Set ObjPrm7 = ObjR3Func.exports("PERSON_IN_CHARGE") Set ObjPrm8 = ObjR3Func.exports("PERSON_IN_CHARGE_TO") Set ObjPrm9 = ObjR3Func.exports("DATE") Set ObjPrm10 = ObjR3Func.exports("DATE_TO") Set ObjPrm11 = ObjR3Func.exports("COSTCENTERGROUP") '--and values ObjPrm1.Value = "GB01" '--do it result = ObjR3Func.call '--if ok then process - else exit If result = False Then '-----if it was stuffed the exit Wscript.Echo "Error reading sap - " & ObjR3.connection.User & " - " & ObjR3.connection.System ObjR3.connection.LOGOFF WScript.Quit else Set ObjUdextab = ObjR3Func.Tables("COSTCENTER_LIST") End If '--drop objects Set ObjR3Func = Nothing Set ObjPrm1 = Nothing Set ObjPrm2 = Nothing Set ObjPrm3 = Nothing Set ObjPrm4 = Nothing Set ObjPrm5 = Nothing Set ObjPrm6 = Nothing Set ObjPrm7 = Nothing Set ObjPrm8 = Nothing Set ObjPrm9 = Nothing Set ObjPrm10 = Nothing Set ObjPrm11 = Nothing end sub sub logon_to_sap Set ObjR3 = CreateObject("SAP.Functions") '--get this info from your logon pad.. ObjR3.connection.System = "Kxx" ObjR3.connection.Client = "172" ObjR3.connection.User = "myid" ObjR3.connection.Password = "mypassword*" ObjR3.connection.Language = "EN" ObjR3.connection.ApplicationServer = "appservernamehere" ObjR3.connection.SystemNumber = "61" '--if no logon then exit If ObjR3.connection.logon(0, True) <> True Then Wscript.Echo "Sap connection error - " & ObjR3.connection.User & " - " & ObjR3.connection.System WScript.Quit End If end sub
pre-req = need a machibne with the sap gui working...
the code called is a sap written bapi - just returns costcenter given a company code but I could have picked any function to demo..
what you could do is write functions that take input and read sap tables and other functions similar & update - I write standard functions via sap tran se37 and just set the "rfc"-able checkbox - at this point the function should be callable to both the dcom & gui functions.
rather than the gui fuction calling above the dcom connecter is really a better solution - when the dcom dll author tool it connects to sap and when u select a bapi function the app will author a dll for U.
this dll is just like any other activexdll with the function becoming methods for the dll and the parameters the properties to and from...
the actual dll is a "proxy stub" and just takes the information and sends this over to the sap function..
I can give u a proper dcom example but its a little indepth lte me know if U want..
have a play around.. - I have a little vb app that lets me view any table and file all from withing vb but the data is in sap - work well and all is done via the gui functions..
cheers AJP
Hi,
Thanks for the Quick Reply...
Can you please suggest me any way in which we can pass an entire ADODB Recordset to SAP without Looping through row by row.
I came to know that there is a option called "TABLES" like IMPORTS AND EXPORTS options...can you please tell us how can we use this TABLES.
Is there some way in which we can attach the ADODB Recorset directly with the TABLES option.
Thanks
Javed
hi,
im not sure it works like that :) I am doing all the work with 1 call and then the loop is later extracting data from the record sets.
the tables/imports/exports methods statements all directly relate to the similarly named tabs inside sap tran se37.
the fields that are sent to the function are the "exports"
eg
Set ObjPrm1 = ObjR3Func.exports("parametername")
ObjPrm1.value = "parametervalue"
this for a normal field - the imports (data returned to us) are similar - so you can send data back and forth as usual.
when a field is not just a straight standard field or structure but something like a set of data, this is where tables are used. Tables are usually used when sending back a variable set of records (i.e. say we want to send a company code to sap and get all the vendor names back (all in 1 call) - the multiple names would all be returned at one within a record set).
(tables are not like imports or exports - the are both in & out..)
so to recap
- set the sap objects
- set up the input values (exports here in sap terms)
- call sap (i.e the "result = ObjR3Func.call" statement)
at this point ALL data is returned.
then loop thru the record sets to extract the data - or do whatever U want with the record set...) looping thru the tables isnt doing a communication to sap here..
does that make sense,
cheers, AJP