Verifies that a record complies with mandatory field and unique index definitions.
Syntax
VALIDATE record [ NO-ERROR ]
|
-
record
-
The name of the record you want to validate.
To validate a record in a table defined for multiple databases, you
must qualify the record's table name with the database name. See the record definition in the Record phrase reference entry for
more information.
- NO-ERROR
- The NO-ERROR option is used to
prevent the statement from raising ERROR and
displaying error messages.
Example
This procedure prompts for an item number. If an Item with that number is
not available, the procedure creates a new Item record and lets you supply some Item
information. The VALIDATE statement checks the data you enter against the
index and mandatory field criteria for the Item record.
r-valid.p
REPEAT FOR Item:
PROMPT-FOR Item.ItemNum.
FIND Item USING Item.ItemNum NO-ERROR.
IF NOT AVAILABLE Item THEN DO:
CREATE iIem.
ASSIGN Item.ItemNum.
UPDATE Item.ItemName Item.Price.
VALIDATE Item.
END.
ELSE
DISPLAY Item.ItemName Item.Price.
END.
|
Notes
- Because validation is done automatically, you rarely have to use the
VALIDATE statement. The AVM automatically validates a record when a
record in the record buffer is replaced by another, a record's scope iterates or ends, the
innermost iterating subtransaction block that creates a record iterates, or a transaction
ends.
- The AVM automatically validates mandatory fields when those fields
are modified.
- If the validation fails on a newly-created record,
VALIDATE raises the ERROR condition.
- The AVM performs validation when it leaves a field.
- For complex validations, it might be easier to use the
IF...THEN...ELSE statement instead of the VALIDATE
statement.
- You cannot use the VALIDATE statement to test fields
that are referenced in SQL statements, since validation is not performed for these
fields.
- If a field or table has been modified, the VALIDATE
statement causes WRITE events and all related WRITE
triggers to execute.