问题描述
美好的一天!
我在实习期间需要提供的项目之一是在SAP GUI中自动执行交易(特别是在财务模块下)。是否可以使用c#自动执行事务,如果是,将c#连接到SAP GUI的步骤是什么?
谢谢!
Good Day!
One of the projects that I need to deliver in my internship is to automate a transaction in SAP GUI(specifically under the financials module). Is it possible to automate a transaction by using c#, if yes what would be the steps for connecting c# to SAP GUI?
Thanks!
推荐答案
using SAPFEWSELib;
using SapROTWr;
添加完成后,添加以下是一个按钮:
Once those are added, add the following to a button:
//Get the Windows Running Object Table
SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper();
//Get the ROT Entry for the SAP Gui to connect to the COM
object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
//Get the reference to the Scripting Engine
object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);
//Get the reference to the running SAP Application Window
GuiApplication GuiApp = (GuiApplication)engine;
//Get the reference to the first open connection
GuiConnection connection = (GuiConnection)GuiApp.Connections.ElementAt(0);
//get the first available session
GuiSession session = (GuiSession)connection.Children.ElementAt(0);
//Get the reference to the main "Frame" in which to send virtual key commands
GuiFrameWindow frame = (GuiFrameWindow)session.FindById("wnd[0]");
此示例与Visual Basic版本完全相同。
如果要在SAP中的文本字段中输入文本,必须将对象明确地转换为正确的变量类型
在CO02交易中输入订单号的示例如下:
This example works exactly like the Visual Basic Version does.
If you want to enter text into a text field within SAP, you must explicitly cast the object into the correct variable type
an example of entering an order number into CO02 Transaction, would be:
GuiTextField ordNum = (GuiTextField)session.FindById("wnd[0]/usr/ctxtCAUFVD-AUFNR");
ordNum.Text = textBox1.Text;
frame.SendVKey(0);
这篇关于如何将C#连接到SAP GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!