Focal Point
[SOLVED] Compare value in one TABLE FILE against value in another Table File

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2187036296

February 17, 2020, 06:46 PM
Brandon Andrathy
[SOLVED] Compare value in one TABLE FILE against value in another Table File
Hello,

I'm currently trying to look up a value in my second table file and compare it to another value in my first hold file. In the example below, I'm using the CAR file however this request is going through a ton of records. I am using WHERE DB_INFILE with a SQL script to narrow down the records and that's working great.

I want to try to find the most efficient way to compare "MPG" in the first table against "ACCEL" in the second table. I've been thinking DBLOOKUP might be a good command here but I haven't been able to get it to work. Is that more efficient then just doing a join? To get a sense of what I'm trying to do, I entered a field called "FLAG" which has the general logic I'd like to get working.

Does anyone have any ideas of what the best approach is here?

 TABLE FILE CAR
BY COUNTRY
BY LOWEST MPG
WHERE DEALER_COST LE 9000
ON TABLE HOLD AS 'TEST' FORMAT SQL_SCRIPT
END
?FF TEST

TABLE FILE CAR
SUM
	DEALER_COST
BY COUNTRY
BY ACCEL
BY TOTAL COMPUTE FLAG/A5 = IF TEST.MPG GE ACCEL THEN 'Y' ELSE 'N''
WHERE DB_INFILE(TEST, COUNTRY, COUNTRY)
END
?FF TEST2
-RUN
 


Thanks in advance!!

This message has been edited. Last edited by: Brandon Andrathy,


WebFOCUS 8204
February 18, 2020, 06:54 AM
MartinY
There is probably no "good" answer to the question : most efficient way
I would say that the answer will strongly depend on type of data source and volume of data to proceed.

If you encounter a lack of performance, you will probably need to test several options and keep the one with best result.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
February 18, 2020, 08:05 AM
Brandon Andrathy
Hey Martin,

Thank you for your response. I got a join working how I’d like and performance is ok. Do you have an idea of other things could work here?

Would DB Lookup work? I tried doing that and got a server error. Assuming I’m doing something wrong. Is the below example correct or so I need to do something different?

 TABLE FILE CAR
BY COUNTRY
BY LOWEST MPG
WHERE DEALER_COST LE 9000
ON TABLE HOLD AS 'TEST' FORMAT SQL_SCRIPT
END
?FF TEST

TABLE FILE CAR
SUM
	DEALER_COST
BY COUNTRY
BY ACCEL
BY TOTAL COMPUTE FLAG/A5 = DB_LOOKUP(TEST, COUNTRY, COUNTRY, MPG);
WHERE DB_INFILE(TEST, COUNTRY, COUNTRY)
END
?FF TEST2
-RUN  



WebFOCUS 8204
February 18, 2020, 11:55 AM
Frans
I'd prefer lookup instead of join in such cases because join can mess up data (null values with inner join or carthesian product with non unique key)

Here your example to lookup MPG:
 
TABLE FILE CAR
BY COUNTRY
BY LOWEST 1 MPG
WHERE DEALER_COST LE 9000
ON TABLE HOLD AS TEST FORMAT TAB
END

TABLE FILE CAR
SUM
	DEALER_COST
BY COUNTRY
BY ACCEL
BY TOTAL COMPUTE FLAG/D5 = DB_LOOKUP(TEST, COUNTRY, COUNTRY, MPG);
WHERE DB_INFILE(TEST, COUNTRY, COUNTRY)
END
?FF TEST2
-RUN   



Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
February 18, 2020, 12:35 PM
Brandon Andrathy
Hey Frans, thank you for your response. Do you have any idea why with DB_LOOKUP, causes the server to crash or for the report not to run?

Is it something with the type of data I am using?

The CAR example works great but then when I try to use it with an actual data source, I get an error.


WebFOCUS 8204
February 18, 2020, 02:42 PM
Frans
Yeah in your example the flag had a decimal value (MPG) The result of the DB_LOOKUP needs to match the definition of the COMPUTE. I also added the 1 with lowest to make sure it's unique, however that should not matter for a DB_LOOKUP.

How big is the first table you are doing the lookup on? Is it a temporary table or do you lookup on a database table? And is it realy a crash, or do you see some kind of error code?


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
February 19, 2020, 01:36 PM
Donna Guadagno
How about using the MATCH command:

MATCH FILE CAR
SUM RETAIL_COST
BY COUNTRY
BY LOWEST MPG
WHERE...
RUN
FILE CAR
SUM DEALER_COST
BY COUNTRY
BY ACCEL AS MPG
WHERE...
AFTER MATCH HOLD OLD-OR-NEW
END
-RUN
TABLE FILE HOLD
PRINT *
WHERE...
END

It will automatically combine the two files using the BY fields and any that match will appear on the same line. OLD-OR-NEW will give you all of the results whether or not they match. OLD-AND-NEW will give you the intersection of the two files. There are the other variations like OLD is only the records in the first file and those that match from the second file. NEW is the opposite of OLD, etc, etc.


FOCUS 7.68, OpenVMS
WebFOCUS 7.7.03
February 19, 2020, 02:03 PM
Brandon Andrathy
Hey Frans, thank you very much for your response. When I try to do DB_LOOKUP with real data, I get "Request Terminated

"Reporting server request may have crashed, or was halted by the operator with a "hard kill"

Please investigate reporting server log."

Is this a known issue/something with an easy fix?


WebFOCUS 8204
February 20, 2020, 12:40 PM
Brandon Andrathy
I found out what my problem was. The format of the fields between the two tables wasn't the same. Additionally, DB_LOOKUP can't be converted to SQL apparently. I had my first file as a FORMAT SQL_SCRIPT.

Can anyone explain why DB_LOOKUP can't be converted to SQL?


WebFOCUS 8204
February 20, 2020, 03:55 PM
Brandon Andrathy
I was able to get this to work good enough for my purposes. Thanks all for the help!


WebFOCUS 8204