How to check for problems with the ECI and EPI classes when starting methods, using Visual Basic and VBScript.
One way of handling exceptions is to use the ErrorWindow method and set it to false, then check the ExCode and ExCodeText methods after a call to see what the return codes are. The ErrorWindow method is not the recommended way and exists only to support compatibility with earlier versions for old applications.
The recommended way os handling exceptions is to use the Err objects which Visual Basic and VBScript provide. An Err object contains the information about an error. Visual Basic supports On Error Goto and On Error Resume features to detect that an error has occurred. VBScript only supports the On Error Resume Next feature. If you use On Error Resume Next either in Visual Basic or VBScript, you must always enter this line before any COM object call that you expect could return an error. Visual Basic/VBScript might not reset the Err variable unless you do this.
The type of interface you have selected (you DIM'ed a variable as either Object or classname) will affect the value contained in the Err.number property. It is possible to write a generic routine that handles all values in Err.Number and converts them to the documented ExCode error codes available. The example code following shows how to achieve this.
ECI.SetErrorFormat 1
or,
for EPI: EPI.SetErrorFormat 1
The following sample shows how to handle errors in Visual Basic.
Private Sub Command1_Click()
'
' The following code assumes you have created the
' required objects first, ECI, Connect, Flow, UOW,
' Buffer
'
On Error GoTo ErrorHandler
conn.Link flow, "EC01", buf, uow
Exit Sub
ErrorHandler:
'
' Ok, the Connect call failed
' Parse the Error Number, this will work regardless of
' how the ECI objects were Dimmed
'
Dim RealError As CclECIExceptionCodes
RealError = (Err.Number And 65535) - eci.ErrorOffset
If RealError = cclTransaction Then
'
' Transaction abend, so query the Abend code
'
AbendCode = flow.AbendCode
If AbendCode = "AEY7" Then
MsgBox "Invalid Userid/Password to execute CICS Program", , "CICS ECI Error"
Else
MsgBox "Unable to execute EC01, transaction abend:" + AbendCode, , "CICS ECI Error"
End If
Else
MsgBox Err.Description, , "CICS ECI Error"
End If
End Sub
The following sample shows error handling code for VBScript.
On Error Resume Next
con.Link flow, "EC01", buf, uow
if Err.Number <> 0 then
'
' Ok, the Connect call failed
' Parse the Error Number, this will work regardless of
' how the ECI objects were Dimmed
'
RealError = Err.Number And 65535 - eci.ErrorOffset
'
' 13 = CclTransaction, a transaction abend.
'
If RealError = 13 Then
'
' Transaction abend, so query the Abend code
'
AbendCode = flow.AbendCode
If AbendCode = "AEY7" Then
Wscript.Echo "Invalid Userid/Password to execute CICS Program"
Else
Wscript.Echo "Unable to execute EC01, transaction abend:", AbendCode
End If
Else
Wscript.Echo Err.Description
End If
End If