//-Begin----------------------------------------------------------------
//-
//- How to use SAP GUI Scripting inside Java
//- Example: Get version of SAP GUI Scripting
//-
//- Author: Stefan Schnell
//-
//----------------------------------------------------------------------
//-Import-------------------------------------------------------------
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import javax.swing.*;
public class SAPGUIScriptingVersion {
public static void main(String[] args) {
//-Variables------------------------------------------------------
ActiveXComponent SAPROTWr, GUIApp;
Dispatch ROTEntry;
String MajorVersion, MinorVersion;
Variant ScriptEngine;
ComThread.InitSTA();
//-Set SapGuiAuto = GetObject("SAPGUI")---------------------------
SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
try {
ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
//-Set application = SapGuiAuto.GetScriptingEngine------------
ScriptEngine = Dispatch.call(ROTEntry, "GetScriptingEngine");
GUIApp = new ActiveXComponent(ScriptEngine.toDispatch());
//-Get version of SAP GUI Scripting---------------------------
//-MajorVersion = application.MajorVersion()----------------
MajorVersion = GUIApp.getProperty("MajorVersion").toString();
//-MinorVersion = application.MinorVersion()----------------
MinorVersion = GUIApp.getProperty("MinorVersion").toString();
//-MsgBox "SAP GUI Scripting " & MajorVersion & "." & _
// MinorVersion-------------------------------------------
JOptionPane.showMessageDialog(null, "SAP GUI Scripting " +
MajorVersion + "." + MinorVersion);
}
catch (Exception e) {
}
finally {
ComThread.Release();
System.exit(0);
}
}
}
//-End------------------------------------------------------------------
//-Begin----------------------------------------------------------------
//-
//- How to use SAP GUI Scripting inside Java
//- Example: Logon to an SAP system
//-
//- Author: Stefan Schnell
//-
//----------------------------------------------------------------------
//-Import-------------------------------------------------------------
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class SAPGUIScriptingLogon {
public static void main(String[] args) {
//-Variables------------------------------------------------------
ActiveXComponent SAPROTWr, GUIApp, Connection, Session, Obj;
Dispatch ROTEntry;
Variant ScriptEngine;
ComThread.InitSTA();
//-Set SapGuiAuto = GetObject("SAPGUI")---------------------------
SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
try {
ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
//-Set application = SapGuiAuto.GetScriptingEngine------------
ScriptEngine = Dispatch.call(ROTEntry, "GetScriptingEngine");
GUIApp = new ActiveXComponent(ScriptEngine.toDispatch());
//-Set connection = application.Children(0)-------------------
Connection = new ActiveXComponent(
GUIApp.invoke("Children", 0).toDispatch());
//-Set session = connection.Children(0)-----------------------
Session = new ActiveXComponent(
Connection.invoke("Children", 0).toDispatch());
//-Set GUITextField Client------------------------------------
//-
//- session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "000"
//-
//------------------------------------------------------------
Obj = new ActiveXComponent(Session.invoke("FindById",
"wnd[0]/usr/txtRSYST-MANDT").toDispatch());
Obj.setProperty("Text", "000");
//-Set GUITextField User--------------------------------------
//-
//- session.findById("wnd[0]/usr/txtRSYST-BNAME").text = _
//- "BCUSER"
//-
//------------------------------------------------------------
Obj = new ActiveXComponent(Session.invoke("FindById",
"wnd[0]/usr/txtRSYST-BNAME").toDispatch());
Obj.setProperty("Text", "BCUSER");
//-Set GUIPasswordField Password------------------------------
//-
//- session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = _
//- "minisap"
//-
//------------------------------------------------------------
Obj = new ActiveXComponent(Session.invoke("FindById",
"wnd[0]/usr/pwdRSYST-BCODE").toDispatch());
Obj.setProperty("Text", "minisap");
//-Set GUITextField Language----------------------------------
//-
//- session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "DE"
//-
//------------------------------------------------------------
Obj = new ActiveXComponent(Session.invoke("FindById",
"wnd[0]/usr/txtRSYST-LANGU").toDispatch());
Obj.setProperty("Text", "DE");
//-Press enter------------------------------------------------
//-
//- session.findById("wnd[0]").sendVKey 0
//-
//------------------------------------------------------------
Obj = new ActiveXComponent(Session.invoke("FindById",
"wnd[0]").toDispatch());
Obj.invoke("sendVKey", 0);
}
catch (Exception e) {
}
finally {
ComThread.Release();
System.exit(0);
}
}
}
//-End------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
12 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |