‎2008 Jan 19 6:33 AM
Hi Experts
I am new to the SAP-VB connect using BAPI, Can anyone send me simple example of connecting SAP and VB using BAPI. I have tried many times but facing error, pls provide me with clear steps. pls dont forward any links.
It would be appreciatable.
Thanks in advance.
Regards
Rajaram
‎2008 Jan 19 6:36 AM
‎2008 Jan 19 6:40 AM
‎2008 Jan 19 6:42 AM
Form VB.NET appliaction you have two ways to connect to SAP system and execute BAPI. Either through webservices or by using NCo. Choice depends upon you appliaction requirement.
For starting with NCo go through
http://help.sap.com/saphelp_nw04s/helpdata/en/a9/4a57c1bac80e4e977d8cd9b3ecab89/frameset.htm
OR
THIS IS ANOTHER WAY TO LOGIN TO SAP THROUGH VB TRY THIS.
Logon with the SAPLogon control, Use an RFC call from the SAP Function
Control, and get the results with the SAP Table Factory Control. . .
You must have SAPGui's FULL install on your machine for this to work (Or at
least SAPLogon and the RFC toolkit)
This VBScript example might help, it calls RFC_READ_TABLE in sap, and emails
the results back to a user from a selected query (In this case uses that are
locked out.
This should show you how this could work in practice.
Thanks,
Will
' Email Locked out SAP users details to user in a .csv file through MS
Exchange / CDO
Dim ctlTableFactory, RFC_READ_TABLE, eQUERY_TAB, tblOptions, tblData,
tblFields, funcControl, objConnection, ctlLogon
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set ctlLogon = CreateObject("SAP.LogonControl.1")
Set funcControl = CreateObject("SAP.Functions")
Set ctlTableFactory = CreateObject("SAP.TableFactory.1")
Set objWindowsScriptShell = CreateObject("WScript.Shell")
Set objConnection = ctlLogon.NewConnection
Set filOutputobjFileSystemObject.CreateTextFile("E:\SAP Scripts\LockedUsers.CSV", True)
objConnection.ApplicationServerobjWindowsScriptShel l.RegRead("HKLM\Software\AccantiaEDI\SAPServer")
objConnection.SystemobjWindowsScriptShell.RegRead(" HKLM\Software\AccantiaEDI\SID")
objConnection.SystemNumber = "00"
objConnection.ClientobjWindowsScriptShell.RegRead(" HKLM\Software\AccantiaEDI\SAPClient")
objConnection.Language = "EN"
objConnection.UserobjWindowsScriptShell.RegRead("HK LM\Software\AccantiaEDI\SAPSAPUser")
objConnection.PasswordobjWindowsScriptShell.RegRead ("HKLM\Software\AccantiaEDI\SAPSAPPassword")
booReturn = objConnection.Logon(0, True)
If booReturn True Then
'MsgBox " Cannot log on! "
'MsgBox booReturn
filOutput.WriteLine "ERROR CALLING LOGGING INTO SAP - FAILED LOGINS
UNKNOWN"
Stop
Else
'MsgBox " Logon OK."
funcControl.Connection = objConnection
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 = "USR02"
strExport2.Value = ","
tblOptions.AppendRow
tblOptions(1, "TEXT") = "LOCNT > 0 OR UFLAG = 128"
tblFields.AppendRow
tblFields(1, "FIELDNAME") = "BNAME"
tblFields.AppendRow
tblFields(2, "FIELDNAME") = "LOCNT"
tblFields.AppendRow
tblFields(3, "FIELDNAME") = "UFLAG"
If RFC_READ_TABLE.Call = True Then
If tblData.RowCount > 0 Then
filOutput.WriteLine "UserName,FailedLogins,LockedFlag"
' MsgBox tblData.RowCount
For intRow = 1 To tblData.RowCount
filOutput.WriteLine tblData(intRow, "WA")
Next
Else
filOutput.WriteLine "NO FAILED LOGINS OR LOCKED USERS"
End If
Else
filOutput.WriteLine "ERROR CALLING SAP REMOTE FUNCTION CALL -
FAILED LOGINS UNKNOWN"
End If
End If
Set filOutput = Nothing
MailProfile = "MS Exchange Settings"
Set objSession = CreateObject("MAPI.Session")
LogonOK = objSession.Logon(MailProfile)
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "SAP Users Report - Locked Users + Failed Logins"
strSetMessage = "There are " & tblData.RowCount & " users that are
either locked due to failed logins, or have at least 1 failed login attempt
on system " & objWindowsScriptShell.RegRead("HKLM\Software\Accant iaEDI\SID")
& vbcrlf &
reward if useful
‎2008 Jan 19 7:05 AM
i have tried ur idea, but its not working,
do i need to define the SalesOrder object in SAP system.
because its giving the error as
An Internal RFC Error occured.
do i need to configure RFC or what else, pls suggest me.
Regards
Rajaram