痛点:SAP部分业务操作重复化、规律化; 目标:无意义的重复无脑操作全部自动化; 工具:Python pywin32库win32com.client模块结合SAP GUI Script; 说明:以下代码来源网络参考思路,无实际意义; 推荐阅读:SAP博客博主Stefan Schnell文章;(SAP脚本工具:https://blogs.sap.com/2014/11/20/scripting-tracker-development-tool-for-sap-gui-scripting/)
零、前奏:
通过Stefan Schnell分享的scripting Tracker工具摸清SAP树形结构ID属性,当然你也可以去看SAP GUI Script API文档。
源自SAP博客.jpg
一、需要的库
import win32com.client
二、获取SAP GUI
SapGuiAuto = win32com.client.GetObject("SAPGUI") application = SapGuiAuto.GetScriptingEngine connection = application.Children(0) session = connection.Children(0)
三、登录
#登录 session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "user" session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "password" session.findById("wnd[0]").sendVKey(0)
三、重复10000遍的操作
#主程序 def main(session): session.findById("wnd[0]/tbar[0]/okcd").text = "mm03" session.findById("wnd[0]").sendVKey(0) session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text="9000000000012" session.findById("wnd[0]").sendVKey(0) session.findById("wnd[1]/tbar[0]/btn[0]").press() session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP02").select() if __name__ == "__main__": main(session)