In the following example, ErrorLevel_IV contains the error code number that denotes the particular error that occurred, and Message_SV contains the current error message
...
call EcsPressENTER()
if ( errorlevel != ECS_E_ERRORFREE ) then
copy errorlevel to ErrorLevel_IV
call EcsGetError( ErrorLevel_IV, Message_SV )
send "Error is: " ErrorLevel_IV "\n"
to errorlog
send "ErrorText is: " Message_SV "\n"
to errorlog
else ...
If there are no errors present, errorlevel will contain the value 0, which equals ECS_E_ERRORFREE, with the associated text "No errors detected". Each subroutine described in this guide lists the error conditions that can result when the subroutine is called, and shows the error code and associated error message text. The error code value is always represented by an integer constant whose names begin with ECS_E_. (See Reserved Variables Constants.) Always use these constants when testing the value of errorlevel.
Suppose the following ESL statements are executed:
# These statements will generate ECS error
# condition, because EcsReadLine cannot accept
# negative value for variable Row.
copy -3 to Row
call EcsReadLine( Row_IV, LineContents_SV )
After EcsReadLine returns, errorlevel will contain ECS_E_LINENUM, and the associated error message "Invalid line number" can be retrieved with a EcsGetError call to the DLL, as described earlier.
At a minimum, you should check for errors after every ECS call that triggers a host transaction. However, we recommend that you check for errors after each ECS subroutine call.
One benchmark test shows that the processing time for retrieving and checking the error level ranges between one ten-thousandths (0.0001) to four ten-thousandths (0.0004) of a second, depending on the hardware.
Many of the error conditions are caused by coding mistakes, as in the following example, and should never occur in a fully debugged program. The following example shows how you can develop a single error handling subroutine that can write errors encountered by ECS into an error log. Since the processing time for error checking is negligible, you can use the subroutine during both development and production.
subroutine ProcessEcsError
( integer: ErrorLevel_IV ) is
string Message _SV
if ( ErrorLevel_IV !=ECS_E_ERRORFREE ) then
call EcsGetError (ErrorLevel_IV, Message_SV )
send "HOST ERROR [" ErrorLevel_IV "]:" Message_SV "\n"
to errorlog
end if
In most host data entry screens, the host marks invalid field entries with a field attribute, such as the intensity of the entry field after you have pressed a special key. Normally, the pressing of this key signifies that you have completed the data entry and are ready to move on to the next screen. In this instance, you may want to check to see if you are at the current data entry screen. If that is the case, check through the entry fields, determine the field with the error condition, and retrieve that information.
The section "Host Field Validation Code Sample" has an example of how you can tie an ESL dialog object to a host field. If a field error is detected on the host, the color of the ESL dialog object is modified and the object is activated to draw the user's attention back to the invalid field.