VBA call sap-BAPI's function

學習筆記
=============
模組中﹕
================

Public Type bapi_msg
  mandt As Integer
  cdate As Date
  ctime As String
  suname As String
  tuname As String
  msgtxt As String
  ok As String
 End Type

Public Type bapi_msg1
 suname As String
 tuname As String
 msgtxt As String
End Type

=========================
表單中﹕
=========================

Private Sub btn_cnt_Click()'按扭事件
 
 'Dim aa As bapi_msg
 Dim bb As bapi_msg1
 
 bb.suname = "aaa"
 bb.tuname = "bb"
 bb.msgtxt = "aaa to bb "

'創建物料﹐連接(登錄)SAP系統
 Set function = CreateObject("SAP.LogonControl.1")
 Set connection = Ofunction.newconnection
 Oconnection.client = "800"
 Oconnection.Language = "ZF"
 Oconnection.user = "USERNAME"
 Oconnection.password = "PASSWORD"
 Oconnection.applicationserver = "192.168.**.**"
 Oconnection.systemnumber = "00"
 result = Oconnection.logon(0, True)
'指定所呼叫的函數(BAPI里的)
 Set fun = CreateObject("SAP.FUNCTIONS")
 Set Ofun.Connection = Oconnection
 Set func = Ofun.Add("ZBAPI_VORTEX_SAVEMSG")
'給所呼叫的函數的參數賦值。此參數為structure類型。
 func.exports("MSG1")("SUNAME") = bb.suname
 func.exports("MSG1")("TUNAME") = bb.tuname
 func.exports("MSG1")("MSGTXT") = bb.msgtxt
'提交
 If func.call = True Then
  MsgBox ("OK!")
 Else
  MsgBox ("Fail")
 End If
'釋放
Oconnection.logoff
Set connection = Nothing
Set func = Nothing
 
End Sub

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14327814/viewspace-669685/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/14327814/viewspace-669685/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值