Adde
Adde

Reputation: 55

SAP GUI script how to test the presence of a message

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 ************************ ```

Upvotes: 0

Views: 4236

Answers (2)

Sandra Rossi
Sandra Rossi

Reputation: 13638

To complete the correct answer, the SAP GUI Scripting object corresponding to "wnd[0]/sbar" is: GuiStatusBar.

For information, below are the values of read-only properties corresponding to this display (in SE16): SE16 No table entries found for specified key MO429

  • MessageAsPopup: False
  • MessageId: "MO"
  • MessageNumber: "429"
  • MessageParameter(0): ""
  • MessageParameter(1): ""
  • MessageParameter(2): ""
  • MessageParameter(3): ""
  • MessageParameter(4): ""
  • MessageParameter(5): ""
  • MessageParameter(6): ""
  • MessageParameter(7): ""
  • MessageType (Read-only): "E"
  • Text (Read-only): "No table entries found for specified key"

For information, the text and ID of a message in the status bar can be found in the table T100 e.g.: SE16 T100

Upvotes: 1

Adde
Adde

Reputation: 55

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

Upvotes: 1

Related Questions