VB.net串連SAP執行個體

來源:互聯網
上載者:User

最近在研究vb串連SAP的例子, 終於可以正常登入SAP通過RFC讀取SAP中的資料。

下面是具體的代碼:

vb6.0寫法:

 

'定義公開變數

Public Connect As Object
Public Functions As Object

'登入SAP
Private Sub Command1_Click()

   '建立ocx對象
    Set Functions = CreateObject("Sap.Functions.unicode")

   'Sap.Functions.unicode 不加unicode的話無法正常顯示中文。這和登入時Language的設定沒有關係

   '是因為字元集的原因。

   '設定串連資訊
    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 "登入失敗"

      Command1.SetFocus
    Else 

      Command1.Enabled = False
      MsgBox "登入成功"

    End If
End Sub

'調用RFC的寫法

Private Sub Command2_Click()
  Dim GetCustomers As Object
  Dim Customers As Object
  Dim i As Integer

 '所要調用的RFC名稱
 Set GetCustomers = Functions.Add("ZCSMS_GET_HRINFO")

 '傳遞的輸入參數名稱並賦值

  GetCustomers.Exports("BEGDAFROM") = ""
  GetCustomers.Exports("BEGDATO") = ""
  GetCustomers.Exports("MILL") = "7960"
  GetCustomers.Exports("NUMBERFROM") = "0061500001"
  GetCustomers.Exports("NUMBERTO") = "0061500080"
 
  '執行後返回的Table,相當於二維數組
  Set Customers = GetCustomers.Tables("THR")

 '簡單的MsgBox彈出以查看值 

 If GetCustomers.Call Then
    For i = 1 To Customers.RowCount
      MsgBox Customers(i, "MILL")
      MsgBox Customers(i, "PERNR")
      MsgBox Customers(i, "NAME1")
      MsgBox Customers(i, "STEXT")
    Next i
  Else
    MsgBox " 函數調用失敗" + GetCustomers.exception
  End If
End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.