cancel
Showing results for 
Search instead for 
Did you mean: 

Scripts to transfer data from Excel to SAP

Former Member
0 Kudos

Hi SAP community ,

im new about scripts in SAP,
what i want t make is optimizate an orders notification process what we do every month.
what i did is to record a script and then (by the notepad program) modificated it, putting the values that i want in a worksheet (excel) and taking the values from that sheet, my whole code is the following one:

******************************************************************************************

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

Set xclapp = CreateObject("Excel.Application")
Set xclwbk = xclapp.Workbooks.Open("C:\Users\ccoaquim\Desktop\Libro1.xls")
set xclsht = xclwbk.Sheets("Hoja3")

for i= 4 to 8

session.findById("wnd[0]/tbar[0]/okcd").text = "/N iw41"
session.findById("wnd[0]").sendVKey 0

if xclsht.Cells(i+1,3).Value > 10 then

session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").text = xclsht.Cells(i,2).Value
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").setFocus
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tblSAPLCORUTC_3100").getAbsoluteRow(0).selected = true
session.findById("wnd[0]/usr/tblSAPLCORUTC_3100/txtCORUF-UPD_ICON[0,0]").setFocus
session.findById("wnd[0]/usr/tblSAPLCORUTC_3100/txtCORUF-UPD_ICON[0,0]").caretPosition = 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/txtW_NOPERS").text = xclsht.Cells(i,8).Value
session.findById("wnd[0]/usr/txtW_DURPERS").text = xclsht.Cells(i,6).Value
session.findById("wnd[0]/usr/txtW_AUTOR").text = xclsht.Cells(i,10).Value
session.findById("wnd[0]/usr/ctxtAFRUD-ISDD").text = xclsht.Cells(i,11).Value
session.findById("wnd[0]/usr/ctxtAFRUD-ISDZ").text = xclsht.Cells(i,13).Value
session.findById("wnd[0]/usr/ctxtAFRUD-IEDD").text = xclsht.Cells(i,14).Value
session.findById("wnd[0]/usr/ctxtAFRUD-IEDZ").text = xclsht.Cells(i,16).Value
session.findById("wnd[0]/usr/ctxtAFRUD-GRUND").text = "1001"
session.findById("wnd[0]/usr/txtAFRUD-LTXA1").text = xclsht.Cells(i,17).Value
session.findById("wnd[0]/usr/txtAFRUD-LTXA1").setFocus
session.findById("wnd[0]/usr/txtAFRUD-LTXA1").caretPosition = 1
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
else
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").text = xclsht.Cells(i,2).Value
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").setFocus
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/txtW_NOPERS").text = xclsht.Cells(i,8).Value
session.findById("wnd[0]/usr/txtW_DURPERS").text = xclsht.Cells(i,6).Value
session.findById("wnd[0]/usr/txtW_AUTOR").text = xclsht.Cells(i,10).Value
session.findById("wnd[0]/usr/ctxtAFRUD-ISDD").text = xclsht.Cells(i,11).Value
session.findById("wnd[0]/usr/ctxtAFRUD-ISDZ").text = xclsht.Cells(i,13).Value
session.findById("wnd[0]/usr/ctxtAFRUD-IEDD").text = xclsht.Cells(i,14).Value
session.findById("wnd[0]/usr/ctxtAFRUD-IEDZ").text = xclsht.Cells(i,16).Value
session.findById("wnd[0]/usr/ctxtAFRUD-GRUND").text = "1001"
session.findById("wnd[0]/usr/txtAFRUD-LTXA1").text = xclsht.Cells(i,17).Value
session.findById("wnd[0]/usr/txtAFRUD-LTXA1").setFocus
session.findById("wnd[0]/usr/txtAFRUD-LTXA1").caretPosition = 1
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
end if

next

******************************************************************************
i just notice that the comand "if" is not working, i mean that in the line 25:

"if xclsht.Cells(i+1,3).Value > 10 then"

the script doesnt follow the "if" comand, and it also continue with the comands which are after
the comand : "else"

Please i'd be very grateful to get an answer

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

Hi Jorge,

it looks so as in lines 5 to 9 and in the column 3 in excel sheet only values existent ​​that are really smaller or equal as 10. Where is the value which is greater than 10?

Regards,

ScriptMan