REP007 - File Validation Rules/Triggers
Field level validation rules are applied before file level validation rules.
The sequence of rules, combined with the validation actions, is very important in controlling when multiple rules are applied.
Referential file integrity can be added by using file lookup checks. Remember that referential integrity is usually defined in both files within a relationship. In our example, Department cannot be deleted if Employees exist, and Employees cannot be added unless the Department exists.
Notice that the trigger function is called after the validation rules are performed. This order of operations prevents invalid data from being passed into the trigger.
Whenever a validation rule or trigger is changed (at field or file level), the file OAM needs to be recompiled.
Tips and Techniques
Most business rules should be defined at the file level. Only in special circumstances should you use a field level rule. For example, when you define the rule for iiiSalary at the field level, then every file using the iiiSalary field has the same rules. Quite often, the iiiSalary will have a different meaning and different rules when used in a different file.
You can create Complex logic rules when you need to perform more complex checking than supported by standard value types.
The use of NEXT, ERROR and ACCEPT processing with multiple rules for a field is very important. ACCEPT processing means that no more rules are evaluated.
It is very important that you check the Actions tab to ensure that you have properly defined the validation usage, that is, when should an error occur. For example, a simple logic check rule can be defined as (#DEPT *NE *BLANKS). If true, is this an error?
The ADDUSE and CHGUSE options control if validation rules are performed. If the field is not included in insert, update or delete, the rule check will not be performed. Typically CHGUSE is applied on file rules (not ADDUSE or DLTUSE). Exercise REP008 - Virtual Fields gives an example of how these options can be used.
Trigger functions are very useful if you want to perform server-side procedures when building client/server or web-based applications.
Trigger functions can be used to define virtual fields and can be used to perform complex validation rules in a file.
What I Should Know
Where validation rules are performed in the LANSA architecture.
What rules are supported at the file level.
At what level you should specify most of your rules.
In what order are the field and file validation rules performed.
How to use a code file/table lookup rule to create referential integrity.
That you need to recompile your file after you have changed it.