‎2022 Apr 21 9:08 PM
Hello, I'm a bignner in sapscript by python, I would like to import the data list from excel one by one to SAP to do some repeat operation automaticlly, how can I realize it? here is the code for your reference, thank you!
#log on SAP
import win32com.client
import subprocess
import sys
import time
import getpass
user=getpass.getuser()
SapGuiAuto = win32com.client.GetObject("SAPGUI")
application = SapGuiAuto.GetScriptingEngine
connection = application.Children(0)
session = connection.Children(0)
#Import pandas
import pandas as pd
import numpy as np
data=pd.read_excel("Order List.xlsx",sheet_name="Sheet1")
to_SAP=data['order'].reset_index(drop=True)
orderlist=to_SAP.values.tolist()
orderlist
[983424744,
983117520,
983117520,
983117513,
983117496,
983117510,
983117514,
983117514,
983495624]
def input_order(orderlist):
for order in orderlist:
session.findById("wnd[0]").maximize()
session.findById("wnd[0]/tbar[0]/okcd").text = "va03"
session.findById("wnd[0]").sendVKey(0)
session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = order (here I would like to loop order in excel)
session.findById("wnd[0]").sendVKey(0)
session.findById("wnd[0]/tbar[0]/okcd").text = "/n"
session.findById("wnd[0]").sendVKey(0)
input_order(orderlist)
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
<ipython-input-119-d366b506afd0> in <module>()
----> 1 input_order(orderlist)
<ipython-input-118-c89372a1fd5d> in input_order(orderlist)
4 session.findById("wnd[0]/tbar[0]/okcd").text = "va03"
5 session.findById("wnd[0]").sendVKey(0)
----> 6 session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = order
7 session.findById("wnd[0]").sendVKey(0)
8 session.findById("wnd[0]/tbar[0]/okcd").text = "/n"
D:\Python\lib\site-packages\win32com\client\dynamic.py in findById(self, *args)
com_error: (-2147352567, 'Exception occurred.', (619, 'SAP Frontend Server', 'The control could not be found by id.', 'c:\\program files (x86)\\sap\\frontend\\sapgui\\sapfront.HLP', 393215, 0), None)
‎2022 Apr 21 9:08 PM
Thank you for visiting SAP Community to get answers to your questions.
Since you're asking a question here for the first time, I'd like to recommend you with the following steps so you can get the most out of your community membership:
I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.
I hope you find this advice useful, and we're happy to have you as part of SAP Community!
All the best,
-Alex