Recently, I am studying the example of connecting to sap using VB, so that I can log on to sap normally and read the data in SAP through RFC.
Below are specificCode:
VB6.0:
'Define public variables
Public connect as object
Public Functions as object
'Log On to sap
Private sub commandementclick ()
'Create OCX object
Set functions = Createobject ("sap. functions. Unicode ")
'Sap. functions. Unicode cannot display Chinese normally without Unicode. This is irrelevant to the language setting during logon.
'Is because of the character set.
'Set connection information
Set connect = functions. Connection
Connect. applicationserver = "172.18.95.173"
Connect. Client = "169"
Connect. Language = "ZH"
Connect. User = "crmdev69"
Connect. Password = "654321"
Connect. systemnumber = 7
Connect. System = "CD2"
If not connect. Logon (0, true) then
Msgbox "Logon Failed"
Command1.setfocus
Else
Command1.enabled = false
Msgbox "Logon successful"
End if
End sub
'The METHOD FOR CALLING RFC
Private sub command2_click ()
Dim getcustomers as object
Dim MERs as object
Dim I as integer
'The RFC name to be called
Set getcustomers = functions. Add ("zcsms_get_hrinfo ")
'Input parameter name passed and value assigned
Getcustomers. Exports ("begdafrom") = ""
Getcustomers. Exports ("begdato") = ""
Getcustomers. Exports ("Mill") = "7960"
Getcustomers. Exports ("numberfrom") = "0061500001"
Getcustomers. Exports ("numberto") = "0061500080"
'Table returned after execution, equivalent to a two-dimensional array
Set MERs = getcustomers. Tables ("thr ")
'Simple msgbox pop-up to view the value
If getcustomers. Call then
For I = 1 to mers MERs. rowcount
Msgbox MERs (I, "Mill ")
Msgbox MERs (I, "pernr ")
Msgbox MERs (I, "name1 ")
Msgbox MERs (I, "stext ")
Next I
Else
Msgbox "function call failed" + getcustomers. Exception
End if
End sub