Summary
Important Observations
- Field level validation rules are applied before table level validation rules.
- The sequence of rules, combined with the validation actions, is very important in controlling when multiple rules are applied.
- Referential integrity can be added by using table lookup checks. Remember that referential integrity is usually defined in both tables 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 table level), the table OAM needs to be recompiled.
Tips and Techniques
- Most business rules should be defined at the table 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 table using the iiiSalary field has the same rules. Quite often, the iiiSalary will have a different meaning and different rules when used in different tables.
- 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 use, 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 an insert, update or delete statement, the rule check will not be performed. Typically, CHGUSE is applied on table rules (not ADDUSE or DLTUSE). Exercise REP008 - Virtual Columns 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 table.
What I Should Know
- Where validation rules are performed in the LANSA architecture.
- What rules are supported at the table level.
- At what level you should specify most of your rules.
- In what order the field and table validation rules are performed.
- How to use a code table lookup rule to create referential integrity.
- That you need to recompile your table after you have changed it.