Using VAL_ERROR(*LASTDIS) in Subroutine, Evtroutine and Mthroutine
|Date:||8 February 2002|
|Product/Release:||Visual LANSA / LANSA for iSeries|
|Abstract:||Application failure when using VAL_ERROR(*LASTDIS) in a subroutine does not occur when used in methods and events|
|Submitted By:||LANSA Technical Support|
|Last Update:||November 2010|
All LANSA database commands have a parameter of VAL_ERROR. The default value for this is *LASTDIS., meaning "Last display".
Consider the following code:
Begin_loop Change Field(#deptment #deptdesc) to(*default) Request Fields(#deptment #deptdesc) Insert Fields(#deptment #deptdesc) to_file(deptab) val_error(*lastdis) End_loop
In this situation, the "Last display" is the REQUEST command, and it is at the same invocation level as the database command.
When a validation error occurs, control is returned to the last display, any fields in error appear in reverse image, and the appropriate error messages are displayed on the message line.
Now consider the following code:
Begin_loop Change Field(#deptment #deptdesc) to(*default) Request Fields(#deptment #deptdesc) Execute subroutine(Insert_rec) End_loop * ********* Subroutine Nmae(Insert_rec) Insert Fields(#deptment #deptdesc) to_file(deptab) val_error(*lastdis) Endroutine
Functionally, this code appears to be the same. However, the last display is now at a different invocation level. If a validation error occurs on the INSERT, the function will attempt to return control to the last display. As the last display is not at the same level, the function will abort. All messages generated by the OAM will be sent to the message line.
It should be noted that in functions where there is no last display, e.g. batch functions, *LASTDIS will be treated as *NEXT.
Event routines and method routines behave slightly differently.
Consider the following examples:
Evtroutine Handling(#Insert.Click) Insert Fields(#deptment #deptdesc) to_file(deptab) val_error(*lastdis) End
Evtroutine Handling(#Insert.Click) Invoke Method(#com_owner.Insert_to_file) End Mthroutine Name(Insert_to_File) Insert Fields(#deptment #deptdesc) to_file(deptab) val_error(*lastdis) Endroutine
These two examples will behave in exactly the same way.
Example 3 is no different in concept to Example 1. When a button is clicked, an attempt is made to insert a record to a file.
However, Example 4 has two layers of invocation: the evtroutine and the method. But, a method can be invoked from an external source e.g. a method in a reusable part. When invoked from an external source, it will be the top level of invocation, and must therefore attempt to return to the last display. As a method never knows what has invoked it, or how many levels there are above it, it must assume that it is the top, and therefore return errors.