Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Compare value in one TABLE FILE against value in another Table File
Go
New
Search
Notify
Tools
Reply
  
[SOLVED] Compare value in one TABLE FILE against value in another Table File
 Login/Join
 
Platinum Member
posted
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
 
Posts: 106 | Registered: July 10, 2018Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 2298 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 106 | Registered: July 10, 2018Reply With QuoteReport This Post
Guru
posted Hide Post
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.
 
Posts: 423 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 106 | Registered: July 10, 2018Reply With QuoteReport This Post
Guru
posted Hide Post
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.
 
Posts: 423 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Member
posted Hide Post
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
 
Posts: 8 | Registered: February 15, 2010Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 106 | Registered: July 10, 2018Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 106 | Registered: July 10, 2018Reply With QuoteReport This Post
Platinum Member
posted Hide Post
I was able to get this to work good enough for my purposes. Thanks all for the help!


WebFOCUS 8204
 
Posts: 106 | Registered: July 10, 2018Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Compare value in one TABLE FILE against value in another Table File

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.