Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linear Join using three files; two files twice

Status
Not open for further replies.

oceannative

Programmer
Oct 7, 2005
92
US
Referencing thread243-1197791

I have three files that I need to join. J0 and J1 work. However, J2 and J3 (children of J0 and J1) do not... they retrieve the same data.

From Group:
FILEA.SM$FCOM/SM$FGP + FILEB.CWCO/CW$FL# + FILEC.IMLITM = ABC
To Group:
FILEA.SM$TCOM/SM$TGP + FILEB.CWCO/CW$FL# + FILEC.IMLITM = DEF

This is the join generated using the JOIN tool:
Code:
JOIN
 FILEA.FILEA.SM$FCOM AND FILEA.FILEA.SM$FGP IN FILEA TO MULTIPLE
 FILEB.FILEB.CWCO AND FILEB.FILEB.CW$FL# IN FILEB AS J0
 END
JOIN
 FILEA.FILEA.SM$TCO AND FILEA.FILEA.SM$TGP IN FILEA TO MULTIPLE
 FILEB.FILEB.CWCO AND FILEB.FILEB.CW$FL# IN FILEB AS J1
 END
JOIN
 FILEB.FILEB.CWLITM IN FILEA TO UNIQUE FILEC.FILEC.IMLITM IN FILEC AS J2
 END
JOIN
 FILEB.FILEB.CWLITM IN FILEA TO UNIQUE FILEC.FILEC.IMLITM IN FILEC AS J3
 END
 
When you say that the JOINs don't work because you get the same data, it may be because you have the SAME file in the structure TWICE. Since both instances have the same filename, segment name and fieldname, unless you qualify the fields differently, you'll always get one of them. The safest way to qualify a JOIN is through the use of a TAG name. This allows you to EXPLICITLY name each of the repeated structures, effectively replacing the FILENAME with the TAG name.
Here's the JOIN syntax:
Code:
JOIN 
[LEFT_OUTER|INNER] hfld1 [AND hfld2 ...] IN hostfile [TAG tag1]     
TO [UNIQUE|MULTIPLE] crfield [AND crfld2 ...] IN crfile [TAG tag2] [AS joinname]
END

Where TAG is defined as:

TAG tag1

Is a tag name of up to eight characters (usually the name of the Master File), which is used as a unique qualifier for fields and aliases in the host file.

TAG tag2

Is a tag name of up to eight characters (usually the name of the Master File), which is used as a unique qualifier for fields and aliases in cross-referenced files. In a recursive join structure, if no tag name is provided, all field names and aliases are prefixed with the first four characters of the join name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top