Below is SAP script for deleting specific rows in Source List.
Upon entering material number and plant there is possiblity of Warning messagees (Pending Obsolence, Requires exemption)- To continue to the next step an Enter session.findById("wnd[0]").sendVKey 0
is required once, twice or even 3 times. Again it depands on number of Warning messages on material.
In below example I have Enter 3 times but instead of using Enter 3 times by defalut I would like it to be more dynamic. If or as long there is an Warning message it should countionue to use Enter else move to next step in the script.
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
session.findById("wnd[0]").maximize
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
If IsEmpty(objSheet.Cells(i, 4)) Then
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nme01"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtEORD-MATNR").text = COL1 'Material number
session.findById("wnd[0]/usr/ctxtEORD-WERKS").text = COL2 'Plant
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205").getAbsoluteRow(COL3-1).selected = true 'Row to delete in SL
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205/ctxtEORD-VDATU[0,6]").setFocus
session.findById("wnd[0]/usr/tblSAPLMEORTC_0205/ctxtEORD-VDATU[0,6]").caretPosition = 0
session.findById("wnd[0]/tbar[1]/btn[14]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
session.findById("wnd[0]/tbar[0]/btn[11]").press
objSheet.Cells(i, 4) = "Deleted"
aux=COL1 & " " & COL2 & " " & COL3
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\SCRIPT\PlOrCreationLog.txt")
End If
next
msgbox "Process Completed"