2
votes

I m using SAP GUI Scripting code for bulk record submission through SAP form. It picks records one by one from excel file and submits in SAP system.

My Question:

I want to include error handling into it. So that if any error occurs at any particular record submission, Script shouldn't stop. It should move to the next line after putting appropriate message in Comment field.

Can anyone throw some light how to identify whether SAP is facing some Error or Warning?

And if Error occurs how to get out of it i.e., how to handle that and move to next record submissions.

3

3 Answers

3
votes

Yes, You can do that.

Look for the status bar at botton

enter image description here

GUI Scripting help section in SAP is very helpful it will explain you things in very details.

GuiStatusBarObject --> Members --> Message Type

enter image description here

Us can use those properties as per your needs, If You need to move next , halt or notify user You can use these messages type and work accordingly.

SAP scripting does not throw error if error occurs in SAP itself , It will only throw error when it can not find elements or some other issue.

Sample Code :

Public Sub get_status_bar_value_exit_if_Error()
    Dim usr_resp As String
    If (session.findById("wnd[0]/sbar").messagetype = "E" Or session.findById("wnd[0]/sbar").messagetype = "W") Then
       usr_resp = MsgBox(session.findById("wnd[0]/sbar").Text & Chr(13) & "Show the Error in SAP ?", vbYesNo)
            If usr_resp = vbYes Then

        Else
            Call go_to_Sap_home
        End If

        End
    End If
End Sub

Here I chose to exit the current task and go to home if user chose not to see error in SAP ,else SAP will halt and user can see error in the status bar. You can do anything you want to do.

0
votes

unfortunately on error resume next will not help due to the fact that it can not find the object,

If (session.findById("wnd[0]/sbar").messagetype = "E" Or session.findById("wnd[0]/sbar").messagetype = "W") Then
       usr_resp = MsgBox(session.findById("wnd[0]/sbar").Text & Chr(13) & "Show the Error in SAP ?", vbYesNo)
            If usr_resp = vbYes Then

        Else
            Call go_to_Sap_home
        End If
this helped
-1
votes

The answer is basically On Error Resume Next but you can read more here... https://scn.sap.com/thread/3270803. On Error Resume Next alone will ignore all of your errors. You can make conditions through If.