程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python multithreading SAP GUI script connecting python with SAP

編輯:Python

https://blogs.sap.com/2020/06/09/connecting-python-with-sap-step-by-step-guide/

''' This script utilizes `multiprocessing` library for SAP GUI automation. Credits to Stefan Schnell for setting up the baseline code. https://blogs.sap.com/2017/09/19/how-to-use-sap-gui-scripting-inside-python-programming-language/ '''
from multiprocessing import Process
import win32com.client
def SAP_Init():
SAP_GUI_AUTO = win32com.client.GetObject('SAPGUI')
if isinstance(SAP_GUI_AUTO, win32com.client.CDispatch):
application = SAP_GUI_AUTO.GetScriptingEngine
connection = application.Children(0)
return connection
def TASK_I():
''' Enter T-code SE16 '''
print('TASK I started.')
connection = SAP_Init()
session = connection.Children(0)
session.findById("wnd[0]").maximize()
session.findById("wnd[0]/tbar[0]/okcd").text = '/nSE16'
session.findById("wnd[0]").sendVKey(0)
print('TASK I complete.')
def TASK_II():
''' Enter T-code FBL3N '''
print('TASK II started.')
connection = SAP_Init()
session = connection.Children(0)
session.findById("wnd[0]").maximize()
session.findById("wnd[0]/tbar[0]/okcd").text = '/nFBL3N'
session.findById("wnd[0]").sendVKey(0)
print('TASK II complete.')
if __name__ == '__main__':
try:
window1 = Process(target = TASK_I)
window2 = Process(target = TASK_II)
window1.start()
window2.start()
except Exception as e:
print(e)

Reference resources
https://gist.github.com/marvintensuan/4b6254dbda81397752b4e07416500fee


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved