简体   繁体   English

通过 SAP GUI 脚本处理 SAP 错误

[英]SAP Error handling by SAP GUI Scripting

I m using SAP GUI Scripting code for bulk record submission through SAP form.我正在使用 SAP GUI 脚本代码通过 SAP 表单批量提交记录。 It picks records one by one from excel file and submits in SAP system.它从excel文件中一一挑选记录并提交到SAP系统中。

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.在 Comment 字段中放置适当的消息后,它应该移动到下一行。

Can anyone throw some light how to identify whether SAP is facing some Error or Warning?任何人都可以说明如何确定 SAP 是否面临错误或警告?

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在 botton 处寻找状态栏

在此处输入图片说明

GUI Scripting help section in SAP is very helpful it will explain you things in very details. SAP 中的 GUI 脚本帮助部分非常有用,它会非常详细地为您解释。

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.如果 SAP 本身发生错误,SAP 脚本不会抛出错误,它只会在找不到元素或其他问题时抛出错误。

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.在这里我选择退出当前任务并回家,如果用户选择不在 SAP 中看到错误,否则 SAP 将停止并且用户可以在状态栏中看到错误。 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,不幸的是,由于找不到对象,因此错误恢复 next 将无济于事,

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 但您可以在此处阅读更多内容... https://scn.sap.com/thread/3270803 On Error Resume Next alone will ignore all of your errors. On Error Resume Next 单独将忽略您的所有错误。 You can make conditions through If.您可以通过 If 设置条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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