ILE COBOL Programmer's Guide


Processing Files with Constraints

Data within the fields of a database physical file (SQL TABLE) can be restricted to certain values by adding a constraint relationship. There are four types of constraints:

You can use constraint relationships to define dependencies between files. The relationships that you define are enforced by the system when changes occur to information in the files. When you define constraint relationships, you control the referential integrity of the data being processed.

Check constraints are validity checks that can be placed on fields (columns) in the database physical files (SQL tables), thereby increasing the integrity of your data.

When data is inserted or updated in fields with constraints, the data must first meet the validity checks placed on those fields, before the insert or update operation can be completed. If all of the constraints are not met, then the I/O request is not performed, and a message is sent back to the program indicating that a constraint has been violated. When a check constraint has been violated during the running of a COBOL I/O statement, a file status of 9W is set. If a referential constraint is violated, a file status of 9R is set.

Although only physical files can have constraints, the constraint is enforced while performing I/O on a logical file built over a physical file with constraints. Check constraints can be used for one or many fields, and can be used with field-to-field-comparisons or field-to-literal comparisons.

For more detailed information about constraints, refer to the DB2 Universal Database for AS/400 section of the Database and File Systems category in the iSeries 400 Information Center at this Web site - http://publib.boulder.ibm.com/pubs/html/as400/infocenter.htm.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]