I was faced today with the problem of trapping a certain condition when a line is entered into a form by means of an interface. I want to check all lines of a certain type that a condition does not occur; if it does, then I want to output an error message and stop the procedure. My initial code was as follows:
ERRMSG 353 FROM TEST_LOADSIFORDERS WHERE USER = SQL.USER AND RECORDTYPE = '2' AND U1 = '' AND PARTNAME = '000' AND STRIND (TEC_PN, 1, 8) = 'ASSEMBLY';
The only important thing here is the first line: if the clause is true, then error message 353 will be displayed. The error message itself says that a line has something missing. Unfortunately, this error message doesn't say on which line the error occurred (which wouldn't be useful, either) or which part is incompletely defined. It would be good if some identifier (TEC_PN) could be shown in the error message, but this concise syntax doesn't allow this. Another possibility is a loop, but that's something that could/should be avoided.
Then I remembered that I once wrote about two undocumented variables that can be useful in designing screen triggers, :GOTO and :WRNMSG. These two variables were used in a similar context: if some condition occurred, then the appropriate warning message would be displayed and execution would transfer to the label stored in :GOTO. I wondered whether there is an undocumented variable, :ERRMSG ... and it turns out that there is. So my code is now
SELECT 353, TEC_PN INTO :ERRMSG, :PAR1 FROM TEC_LOADSIFORDERS WHERE USER = SQL.USER AND RECORDTYPE = '2' AND U1 = '' AND PARTNAME = '000' AND STRIND (TEC_PN, 1, 8) = 'ASSEMBLY';
with the error message containing both unchanging text and P1, thus killing two birds with one stone. The disadvantage of this code as opposed to a loop is that the above ignores the possibility that two lines might have the error. I don't have any statistics at hand but I imagine that this error occurs about once every two hundred lines, which is why I don't want to slow down the 199 lines that are correct.
No comments:
Post a Comment