In this section: |
The term referential integrity defines the type of consistency that should exist between parent and descendant segments.
FOCUS can provide referential integrity for the following types of data sources described in one multi-segment Master File:
The following sections discuss referential integrity constraints.
The FOCUS MODIFY facility syntax provides automatic referential integrity for inserting new records.
You must describe the data source in one multi-segment Master File. The multi-segment description establishes the relationship between the segments.
With a multi-segment Master File, you cannot add a descendant segment using the FOCUS MODIFY facility unless the parent segment already exists. Therefore, a MODIFY procedure that inserts records must MATCH on the parent segment before adding a record in descendant segment.
The following examples demonstrate referential integrity when adding new records. The scenarios are:
A simple, annotated FOCUS MODIFY procedure for each scenario follows.
The first example adds course information only if a record already exists for the employee:
MODIFY FILE EMPWRITE CRTFORM LINE 2 "ADD SALARY INFORMATION FOR EMPLOYEE </1" 1. "EMPLOYEE ID: <EMPLOYEE_ID </1 " "SALARY: <SALARY CURR_CODE: <CURR_CODE " 2. MATCH EMPLOYEE_ID ON MATCH COMPUTE AQ0201_OCC = 0; 3. ON MATCH CONTINUE 4. ON NOMATCH REJECT 5. MATCH AQ0201_OCC ON NOMATCH INCLUDE ON MATCH REJECT DATA END
The MODIFY procedure processes as follows:
The second example adds a record to the EMPWRITE data source for a new employee and adds a salary for that employee to the AQ0201 segment. If the employee ID already exists, the procedure adds only the salary information to the AQ0201 segment:
MODIFY FILE EMPWRITE CRTFORM LINE 1 1. "ID: <EMPLOYEE_ID " 2. MATCH EMPLOYEE_ID 3. ON NOMATCH CRTFORM LINE 2 " LAST: <LAST_NAME FIRST: <FIRST_NAME </1 " " MIDDLE: <MIDDLE_NAME> </1 " " ADDRESS_LINE_CNT <ADDRESS_LINE_CNT> CITY: <CITY " " ZIP: <ZIP_CODE COUNTRY: <COUNTRY </1" " DEPT: <DEPT INCOME_CNT: <INCOME_CNT </1" "LEAVE DUE: <LEAVE_DUE DEPARTMENT: <DEPARTMENT " "SALARY: <SALARY CODE: <CURR_CODE " ON NOMATCH INCLUDE ON NOMATCH COMPUTE AQ0201_OCC = 0; ON MATCH COMPUTE AQ0201_OCC = 0; 4. ON MATCH CRTFORM LINE 9 "SALARY: <SALARY CODE: <CURR_CODE "R_TAKEN QTR: <QTR " 5. MATCH AQ0201_OCC ON NOMATCH INCLUDE ON MATCH REJECT DATA END
The MODIFY procedure processes as follows:
FOCUS provides automatic referential integrity for deleting records described in a multi-segment Master File. Just as with INCLUDE referential integrity, only data sources described in a multi-segment Master File invoke FOCUS DELETE referential integrity.
When you delete a parent segment in a MODIFY or Maintain procedure, FOCUS automatically deletes all descendant segments at the same time.
For example, when you delete an employee from the root segment in the EMPWRITE Master File, FOCUS also deletes all records from the descendent segments for the employee:
MODIFY FILE EMPWRITE CRTFORM LINE 2 "DELETE EMPLOYEE </1" 1. "EMPLOYEE ID: <EMPLOYEE_ID " 2. MATCH EMPLOYEE_ID ON MATCH COMPUTE DOIT/A1 = 'N'; ON MATCH CRTFORM LINE 6 3. "EMPLOYEE TO BE DELETED: <D.EMPLOYEE_ID </1" " LAST NAME: <D.LAST_NAME </1" " FIRST NAME: <D.FIRST_NAME </1" " DEPARTMENT: <D.DEPARTMENT </1" "IS THIS THE EMPLOYEE YOU WISH TO DELETE? (Y,N): <DOIT " ON MATCH IF DOIT EQ 'N' THEN GOTO TOP; 4. ON MATCH DELETE ON NOMATCH REJECT DATA END
The MODIFY procedure processes as follows:
You may not always want to enforce FOCUS referential integrity. If the referential integrity is being enforced between separate Adabas files described in a single Master File using an embedded join described in the Access File, you can describe each file you want to modify separately in a separate Master File
Another technique is to COMBINE data sources rather than using a multi-segment Master File. COMBINE of single data sources does not invoke FOCUS referential integrity.
Information Builders |