简体   繁体   English

将第三方应用程序 (MS Excel) 与 SAP R/3 连接

[英]Connect a third-party application (MS Excel) with SAP R/3

I'm working out a solution for communicate MS Excel (a VBA macro) with SAP.我正在制定与 SAP 通信 MS Excel(VBA 宏)的解决方案。 Sometimes is too hard to reach SAP support people at any company you are working for, so it is better to figure out your own solution.有时很难联系到您所在公司的 SAP 支持人员,因此最好找出自己的解决方案。

About that reason, I started with the basic: "connect my own User profile with SAP R/3".出于这个原因,我从基本的开始:“将我自己的用户配置文件与 SAP R/3 连接起来”。 Doing some Google research, I found a good paper with the connectivity and here is the key part of the code:做了一些谷歌研究,我找到了一篇关于连接性的好论文,这是代码的关键部分:

Dim objBAPIControl As Object 'Function Control (Collective object)
Dim sapConnection As Object 'Connection object
Set objBAPIControl = CreateObject("SAP.Functions")
Set sapConnection = objBAPIControl.Connection

sapConnection.client = "32"
sapConnection.user = "myUser"
sapConnection.Language = "EN"
sapConnection.hostname = "qwerty.example.com"
sapConnection.Password = "myPass"

(and more user profile values........) (以及更多用户个人资料值......)

Later on, I did the second step which was reading some table (in this case, the Users Table)后来,我做了第二步,读取一些表(在这种情况下,用户表)

If sapConnection.logon(1, True) <> True Then
MsgBox "No connection to R/3!"
Exit Sub 'End program
End If
Set objUserList = objBAPIControl.Add("BAPI_USER_GETLIST")
Set objUserDetail = objBAPIControl.Add("BAPI_USER_GET_DETAIL")

returnFunc = objUserList.Call
If returnFunc = True Then
Dim objTable As Object
Set objTable = objUserList.Tables("USERLIST")
ActiveSheet.Cells(1, 1) = "User count :" & objTable.RowCount

But now, here is my question: How to run some transaction (LM02, LS26, LX03, or etc) fired from VBA ?但是现在,我的问题是:如何运行从 VBA 触发的某些事务(LM02、LS26、LX03 等)?

Thank you guys!感谢大伙们!

PS.附注。 I'm using MS Office 2007 and Windows 7.我使用的是 MS Office 2007 和 Windows 7。

-- EDITED: - 编辑:

Hey I change the way I was attacking the challenge ( I will let the OP above for helping some other guy)嘿,我改变了我攻击挑战的方式(我会让上面的 OP 帮助其他人)

This must be add to the first这必须添加到第一个

Dim RfcCallTransaction As Object
Dim Messages As Object
Dim BdcTable As Object

The connection to SAP is the same, but once you're logged in:与 SAP 的连接是相同的,但一旦您登录:

If objBAPIControl.Connection.Logon(0, False) <> True Then
    Exit Sub
End If

Set RfcCallTransaction = objBAPIControl.Add("RFC_CALL_TRANSACTION_USING") 

here you can find the "new" arguments for the RFC_CALL_TRANSACTION old function. 在这里您可以找到RFC_CALL_TRANSACTION旧函数的“新”参数。

    RfcCallTransaction.exports("tcode") = "SE16"
    RfcCallTransaction.exports("mode") = "N"
Set BdcTable = RfcCallTransaction.Tables("bt_data")

Until this part I'm sure of three things:在这部分之前,我确信三件事:

1) It does connect to SAP R/3 1) 它确实连接到 SAP R/3

2) It Runs the "SE16" transaction 2)它运行“SE16”交易

3) It could receive the Batch input from a BdcTable 3) 它可以接收来自 BdcTable 的 Batch 输入

The missing part is, how to "format" the BdcTable (I think it must be in ABAP language) to upload the exact Data (table) that I want to be run at SE16.缺少的部分是,如何“格式化” BdcTable(我认为它必须是 ABAP 语言)以上传我想在 SE16 上运行的确切数据(表)。

EDITED: I found an example of the "formatting" table I'm looking for:编辑:我找到了一个我正在寻找的“格式化”表的例子:

add_bdcdata BdcTable, "SAPLSETB", "230", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "DATABROWSE-TABLENAME"
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=ANZE"
add_bdcdata BdcTable, "", "", "", "DATABROWSE-TABLENAME", "KNA1"
add_bdcdata BdcTable, "/1BCDWB/DBKNA1", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "MAX_SEL"
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=ONLI"
add_bdcdata BdcTable, "", "", "", "LIST_BRE", "250"
add_bdcdata BdcTable, "", "", "", "MAX_SEL", "5"
add_bdcdata BdcTable, "SAPMSSY0", "120", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "01/02/2012"
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=%EX"
add_bdcdata BdcTable, "/1BCDWB/DBKNA1", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "/EE"
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "I1-LOW"
add_bdcdata BdcTable, "SAPLSETB", "230", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "/EBACK"
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "DATABROWSE-TABLENAME"

The above code still being part of the VBA macro.上面的代码仍然是 VBA 宏的一部分。 But I don't know what do all those fills mean.但我不知道所有这些填充是什么意思。

After this task is complete, the second challenge is to save the data automatically into a MS Excel sheet.完成此任务后,第二个挑战是将数据自动保存到 MS Excel 工作表中。

(Could you tell me if the all editing thing is working or should I just paste the new code and erase the history?) (你能告诉我所有编辑工作是否正常,还是我应该粘贴新代码并删除历史记录?)

EDITED: I asked the same question as a summary in SCN platform.编辑:我问了与 SCN 平台中的摘要相同的问题。 You can review it here .您可以在此处查看

EDITED: My objective in this challenge is to run a transaction ( the TCODE I'm looking for is LM02, a bin to bin transaction for warehouse) via a VBA Macro, upload some date extracted from a MS Excel file and Execute the transaction.编辑:我在这个挑战中的目标是通过 VBA 宏运行交易(我正在寻找的 TCODE 是 LM02,仓库的 bin 到 bin 交易),上传从 MS Excel 文件中提取的一些日期并执行交易。

-- last edit: It seems like this task can't be done without the help of SAP IT support. -- 最后编辑:如果没有 SAP IT 支持的帮助,这项任务似乎无法完成。 19/sep/12 | 19/sep/12 | still researching about this topic.还在研究这个话题。 25/09/12 | 25/09/12 | 02/OCT/12 --> I will try AutoIT for logging, run a basic Tcode and display the report. 02/OCT/12 --> 我将尝试使用AutoIT进行日志记录,运行基本的 Tcode 并显示报告。 I'd Comment my results after I double checked it.在我仔细检查后,我会评论我的结果。

Note: This is an alternative suggestion to @fabiopagoti's answer, a completely different approach.注意:这是@fabiopagoti 答案的替代建议,这是一种完全不同的方法。

If - as you suggested in another comment - you want to import data into R/3 applications, you'd better not try to bypass the company IT.如果 - 正如您在另一条评论中所建议的 - 您想将数据导入 R/3 应用程序,您最好不要试图绕过公司 IT。 Instead, you could try to talk to them and get access to the Legacy System Migration Workbench (LSMW).相反,您可以尝试与他们交谈并访问Legacy System Migration Workbench (LSMW)。 This is a powerful toolkit that allows you to record dialog steps (under certain conditions), import some data (for example from CSV files) and then combine the recording and the data to "replay" the same steps with different data - all using standard functions and without bypassing any security checks.这是一个功能强大的工具包,它允许您记录对话步骤(在某些条件下),导入一些数据(例如从 CSV 文件),然后将记录和数据组合起来以使用不同的数据“重放”相同的步骤 - 所有这些都使用标准功能,而无需绕过任何安全检查。

Well, let me quote the best answer that I got.好吧,让我引用我得到的最佳答案。 I'm pasting it here because I think somebody else will have the same question that I did.我把它贴在这里是因为我认为其他人会和我有同样的问题。

The step one is to understand if there' sa RFC or BAPI for your transaction, but you don't have the permission for ABAP transactions, so I don't know how you can find out it.第一步是了解您的交易是否有 RFC 或 BAPI,但您没有 ABAP 交易的权限,所以我不知道您如何找到它。

Theorically you can try to looking for it in WEB or in SAP documentation, but then (if it exists) you need to check the interface where the the import/export parameters are defined.....so you should have the authorization for SE37.理论上你可以尝试在WEB或SAP文档中寻找它,但是(如果存在)你需要检查定义导入/导出参数的接口......所以你应该有SE37的授权.

The next step depends on if you can or can't find out a RFC function for LM02:下一步取决于您是否可以找到 LM02 的 RFC 函数:

if there's a function, you need to understand how to run it如果有一个函数,你需要了解如何运行它

if there isn't a function.如果没有函数。 you need to understand if you or an abaper can develop a custom one.您需要了解您或 abaper 是否可以开发定制的。

Max最大限度

Thank you for your research effort.感谢您的研究努力。

I'm sorry my friend but you won't get much further than this.对不起,我的朋友,但你不会比这更进一步。

What you are doing in your code is calling a BAPI (basically a RFC enable function).您在代码中所做的是调用 BAPI(基本上是 RFC 启用函数)。 In other words, SAP provide standard functions which call be called from different systems.换句话说,SAP 提供了从不同系统调用的标准函数。 You can think this as an old fashioned API.你可以认为这是一个老式的 API。 It's also possible to create custom BAPIs, but in practice almost nobody does this.也可以创建自定义 BAPI,但实际上几乎没有人这样做。

The good news is that usually, I said usually BAPIs brings the same functionality of standard transactions.好消息是,通常,我说通常 BAPI 会带来与标准事务相同的功能。 So in theory what you can do via transaction code you can do via BAPI call.因此,理论上您可以通过事务代码执行的操作可以通过 BAPI 调用执行。

BAPI relation with transaction codes is not one to one. BAPI 与事务代码的关系不是一对一的。 For example, you may use a single transaction which enables you inserting, searching, deleting and editing a particular kind of document but to achieve this using BAPI calls you will need many of them (one to create a document, one to delete, one to retrieve etc).例如,您可以使用单个事务来插入、搜索、删除和编辑特定类型的文档,但要使用 BAPI 调用实现这一点,您将需要许多事务(一个用于创建文档,一个用于删除,一个用于检索等)。

There's a transaction called "BAPI" (maybe the only tx code with a decent name) which contains all BAPIs in the system, its parameters and (some poor) documentation.有一个名为“BAPI”的交易(可能是唯一具有体面名称的交易代码),其中包含系统中的所有 BAPI、其参数和(一些糟糕的)文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM