有一种节约SAP 用户license的办法:
设定一个帐号池,比如30个帐号放这个池里: U1,U2,U3,U4,,,U30。
用户在使用SAPGUI登录SAP服务器时,不需要用户输入账号。【桌面程序】会自动在帐号池中拿一个没有用帐号,登入SAP服务器。
【桌面程序】它怎么会知道哪个用户没用呢? 可以先连接到SAP服务器查询。
怎么把用户同SAP帐号池联系起来呢?【桌面程序】自己搞一个用户帐号记录系统,把系统外用户和SAP帐号对应的记录下来。
账号池的账号,A用户用完就可以给B用户用,如果用户交替登录SAP服务器,这种方式确实可以节省帐号。
这套做法有一个关键点,就是对SAPGUI要用程序去让它登入服务器。
方法1、用WINDOWS提供的功能: 找对SAPGUI应用程序窗口的2个控件,填入用户名,密码,再对SAPGUI窗口发一个回车。
方法2、用SAP官方的sap gui scripting api: 测试后发现登入界面不是标准的SAPGUI,看来官方的办法不理想。
开发环境是VS2010,C# ,例子代码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using SAPFEWSELib; //这里需要把dll添加到【引用】 namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); SAPActive.openSap("WPRD"); SAPActive.login("800", "liuxin", "123456", "EN"); SAPActive.SapSession.StartTransaction("SU3"); } //created a class for the SAP app, connection, and session objects as well as for common methods. public class SAPActive { public static GuiApplication SapGuiApp { get; set; } public static GuiConnection SapConnection { get; set; } public static GuiSession SapSession { get; set; } public static void openSap(string env) { SAPActive.SapGuiApp = new GuiApplication(); string connectString = null; if (env.ToUpper().Equals("DEFAULT")) { connectString = "1.0 Test ERP (DEFAULT)"; } else { connectString = env; } SAPActive.SapConnection = SAPActive.SapGuiApp.OpenConnection(connectString, Sync: true); //creates connection SAPActive.SapSession = (GuiSession)SAPActive.SapConnection.Sessions.Item(0); //creates the Gui session off the connection you made } public static void login(string myclient, string mylogin, string mypass, string mylang) { GuiTextField client = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField"); GuiTextField login = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField"); GuiTextField pass = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField"); GuiTextField language = (GuiTextField)SAPActive.SapSession.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField"); client.SetFocus(); client.Text = myclient; login.SetFocus(); login.Text = mylogin; pass.SetFocus(); pass.Text = mypass; language.SetFocus(); language.Text = mylang; //Press the green checkmark button which is about the same as the enter key GuiButton btn = (GuiButton)SapSession.FindById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/btn[0]"); btn.SetFocus(); btn.Press(); } } } }