简体   繁体   中英

SAP Error handling by SAP GUI Scripting

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 ie, how to handle that and move to next record submissions.

Yes, You can do that.

Look for the status bar at botton

在此处输入图片说明

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

GuiStatusBarObject --> Members --> Message Type

在此处输入图片说明

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM