A pointer to the table that will become a child to parent <TBL>.
Add a relation to a table.
Type "N". Describes the relationship between the parent and child tables. The Link Type parameter can be assigned one of four types of links:
- Link Type
One record from the parent table is related to one or more records in the child table.
One record from the parent table is related to the first matching record in the child table.
One record from the parent table is related to the last matching record in the child table.
One record from the parent table is related to the closest matching record in the child table.
Type "P". To link tables, the linking field(s) in the child table must be indexed. To specify the linking index, assign the Relation.index_child a pointer to an existing index.
Type "C". Indicates which field or combination of fields in the parent table are used to link to the indexed field(s) in the child table. In most cases, the expression used in the linking index and the common linking expression are similar (i.e., the parent and child table are linked on a single field, with identical field names).
Type "N". A numeric value that indicates how referential integrity is to be enforced on the link. The referential integrity parameter can be set to: 0 = no integrity 1 = cascade changes 2 = prevent changes For more information on referential integrity, see "Using the Set Editor" in the User's Guide.
The <TBL>.RELATION_ADD() method establishes a relationship, or link, between two open tables. The link definition determines the nature of this relationship. It is established through the relation function variable, as shown in the syntax diagram above. The <TBL>.RELATION_ADD() method uses the contents of the relation function variable when constructing the link. The parent table of the link is the table referenced by the object pointer, <TBL>, and the child table of the link is the table referenced by the object pointer, <Child_Table> pointer. You can use <TBL>.RELATION_ADD()with two or more open tables to form a set design. You can then save this set as a set definition file using the <TBL>.SET_CREATE() method. When the collection of tables linked by <TBL>.RELATION_ADD()is complete, you can store it in a set definition using the <TBL>.SET_CREATE() method. A set is referenced by the table pointer of the set's primary table.
This script uses the relation add method to find the number of invoices for an individual customer.
dim parent as P dim parent_index as P id = ui_get_text("Count Invoices","For which customer ID? ","C001") if id = "" then end end if parent = table.open("c:\a5\a_sports\customer.dbf") parent_index = parent.index_primary_put("CUST_ID") result = parent.fetch_find(id) if (result < 0) then ui_msg_box("Error", "Customer not found.") end end if child_tbl = table.open("c:\a5\a_sports\inv_head.dbf") relation.link_type = LINK_MANY child_index = child_tbl.index_get("CUST_ID") relation.index_child = child_index relation.order_parent = "CUST_ID" relation.ref_integrity = 0 parent.relation_add(child) ' or parent.relation.change()if the relationship exists but is being changed count = 0 child_tbl.fetch_first() while .NOT. child_tbl.fetch_eof() count = count + 1 child_tbl.fetch_next() end while trace.writeln("Number of invoices for customer: " + ltrimcount?) parent.relation_drop(child) child_tbl.close()