Python源码
#-Begin-----------------------------------------------------------------
#-Includes--------------------------------------------------------------
import sys, win32com.client
import os
#-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
application.HistoryEnabled = False
connection = application.Children(0)
if not type(connection) == win32com.client.CDispatch:
application = None
SapGuiAuto = None
return
if connection.DisabledByServer == True:
connection = None
application = None
SapGuiAuto = None
return
session = connection.Children(0)
if not type(session) == win32com.client.CDispatch:
connection = None
application = None
SapGuiAuto = None
return
if session.Busy == True:
session = None
connection = None
application = None
SapGuiAuto = None
return
if session.Info.IsLowSpeedConnection == True:
session = None
connection = None
application = None
SapGuiAuto = None
return
#>Insert your SAP GUI Scripting code here<
session.findById("wnd[0]").resizeWorkingPane(112, 26, 0)
session.findById("wnd[0]/tbar[0]/okcd").text = "as02"
session.findById("wnd[0]").sendVKey(0)
os.chdir(r'D:\资产修改')
fi = open("as03.txt")
for i in fi:
i = i.split()
# print(i[0])
session.findById("wnd[0]/usr/ctxtANLA-ANLN1").text = i[0]
session.findById("wnd[0]/usr/ctxtANLA-BUKRS").text = "8000"
session.findById("wnd[0]/usr/ctxtANLA-BUKRS").setFocus()
session.findById("wnd[0]/usr/ctxtANLA-BUKRS").caretPosition = 4
session.findById("wnd[0]/tbar[1]/btn[8]").press()
session.findById("wnd[0]/mbar/menu[1]/menu[0]").select()
session.findById("wnd[0]/usr/subDEPR_PARAM:SAPLAIST:3095/chkANLB-XNEGA").selected = -1
session.findById("wnd[0]/usr/subDEPR_PARAM:SAPLAIST:3095/chkANLB-XNEGA").setFocus()
session.findById("wnd[0]/tbar[0]/btn[11]").press()
except:
print(sys.exc_info()[0])
finally:
application.HistoryEnabled = True
session = None
connection = None
application = None
SapGuiAuto = None
#-Main------------------------------------------------------------------
Main()
#-End-------------------------------------------------------------------
数据模板
import os
os.chdir(r'C:\Users\admin\PycharmProjects\pythonProject')
fi = open("as03.txt")
for i in fi:
i = i.split()
print(i)
资产编码
['1000000']
['1000001']
注意事项
1、仅限于正对SAP日常工作的批量处理
2、需要管理员授权RZ11脚本录制回放功能
3、数据模板按实际需求更新