errorlog() takes a character expression as its argument and copies that argument into the current error log file.
If you simply invoke startlog(), any extra error records that 4GL adds to the error log after each following error have this format:
Date: 11/05/2004 Time: 13:57:14
Program error at "contact.4gl", line number 137.
SQL statement error number -236.
Number of columns in INSERT does not match number of VALUES
The actual record might be incomplete if, after an error, the operating system does not keep the buffer containing the module name or the line number. You can use errorlog() to supplement default error records with additional information. Entries that errorlog() makes in the error log file automatically include the date and time when the error was recorded.
This description details a typical sequence of events when logging system error messages:
Call STARTLOG( ) to open or create an error log file.
If an error is found, test the value of the global status variable to see if it is less than zero.
If its status is negative, call ERR_GET( ) to retrieve the error text.
Call ERRORLOG( ) to make an entry into the error log file.
By default, the WHENEVER ERROR CONTINUE statement is in effect. This default prevents the first SQL error from terminating program execution. It can be over-ridden with another statement or action.
You can use errorlog() to identify errors in programs that you are developing and to customize error handling. Even after implementation, some errors, such as those relating to permissions and locking, are sometimes unavoidable. These errors can be trapped and recorded by these logging functions.
You can use error-logging functions with other 4GL features for instrumenting a program, by tracking the way the program is used. This functionality is not only valuable for improving the program but also for recording work habits and detecting attempts to breach security.
The following program fragment calls startlog() in the MAIN program block. Here errorlog() has a quoted string argument:
CALL STARTLOG("errors.txt")
...
CALL errorlog("Encountered unexpected error"")
If its argument is not of a character data type (for example, a DECIMAL variable), invoking errorlog() can itself produce an error.
Automatic error logging increases the size of the generated executable.