SAP GUI script how to test the presence of a message

白昼怎懂夜的黑 提交于 2021-02-11 14:30:12

问题


Below I have a pretty simple and straight forwards script for update Valid To date on Agreement/Contract in SAP.

My script runs fine but if the date I want to change to is already the same then there is nothing to change/save and therefore the script stops...

After this step session.findById("wnd[1]/usr/btnSPOP-OPTION1").press is performed the message from the system is No data changed and it's after this step the script stops. Message No. 06022

The recording part in the script is based on that you can save but when the "non change" scenario occures because the date is already the same then there is nothing to save and the script stops.

How can I add functionality to the script so that it still continues to next Agreement/Contract even though there is nothing to save on the current one. I would also like to add a comment in that case "No change". When it does update I have objSheet.Cells(i, 3) = "Updated" but when there is nothing to save (not possible to save) I would like to have in column 3 comment "No data changed".

   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


REM ADDED BY EXCEL *************************************

Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet

For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1 Agreement/Contract number
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2 New Valid to date
    if isEmpty(objSheet.cells(i,3)) then


session.findById("wnd[0]/tbar[0]/okcd").text = "/nme32k"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRM06E-EVRTN").text = COL1
session.findById("wnd[0]/usr/ctxtRM06E-EVRTN").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[6]").press
session.findById("wnd[0]/usr/ctxtEKKO-KDATE").text = COL2
session.findById("wnd[0]/usr/ctxtEKKO-KDATE").setFocus
session.findById("wnd[0]/usr/ctxtEKKO-KDATE").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press


objSheet.Cells(i, 3) = "Updated"

REM FINALIZATION CONTROL CHECK ************************

aux=col1 & " " & COL2
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\SCRIPT\PlOrCreationLog.txt")

End if
next

msgbox "Process Completed"

REM FINALIZATION CONTROL CHECK ************************ ```

回答1:


I managed to solve it after many tries and help in the comment section :)

session.findById("wnd[0]/tbar[0]/btn[11]").press
If session.ActiveWindow.Name = "wnd[1]" then
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
objSheet.Cells(i, 3) = "Updated"

else

objSheet.Cells(i, 3).Value = session.findById("wnd[0]/sbar").Text

End if


来源:https://stackoverflow.com/questions/65352648/sap-gui-script-how-to-test-the-presence-of-a-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!