-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpython_sapscript
More file actions
61 lines (49 loc) · 2.05 KB
/
python_sapscript
File metadata and controls
61 lines (49 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# original post https://blogs.sap.com/2017/09/19/how-to-use-sap-gui-scripting-inside-python-programming-language/#comment-398057
# changed session = connection.Children(0) index 0 instead of 1, tcode changed from se16 to se16n, field name changed accordingly
#-Begin-----------------------------------------------------------------
#-Includes--------------------------------------------------------------
import sys, win32com.client
#-Sub Main--------------------------------------------------------------
def Main():
try:
SapGuiAuto = win32com.client.GetObject("SAPGUI")
if not type(SapGuiAuto) == win32com.client.CDispatch:
return
application = SapGuiAuto.GetScriptingEngine
if not type(application) == win32com.client.CDispatch:
SapGuiAuto = None
return
connection = application.Children(0)
if not type(connection) == win32com.client.CDispatch:
application = None
SapGuiAuto = None
return
session = connection.Children(0)
if not type(session) == win32com.client.CDispatch:
connection = None
application = None
SapGuiAuto = None
return
#session.findById("wnd[0]").resizeWorkingPane 173, 36, 0
session.findById("wnd[0]").resizeWorkingPane(173, 36, 0)
#session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16"
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16n"
#session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey(0)
#session.findById("wnd[0]/usr/ctxtGD-TAB").text = "TADIR"
session.findById("wnd[0]/usr/ctxtGD-TAB").text = "TADIR"
#session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey(0)
#session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press()
except:
print(sys.exc_info()[0])
finally:
session = None
connection = None
application = None
SapGuiAuto = None
#-Main------------------------------------------------------------------
if __name__ == "__main__":
Main()
#-End-------------------------------------------------------------------