Article ID: 155749
Article Last Modified on 9/30/2003
tcParentTable ncount
tcParentTable=ALIAS(tcParentWkArea)
ncount=OCCURS('+',tcFieldName)+1
FOR i = 1 TO ncount
DO CASE
CASE i = 1 && First occurrence of "+"
REPLACE (SUBSTR(tcFieldName,i,AT("+",tcFieldName,i)-1));
WITH EVAL(tcParentTable+'.'+;
SUBSTR(tcFieldName,i,AT("+",tcFieldName,i)-1))
CASE i = ncount && Last occurrence of "+"
REPLACE (SUBSTR(tcFieldName,AT('+',tcFieldName,ncount-1)+1)) ;
WITH EVAL(tcParentTable+'.'+ ;
SUBSTR(tcFieldName,AT('+',tcFieldName,ncount-1)+1))
OTHERWISE && Any number of occurrences of + in between.
REPLACE (SUBSTR(tcFieldName,AT('+',tcFieldName,(i-1))+1, ;
((AT('+',tcFieldName,i)-AT('+',tcFieldName,(i-1)))-1))) ;
WITH EVAL(tcParentTable+'.'+SUBSTR(tcFieldName, ;
AT('+',tcFieldName,(i-1))+1,((AT('+',tcFieldName,i)- ;
AT('+',tcFieldName,(i-1)))-1)))
ENDCASE
NEXT i
The above code works with any number of columns in a compound key.
CREATE DATABASE test
CREATE TABLE xparent (half1 c(3), half2 c(3), other c(5))
ALTER TABLE xparent ADD PRIMARY KEY half1+half2 TAG pkey
CREATE TABLE xchild (half1 c(3), half2 c(3), other c(5), ;
FOREIGN KEY half1+half2 TAG fkey REFERENCES xparent )
CLOSE TABLES ALL
USE xparent
INSERT INTO xparent (half1, half2, other) VALUES ('aaa','111','a1')
INSERT INTO xparent (half1, half2, other) VALUES ('bbb','222','b2')
INSERT INTO xparent (half1, half2, other) VALUES ('ccc','333','c3')
USE xchild
INSERT INTO xchild (half1, half2, other) VALUES ('aaa','111','a1')
INSERT INTO xchild (half1, half2, other) VALUES ('bbb','222','b1')
INSERT INTO xchild (half1, half2, other) VALUES ('ccc','333','c1')
INSERT INTO xchild (half1, half2, other) VALUES ('bbb','222','b2')
INSERT INTO xchild (half1, half2, other) VALUES ('aaa','111','a2')
INSERT INTO xchild (half1, half2, other) VALUES ('aaa','111','a3')
MODIFY DATA NOWAIT
Keywords: kbbug kbfix kbvfp500fix KB155749