无法从VBA调用SAP BAPI函数 [英] Unable to call SAP BAPI function from VBA

查看:613
本文介绍了无法从VBA调用SAP BAPI函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Excel宏VBA中调用SAP函数。我可以做连接,但每当代码到达调用函数的行时,我会收到错误消息
运行时错误'61704':
内部应用程序错误。



我的代码如下:

  Dim functionCtrl As Object 
Dim sapConnection As Object
Dim theFunc As Object
Dim PoNumber

设置functionCtrl = CreateObject(SAP.Functions)
设置sapConnection = functionCtrl.Connection
sapConnection。 System =
sapConnection.Client =
sapConnection.user =
sapConnection.Password =
sapConnection.Language =

如果sapConnection.logon(0,False)<> True然后
MsgBox不连接到R / 3系统
退出子'结束程序
结束如果
设置Func = functionCtrl.Add(BAPI_REQUISITION_CREATE)

刚刚执行最后一行时出错我已经在参考文献中添加了librfc32.dll s,我可以执行GUI脚本(从SAP记录)。



是否与权限或某事有关?



谢谢

解决方案

我不会完全回答你的问题,但我希望提供有用的信息。
我目前正在从QuickBooks到SAP迁移会计数据。
我使用Ruby和Ruby on Rails进行脚本和Web界面。



由于您对脚本感到舒服,我建议您尝试以下操作:





安装Ruby和库非常简单。



您可能需要创建配置文件:

 #c:\tmp\sapdev.yml 
#将参数调整到您的
ashost:your.sap.server.ip
sysnr:00
客户端:100
用户:yoursaplogin
passwd:yoursappwd
lang:EN
trace:1

然后尝试这样:

 code>#c:\tmp\sap-test.rb 
require'rubygems'
require'sapnwrfc'

SAPNW :: Base.config_location = c:\\tmp\\\sapdev.yml
SAPNW :: Base.load_config
conn = SAPNW :: Base.rfc_connect
attrib = conn.connection_attributes
#在这里你会发现你是否可以以编程方式连接到SAP
puts\\\
>>>连接属性:#{attrib.inspect} \\\


#发现BAPI函数
call = conn.discover(BAPI_ACC_DOCUMENT_CHECK)。new_function_call

#设置参数,在这种情况下,DOCUMENTHEADER,ACCOUNTGL和CURRENCYAMOUNT
call.DOCUMENTHEADER = {
HEADER_TXT=>EXCEL POST,
COMP_CODE=>2080 ,
DOC_DATE=>20090123,
PSTNG_DATE=>20090123,
USERNAME=>YOURSAPLOGIN,
BUS_ACT =FRBU,
DOC_TYPE=>SA#CUSTOMER INVOICE
}
puts\\\
>>>> DOCUMENTHEADER:
p call.DOCUMENTHEADER

call.ACCOUNTGL = [
{ITEMNO_ACC=>0000000001,GL_ACCOUNT=>0000500000},
{ITEMNO_ACC=>0000000002,GL_ACCOUNT=>0000799900,ORDERID=>CS_USD4110}
]
将\\\
> ;> ACCOUNTGL:
p call.ACCOUNTGL

call.CURRENCYAMOUNT = [
{ITEMNO_ACC=>0000000001,CURR_TYPE=>00,CURRENCY =USD,AMT_DOCCUR=>-0.70},
{ITEMNO_ACC=>0000000002,CURR_TYPE=>00,CURRENCY=& ;USD,AMT_DOCCUR=>0.70}
]
放置\\\
>>> CURRENCYAMOUNT:
p call.CURRENCYAMOUNT

call.invoke
puts\\\
>>> call.RETURN:
message = []
call.RETURN.each do | r |
message< r [MESSAGE]。strip
end
message.uniq!
puts message.join(\\\

您可能会收到有关GL帐户的错误等等,但这只是我的工作示例
这里重要的是获取RFC连接建立
然后您可以继续准备 BAPI_REQUISITION_CREATE 调用,填写 call.REQUISITION_ITEMS ,调用它并检查 call.RETURN 。 p>

您也可以找到方便的Ruby和Ruby on Rails可以从Excel读取数据并与不同的数据库集成
这对我来说是有用的。



干杯,



Alexei


I'm trying to call SAP functions from an Excel macro, VBA. I can do the connection, but whenever the code reaches the line that calls a function, I get the error message "Run-time error '61704': Internal application error.

My code is the following:

Dim functionCtrl As Object
Dim sapConnection As Object
Dim theFunc As Object
Dim PoNumber

Set functionCtrl = CreateObject("SAP.Functions")
Set sapConnection = functionCtrl.Connection
sapConnection.System = ""
sapConnection.Client = ""
sapConnection.user = ""
sapConnection.Password = ""
sapConnection.Language = ""

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_REQUISITION_CREATE")

The error comes just when the last line is executed. I've added librfc32.dll in the references, I'm able to execute GUI scripts (recorded from SAP).

Does it have something to do with permissions or something?

Thanks

解决方案

I would not answer exactly your question but I hope to provide useful info anyway. I currently work on migration of accounting data from QuickBooks to SAP. I used Ruby and Ruby on Rails for scripting and web interface.

Since you are comfortable with scripting let me recommend to try the following:

Installing Ruby and libraries is really simple.

You may need to create config file:

# c:\tmp\sapdev.yml
# adjust parameters to yours
ashost: your.sap.server.ip
sysnr: "00"
client: "100"
user: yoursaplogin
passwd: yoursappwd
lang: EN
trace: "1"    

Then try something like this:

# c:\tmp\sap-test.rb
require 'rubygems'
require 'sapnwrfc'

SAPNW::Base.config_location = "c:\\tmp\\sapdev.yml"
SAPNW::Base.load_config
conn = SAPNW::Base.rfc_connect
attrib = conn.connection_attributes
# here you will find if you can connect to SAP programmatically
puts "\n>>> Connection Attributes: #{attrib.inspect}\n"

# discover the BAPI function
call = conn.discover("BAPI_ACC_DOCUMENT_CHECK").new_function_call

# set up parameters. in this case DOCUMENTHEADER, ACCOUNTGL and CURRENCYAMOUNT
call.DOCUMENTHEADER = { 
  "HEADER_TXT" => "EXCEL POST", 
  "COMP_CODE" => "2080", 
  "DOC_DATE" => "20090123", 
  "PSTNG_DATE" => "20090123", 
  "USERNAME" => "YOURSAPLOGIN", 
  "BUS_ACT" => "RFBU", 
  "DOC_TYPE" => "SA" # CUSTOMER INVOICE 
}
puts "\n>>> DOCUMENTHEADER:"
p call.DOCUMENTHEADER

call.ACCOUNTGL = [
  {"ITEMNO_ACC" => "0000000001", "GL_ACCOUNT" =>"0000500000" },
  {"ITEMNO_ACC" => "0000000002", "GL_ACCOUNT" =>"0000799900", "ORDERID" => "CS_USD4110" }
]
puts "\n>>> ACCOUNTGL:"
p call.ACCOUNTGL

call.CURRENCYAMOUNT = [
   {"ITEMNO_ACC" => "0000000001", "CURR_TYPE" => "00", "CURRENCY" => "USD", "AMT_DOCCUR" => "-0.70" }, 
   {"ITEMNO_ACC" => "0000000002", "CURR_TYPE" => "00", "CURRENCY" => "USD", "AMT_DOCCUR" => "0.70" }
]
puts "\n>>> CURRENCYAMOUNT:"
p call.CURRENCYAMOUNT

call.invoke
puts "\n>>> call.RETURN:" 
message = []
call.RETURN.each do |r|
    message << r["MESSAGE"].strip
end
message.uniq!
puts message.join("\n")

You may receive errors regarding GL accounts etc. but this is just my working example. What's important here is to get RFC connection established. Then you can move on to prepare BAPI_REQUISITION_CREATE call, fill in call.REQUISITION_ITEMS, invoke it and check call.RETURN.

You may also find convenient that Ruby and Ruby on Rails can read data from Excel and integrate with different databases. This is working for me.

Cheers,

Alexei

这篇关于无法从VBA调用SAP BAPI函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆