VB调用sap连接的程序

:Option Explicit

Dim functionCtrl As Object
Dim sapConnection As Object
Dim theFunc As Object
Dim objStruct

Private Sub Command1_Click()
If ConnectToSAP = False Then
MsgBox "Connect Error"
Exit Sub
End If

'Set theFunc = functionCtrl.Add("RFC_READ_TABLE")
Set theFunc = functionCtrl.Add("BAPI_PO_GETDETAIL")


If theFunc Is Nothing Then
MsgBox "Creating function module object failed"
Exit Sub
End If

theFunc.Exports("PURCHASEORDER") = "4500014788"

If theFunc.Call = False Then
MsgBox "Function call failed"
Exit Sub
End If

Set objStruct = theFunc.tables("PO_ITEMS")
objStruct.Value(2, "MATERIAL") = "MYITEMNUMBER"

Dim i As Integer
For i = 1 To objStruct.RowCount()
MsgBox objStruct.Value(i, "MATERIAL")
Next i

End Sub

Private Function ConnectToSAP() As Boolean
Set functionCtrl = CreateObject("SAP.Functions")
Set sapConnection = functionCtrl.Connection

sapConnection.client = "800"
sapConnection.user = "USERNAME"
sapConnection.Password = "PASSWORD"
sapConnection.language = "EN"

If sapConnection.Logon(0, False) = False Then
ConnectToSAP = False
Else
ConnectToSAP = True
End If
End Function


例2:

Option Explicit
Dim functionCtrl As Object
Dim sapConnection As Object
Dim theFunc As Object
Dim PoNumber

Private Sub Command1_Click()

Set functionCtrl = CreateObject("SAP.Functions")
Set sapConnection = functionCtrl.Connection
sapConnection.Client = "500"
sapConnection.user = "USERNAME"
sapConnection.password = "PASSWORD"
sapConnection.Language = "EN"

If sapConnection.logon(0, False) True Then
MsgBox "No connection to R/3 System"
Exit Sub 'End program
End If
Set theFunc = functionCtrl.Add("BAPI_PO_CREATE")


Dim poheader As Object
Dim poitems As Object
Dim poitemschedule As Object
Dim retMess As Object
Dim returnFunc As Boolean
Dim startzeil As Integer
Dim endcol As Integer
Dim the_name As String

Set poheader = theFunc.exports.Item("PO_HEADER")
Set poitems = theFunc.tables.Item("PO_ITEMS")
Set poitemschedule = theFunc.tables.Item("PO_ITEM_SCHEDULES")

poheader.Value("VENDOR") = Text1.Text

poheader.Value("PURCH_ORG") = Text2.Text
poheader.Value("PUR_GROUP") = Text3.Text
poheader.Value("DOC_TYPE") = Text4.Text

poitems.Rows.Add
poitems.Value(1, "PUR_MAT") = Text5.Text
poitems.Value(1, "PLANT") = Text6.Text
poitems.Value(1, "NET_PRICE") = Text7.Text


poitemschedule.Rows.Add
poitemschedule.Value(1, "DELIV_DATE") = Text8.Text
poitemschedule.Value(1, "QUANTITY") = Text9.Text

returnFunc = theFunc.call
PoNumber = theFunc.imports("PURCHASEORDER")
Set retMess = theFunc.tables.Item("RETURN")
If retMess Is Nothing Then

MsgBox retMess.Value(1, "MESSAGE")
Else
MsgBox "Purchase Order No : " & PoNumber & "Created"
End If

End Sub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值