[英]How can i run SAP with Python scripting?
Currently im working on how can i start SAP Scripting with python with the help of stackoverflow but apparently my sap does not open the connection page the Page where i enter USERNAME and PASSWORD .目前我正在研究如何在 stackoverflow 的帮助下使用 python 启动 SAP 脚本,但显然我的 sap 没有打开连接页面,即我输入 USERNAME 和 PASSWORD 的页面。 I believe
DCG210
is my connectioname, Below is a picture to show where i land after i run the python code.我相信
DCG210
是我的连接名称,下面是一张图片,显示我运行 python 代码后的位置。 Also, i would appreciate if anyone have any links to learning SAP Scripting with Python.另外,如果有人有任何使用 Python 学习 SAP 脚本的链接,我将不胜感激。 Thank you!
谢谢!
import win32com.client
import sys
import subprocess
import time
# This function will Login to SAP from the SAP Logon window
def saplogin():
try:
path = r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"
subprocess.Popen(path)
time.sleep(10)
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.OpenConnection("DCG210", True)
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]/usr/txtRSYST-BNAME").text = "USERNAME"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD"
session.findById("wnd[0]").sendVKey(0)
except:
print(sys.exc_info()[0])
finally:
session = None
connection = None
application = None
SapGuiAuto = None
saplogin()
If you need just to log into SAP you can use this simple snippet and not enter password at all如果您只需要登录 SAP,您可以使用这个简单的代码段,而根本不需要输入密码
import subprocess
subprocess.check_call(['C:\Program Files (x86)\SAP\FrontEnd\SAPgui\\sapshcut.exe', '-system=DCG210', '-client=100', '-user=USERNAME', '-pw=PASSWORD'])
Your GUI script only logins to SAP and does nothing more, it is scripting just for scripting.您的 GUI 脚本仅登录到 SAP 而不会执行其他操作,它只是用于编写脚本的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.