Link data items are used to link one data set record to another. They represent a logical relationship between records. Link data items cannot point to sectioned data sets. However, link data items that point to nonsectioned data sets can be included in sectioned data sets.
When a link item is used in a data set, both the data set containing the link item and the data set being pointed to by the link must be declared using the EXTENDED keyword or must omit the EXTENDED declaration. That is, the use of the EXTENDED attribute for both data sets must be identical.
When a link item occurs in DASDL before its object data set, it creates a forward declaration. DASDL has a limit of 511 forward declarations.
The following are the types of links available:
<link data items>
──┬─<counted links>─────────┬──────────────────────────────────────────┤ ├─<self-correcting links>─┤ ├─<symbolic links>────────┤ ├─<unprotected links>─────┤ └─<verified links>────────┘
The text in this section describes the use of links followed by a description of each link type.
The following example uses the counted link type:
D DATA SET ( L-COUNTED IS IN E COUNTED; L-SELF-CORRECTING IS IN S; L-SYMBOLIC IS KEY OF S; L-UNPROTECTED IS IN E WITH NO PROTECTION; L-VERIFIED IS IN E VERIFY ON K; A ALPHA(3); )EXTENDED = TRUE, SECTIONS = 2; E DATA SET ( LINK-COUNT COUNT(10); K ALPHA(5); )EXTENDED = TRUE; S SET OF E KEY K NO DUPLICATES;
Links can also be used to represent relationships between records in a single data set. When an EMPLOYEE record has been selected, the employee's supervisor can be determined using the link item SUPERVISOR.
Links represent one-directional relationships. For example, the SUPERVISOR link item can be used to determine an employee's supervisor, but it cannot be used to locate the people who work for a particular supervisor. If both the SUPERVISOR relationship and the SUBORDINATE relationship must be represented in the database, two links can be declared as shown in the following example:
EMPLOYEE DATA SET ( EMP-NUMBER NUMBER(7); NAME ALPHA(20); TITLE ALPHA(20); SUPERVISOR IS IN EMPLOYEE VERIFY ON EMP-NUMBER; SUBORDINATE IS IN EMPLOYEE VERIFY ON EMP-NUMBER OCCURS 15 TIMES; );
As before, the SUPERVISOR link is used to locate an employee's supervisor. The SUBORDINATE link is used to determine an employee's subordinates. The occurring link allows an employee to have several subordinates.
A link can point only to one record at a time. If a record must be linked to several records simultaneously, then multiple link items must be declared, an occurring link must be used, or a subset must be employed. The following examples illustrate the uses of links.
Example 1
The database includes two data sets related using a link. When a record in the CUSTOMER data set has been retrieved, the corresponding MAILLIST record can be located using the MAIL-ADDR link.
CUSTOMER DATA SET ( ACCOUNT-NO NUMBER(6); NAME ALPHA(25); BALANCE NUMBER(S9,2); MAIL-ADDR IS IN MAILLIST VERIFY ON TELEPHONE; ); MAILLIST DATA SET ( STREET-NO NUMBER(7); STREET-NAME ALPHA(20); CITY ALPHA(20); STATE ALPHA(20); ZIPCODE NUMBER(5); TELEPHONE NUMBER(10); );
Example 2
The database includes a link that maps to an item that is declared in the same data set as the link. When a record in the EMPLOYEE data set is retrieved, the same record must also be located using the EMPLOYEE link.
EMPLOYEE DATA SET ( EMP-NUMBER NUMBER(7); NAME ALPHA(20); TITLE ALPHA(20); SUPERVISOR IS IN EMPLOYEE VERIFY ON EMP-NUMBER; );
When a link item is declared in a DASDL description, the database administrator specifies which data set the link is to reference. Scope rules for links, which are exactly like those for manual subsets, control which data sets can be specified.
The data set referenced must be
-
Disjoint
-
Owned by the data set containing the link
-
Owned by an ancestor of the data set containing the link
An ancestor is the owner, the owner's owner, and so on.
Example 1
The relationships illustrated in Links are based on the following DASDL description:
A DATA SET ( B DATA SET ( D DATA SET( ... ); E DATA SET( ... ); ); C DATA SET ( F DATA SET( ... ); G DATA SET( ... ); ); ); X DATA SET ( Y DATA SET( ... ); Z DATA SET( ... ); );
Data set A has no ancestors. Links in data set A can reference the disjoint data sets A or X, or the embedded data sets B or C.
Data set B has a single ancestor: data set A. Links in data set B can reference disjoint data sets A or X, or embedded data sets B or C.
Data set D has two ancestors, data sets A and B. A link in data set D can reference data sets A, X, B, C, D, or E.
The database administrator is responsible for declaring the link item and selecting the data set which it references; but host language programs are responsible for establishing and severing relationships between particular records. User programs link records by assigning a value to the link item. The contents of the link enable the system to locate the associated record in the referenced data set. If a link item in a record has not been assigned a value, the link is said to be null. Host language programs written in COBOL can determine if a link has been assigned a value using the IF statement, while ALGOL programs can test a link with the DMTEST statement.
Host language programs must observe the following restrictions when assigning a value to a link:
-
The record being pointed to must be contained in the data set specified when the link was declared.
-
If the link references a disjoint data set, then the link can point at any record in the data set. If the link references an embedded data set, then only certain records in the data set can be referenced. The record being referenced must be owned by the record containing the link or by an ancestor of the record containing the link. (An ancestor is the owner, the owner's owner, and so on.)
Example 2
The relationships illustrated in Scope Rules for Links are based on the following DASDL description:
A DATA SET ( B DATA SET( ... ); C DATA SET ( D DATA SET ( L IS IN ... ; % links illustrated in Figure 9-2. ); ); );
Scope Rules for Links depicts a portion of the database with record A4 as the current record of A, record C17 as the current record of C, and record D34 as the current record of D. The link L contained in record D34 can reference only some data set records.
The record relationship for these data sets is based on the following conditions:
-
If L references data set A, it can reference any record in A.
-
If L references data set B, it can reference records B54, B55, B58, and B60.
-
If L references data set C, it can reference records C15 and C17.
-
If L references data set D, it can reference records D34, D37, and D39.
Link Types
There are five different types of links corresponding to the five mechanisms by which a link can point to a record in a data set. Basic Link Syntax provides the basic syntax for each type of link. Following the table is a more detailed explanation of each type of link.
Table 9. Basic Link Syntax
Link Type |
Syntax |
---|---|
Counted |
IS IN <data set name> COUNTED |
Self-correcting |
IS IN <set name> |
Symbolic |
IS KEY OF <set name> |
Unprotected |
IS IN <data set name> WITH NO PROTECTION |
Verified |
IS IN <data set name> VERIFY ON <item name> |
A data set referenced by a counted link must contain a count item. The count item is maintained by the system; its value indicates the number of counted links that currently point at the record. Records which contain a nonzero value in the count item cannot be deleted. Any program which attempts to delete a record with a nonzero count item receives an exception and the record is not deleted. Counted Link illustrates a counted link.
The following diagram illustrates the syntax for counted links:
<counted links>
──<counted link name>─┬───────────┬────────────────────────────────────► └─<comment>─┘ ►─┬─ IS IN ────────┬─ <data set name> COUNTED ─────────────────────────► └─ REFERENCE TO ─┘ ►─┬───────────────────────────────────┬────────────────────────────────┤ └─ OCCURS <unsigned integer> TIMES ─┘
The following table explains the elements of the syntax diagram:
Example
The following example illustrates the DASDL syntax for a counted link:
D DATA SET ( L IS IN E COUNTED; A ALPHA(3); ); E DATA SET ( L-C COUNT(10); Y ALPHA(3); K NUMBER(3); );
When a self-correcting link is assigned a value, both the address and the key of the referenced record are stored in the link. On retrieval, the key value stored with the link is compared to the key of the record located using the address. If the key values are not equal, the set is searched using the key value stored in the link item. If the search is successful, the address field in the link item is corrected; otherwise, the user program is notified that no record was found and the link is assigned a null value.
If the key value stored with the link and the key in the referenced data set match, self‑correcting links provide quick access to the referenced data set. When the values do not match, the system automatically corrects the link to ensure that future references to the link will locate the record directly.
Self-Correcting Link illustrates self-correcting links.
The following diagram illustrates the syntax for self-correcting links:
<self-correcting links>
──<self-correcting link name>─┬───────────┬────────────────────────────► └─<comment>─┘ ►─┬─ IS IN ────────┬─<set name>────────────────────────────────────────► └─ REFERENCE TO ─┘ ►─┬───────────────────────────────────┬────────────────────────────────┤ └─ OCCURS <unsigned integer> TIMES ─┘
The following table explains the elements of the syntax diagram:
Example
The following example illustrates the DASDL syntax for a self-correcting link:
D DATA SET ( L IS IN S; A ALPHA(3); ); E DATA SET ( Y ALPHA(3); K NUMBER(3); ); S SET OF E KEY K NO DUPLICATES;
When a symbolic link is assigned a value, the key value of the referenced record is stored in the link. On retrieval, this key value is used to search the set. Records can be changed or deleted without concern for existing links because all accesses go through the set. A NOTFOUND exception is returned when a FIND operation is performed and no matching entry is found in the set.
Symbolic links are most useful when the referenced data set changes frequently.
Symbolic Link illustrates symbolic links.
The following diagram illustrates the syntax for symbolic links:
<symbolic links>
──<symbolic link name>─┬───────────┬───────────────────────────────────► └─<comment>─┘ ►─┬─ IS KEY OF ───────────┬─<set name>─────────────────────────────────► └─ REFERENCE TO KEY OF ─┘ ►─┬───────────────────────────────────┬────────────────────────────────┤ └─ OCCURS <unsigned integer> TIMES ─┘
The following table explains the elements of the syntax diagram:
Example
The following example illustrates the DASDL syntax for a symbolic link:
D DATA SET ( L IS KEY OF S; A ALPHA(3); ); E DATA SET ( Y ALPHA(3); K NUMBER(3); ); S SET OF E KEY K NO DUPLICATES;
Unprotected Links
When an unprotected link is assigned a value, the address of the referenced record is stored in the link. During retrieval, this address is used to locate the record. The user is entirely responsible for ensuring that the correct record is retrieved. If the record pointed to by the link is relocated or deleted, results from the use of the link are unpredictable.
Unprotected links should be used only when the records in the data set referenced by the link will never be deleted or moved. In general, unprotected links should be avoided.
Unprotected Link illustrates an unprotected link.
The following diagram illustrates the syntax for unprotected links:
<unprotected links>
──<unprotected link name>─┬───────────┬────────────────────────────────► └─<comment>─┘ ►─┬─ IS IN ────────┬─ <data set name> WITH NO PROTECTION ──────────────► └─ REFERENCE TO ─┘ ►─┬───────────────────────────────────┬────────────────────────────────┤ └─ OCCURS <unsigned integer> TIMES ─┘
The following table explains the elements of the syntax diagram:
Option |
Description |
---|---|
An unprotected link name is an identifier that names the item. The unprotected link name cannot exceed 30 characters. |
|
A data set name indicates which data set the link references. Scope rules control which data sets can be referenced. For more information, refer to “Scope Rules for Links” earlier in this section. |
|
The OCCURS option is used to establish an ordered collection of link items, all of which reference the same data set. The unsigned integer following OCCURS controls the number of times the link is repeated. The value of the unsigned integer must not exceed 1023. Whenever the occurring link item is referenced, its name must be followed by a subscript enclosed within parentheses. Valid subscripts range from 1 to the value of the unsigned integer. |
Example
The following example illustrates the DASDL syntax for an unprotected link:
D DATA SET ( L IS IN E WITH NO PROTECTION; A ALPHA(3); ); E DATA SET ( Y ALPHA(3); K NUMBER(3); );
When a verified link is assigned a value, both the address of the referenced record and the value of the item specified following VERIFY ON are stored in the link. On retrieval, the value of the item stored with the link is compared to the value of the item in the record located using the address. If the values are not equal, an exception is returned.
Verified Link illustrates a verified link.
The following diagram illustrates the syntax for verified links:
<verified links>
──<verified link name>─┬───────────┬───────────────────────────────────► └─<comment>─┘ ►─┬─ IS IN ────────┬─ <data set name> VERIFY ON ───────────────────────► └─ REFERENCE TO ─┘ ►─┬─<alpha item name>───┬──────────────────────────────────────────────► ├─<Boolean item name>─┤ ├─<field item name>───┤ ├─<numeric item name>─┤ └─<real item name>────┘ ►─┬───────────────────────────────────┬────────────────────────────────┤ └─ OCCURS <unsigned integer> TIMES ─┘
The following table explains the elements of the syntax diagram:
Option |
Description |
---|---|
The verified link name is an identifier that names the item. The verified link name cannot exceed 30 characters. |
|
The data set name indicates which data set the link references. Scope rules control which data sets can be referenced. For more information, refer to “Scope Rules for Links” earlier in this section. |
|
The data item named following VERIFY ON specifies the item that is to be stored with the link. The item must be a nonsubscripted data item. |
|
The OCCURS option is used to establish an ordered collection of link items, all of which reference the same data set. The unsigned integer following OCCURS controls the number of times the link is repeated. The value of the unsigned integer must not exceed 1023. Whenever the occurring link item is referenced, its name must be followed by a subscript enclosed within parentheses. Valid subscripts range from 1 to the value of the unsigned integer. |
Example
The following example illustrates the DASDL syntax for a verified link:
D DATA SET ( L IS IN E VERIFY ON K; A ALPHA(3); ); E DATA SET ( Y ALPHA(3); K NUMBER(3); );