Connecting to an SAP instance using VB.net

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.