I’m having trouble joining two hold files together. The problem lies in that the unique identifier I want to join on is a composite of two fields, for example’s sake, let’s call them EmpNumber and Company. EmpNumber is unique within a Company, but multiple companies can have the same EmpNumber. So, here’s a brief and oversimplified version of what I’ve got to do:
TABLE FILE TABLEA PRINT Customer EmpNumber DATAA ON TABLE SET PAGE-NUM OFF ON TABLE NOTOTAL ON TABLE HOLD AS HOLDA FORMAT FOCUS INDEX EmpNumber Customer END
TABLE FILE TABLEB PRINT Customer EmpNumber DATAB ON TABLE SET PAGE-NUM OFF ON TABLE NOTOTAL ON TABLE HOLD AS HOLDA FORMAT FOCUS INDEX EmpNumber Customer END
JOIN LEFT_OUTER FILE HOLDA AT HOLDA.SEG01.EmpNumber TO UNIQUE FILE HOLDB AT HOLDB.SEG01.EmpNumber TAG J0 AS J0 END
ON TABLE SET BYDISPLAY ON ON TABLE PCHOLD FORMAT HTML ON TABLE NOTOTAL ON TABLE SET PAGE-NUM OFF ON TABLE SET HTMLCSS ON END
What I'm having a hard time doing is making the join be on both EmpNumber and Client. From reading the documentation, it suggests that one can AND join fields together. So, I've tried the equivalent of:
JOIN LEFT_OUTER FILE HOLDA AT HOLDA.SEG01.EmpNumber AND HOLDA.SEG01.Customer TO UNIQUE FILE HOLDB AT HOLDB.SEG01.EmpNumber AND HOLDB.SEG01.Customer TAG J0 AS J0 END
But it just errors out. Has anyone else out there been in a similar situation and come up with a good solution? Ideas would be appreciated... I have tried a "Where" based join, but it runs at least 20 times slower, so that's not really an option.
Version 7.6.10 Windows 7 Pro all output
January 19, 2011, 06:54 PM
Waz
You are using a conditional join.
To do equality tests, you will have to add WHERE host field EQ join field ; before the END of the join.
You can have multiple WHERE clauses in conditiona join, each one on a separate lina dn ending ina ;.
What is the error message you are getting ?
Waz...
Prod:
WebFOCUS 7.6.10/8.1.04
Upgrade:
WebFOCUS 8.2.07
OS:
Linux
Outputs:
HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!
January 20, 2011, 04:18 AM
Alan B
When joining FOCUS files, the host does not need to have an INDEX, only the x-referenced file. Also a join to a FOCUS file can only be to ONE field, unlike SQL based data. The host file can use up to 4 fields (I think) to JOIN to the x-referenced file. The following is roughly what I think you are after. (Being old school I prefer the old style join syntax...)
TABLE FILE TABLEA
PRINT
Customer
EmpNumber
DATAA
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
ON TABLE HOLD AS HOLDA FORMAT FOCUS
END
TABLE FILE TABLEB
PRINT
DATAB
COMPUTE LINK/Ann = Customer | EmpNumber;
BY Customer
BY EmpNumber
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
ON TABLE HOLD AS HOLDB FORMAT FOCUS INDEX LINK
END
JOIN
Customer and EmpNumber IN HOLDA TAG A
TO LINK IN HOLDB TAG B AS J0
END
TABLE FILE HOLDA
PRINT
A.Customer
A.EmpNumber
A.DATAA
B.DATAB
ON TABLE SET BYDISPLAY ON
ON TABLE PCHOLD FORMAT HTML
ON TABLE NOTOTAL
ON TABLE SET PAGE-NUM OFF
ON TABLE SET HTMLCSS ON
END
Alan. WF 7.705/8.007
January 20, 2011, 07:34 AM
GamP
Another method, which I also sometimes use, is:
JOIN
Customer IN HOLDA TAG A
TO ALL Customer IN HOLDB TAG B AS J0
END
TABLE FILE HOLDA
PRINT
A.Customer
A.EmpNumber
A.DATAA
B.DATAB
WHERE A.EmpNumber EQ B.EmpNumber;
END
In this case you have to have the ALL (1-n relation) in the join, the WHERE will filter out unequal records.
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
January 20, 2011, 10:00 AM
Byrnsy
Thanks everyone for the suggestions. The error was related to the rule Alan mentioned that FOCUS won't allow joins on 2 fields. I've done a lot of SQL, so I guess I took that for granted... Anyways, taking that option off the table, I've used the input to craft a solution that works for me (all 3 suggestions do in fact work). In the report(s) I've actually got, I've got a few more hold files involved. Also, Customer and EmpNumber are both whole numbers, and the max allowable value on Customer is 99999. Since most systems are most efficient at comparing numbers, I've tried this approach:
TABLE FILE TABLEA PRINT Customer EmpNumber DATAA COMPUTE CliEmp/P26 = (EmpNumber * 100000) + Customer; NOPRINT ON TABLE SET PAGE-NUM OFF ON TABLE NOTOTAL ON TABLE HOLD AS HOLDA FORMAT FOCUS INDEX CliEmp END
TABLE FILE TABLEB PRINT Customer EmpNumber DATAB COMPUTE CliEmp/P26 = (EmpNumber * 100000) + Customer; NOPRINT ON TABLE SET PAGE-NUM OFF ON TABLE NOTOTAL ON TABLE HOLD AS HOLDA FORMAT FOCUS INDEX CliEmp END
JOIN LEFT_OUTER HOLDA.SEG01.CliEmp IN HOLDA TO UNIQUE HOLDB.SEG01.CliEmp IN HOLDB TAG J0 AS J0 END
ON TABLE SET BYDISPLAY ON ON TABLE PCHOLD FORMAT HTML ON TABLE NOTOTAL ON TABLE SET PAGE-NUM OFF ON TABLE SET HTMLCSS ON END
I've still got to run it through the performance analyzer, and I'll compare the results with the other 3 approaches suggested to find the one that will scale best for me.
Again, thanks everyone for putting me on the path to solving this. Your input, as always, is invaluable.This message has been edited. Last edited by: Byrnsy,