Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.



Read-Only Read-Only Topic
Go
Search
Notify
Tools
"WHERE" vs "IF"
 Login/Join
 
Member
posted
At Summit this year, many of the presentations still had 'IF' statements. It was my understanding - some time ago! - that we should be using 'WHERE' instead of 'IF'.

Can someone explain to me - again! - what the difference is between the two?

Thanks!
 
Posts: 12 | Location: Omaha, NE | Registered: September 12, 2007Report This Post
Expert
posted Hide Post
I haven't used an IF statement for years.

There are several differences, one of which is that an IF statement will allow alpha values without quotes, which I think is sloppy:

TABLE FILE CAR
PRINT
SEG.COUNTRY
SEG.MODEL
IF COUNTRY EQ ENGLAND
END


I'm sure others will tell you why they still use IF statements.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
Tom,

I agree with Francis, here is some documentation from IBI:

quote:

This topic is also covered in IBI Course(s): Course 102

In TABLE, IF tests only recognize OR connectors. A field can't be equal to two different values. Internally, 'AND' is treated as 'OR' in an IF test. For example, the test "IF COUNTRY EQ 'ENGLAND' AND 'FRANCE'" is converted internally to "IF COUNTRY EQ 'ENGLAND' OR 'FRANCE'".

The same is not true of WHERE tests. "WHERE COUNTRY EQ 'ENGLAND' AND 'FRANCE'" will return 0 records. In a WHERE test, 'AND' is used to connect two expressions. Using parenthesis, this expression can be rewritten as WHERE (COUNTRY EQ 'ENGLAND') AND ('FRANCE'). In this example, COUNTRY EQ 'ENGLAND' is the first expression. The second expression, 'FRANCE' is evaluated as "WHERE 'FRANCE' EQ 'TRUE'". The second expression can never be true, so the entire expression WHERE COUNTRY EQ 'ENGLAND' AND 'FRANCE' will never be true. Therefore, zero records will always be returned when using this type of syntax.


By-the-Way, are you from the Univ of Nebraska???

Tom


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Member
posted Hide Post
Thank you for the input!!

Tom, I am not from UNO. I am from Physicians Mutual.

Tom
 
Posts: 12 | Location: Omaha, NE | Registered: September 12, 2007Report This Post
Virtuoso
posted Hide Post
I have only found a single instance where it was better to use an IF instead of WHERE. That is when I was comparing a field to a list of values in an external file, along with many other complex criteria. The syntax is different for an IF vs. WHERE and for whatever reason, I could get IF to work right with multiple complex criteria but WHERE would not. Probably something I was just missing, but in any case the IF worked so I stuck with it. In all other case, I always use WHERE.

As mentioned, IF only seemed to work consistently (or at least what I consider to be consistent) when the criteria were simple. Any compound/complex statements required a WHERE. In most cases, its user preference. I would suggest sticking with WHERE.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
 
Posts: 2298 | Location: Salt Lake City, Utah | Registered: February 02, 2007Report This Post
Master
posted Hide Post
Darin,

Your problem may have been the size of the file you were comparing against. I can't remember the exact limits, but I know that with a WHERE it is very small. The syntax is a little easier with an IF when searching for a value in a file and I agree that it is about the only time I still use IF.


Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
 
Posts: 755 | Location: TX | Registered: September 25, 2007Report This Post
Master
posted Hide Post
I have lots of code where I used IF before WHERE was an option and there used to be a problem where:
WHERE datefield IS MISSING

would not be passed to Oracle and
IF datefield IS MISSING

would be passed, but that has been fixed. The only time I use IF now is when using a list in an external file and the file is larger than 16K. The file can be 32K in size with IF and only about 16K with WHERE.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
 
Posts: 975 | Location: Oklahoma City | Registered: October 27, 2006Report This Post
Virtuoso
posted Hide Post
There is a form of selection test available with IF but not with WHERE:

"IF x IS TRUE", where x is a numeric variable, is treated as "IF x NE 0".

That allows you to express decision logic quite naturally:
DEFINE FILE CAR
 TAKE/I1=(COUNTRY CONTAINS 'Y') 
      OR (CAR CONTAINS 'A');  
END
TABLE FILE CAR
 LIST CAR BY COUNTRY 
 IF TAKE IS TRUE
END


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Virtuoso
posted Hide Post
1. When WHERE was first introduced (way back when), it was because of SQL that had a WHERE clause and, people being what they are, WHERE became a necessary feature.

2. IF is very straightforward: IF field OP value. Nothing else, no field to field comparison, no OR between conditions. In order to do that, one had to create a DEFINE field and use IF on the result.

3. So, when WHERE came along, FOCUS translated it to an IF where possible, otherwise to a DEFINE and IF.

4. With SQL passthru, FOCUS examines the WHERE and if it decides that it is "good" SQL then the WHERE is sent to the database, otherwise FOCUS will do the screening (hence the importance of tracing).

5. With FOCUS files what is described in (3) is, as far as I know, still used.

Old hands at FOCUS, like me, cannot abandon IF so quickly: 2 characters instead of 5! What a savings!


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Virtuoso
posted Hide Post
Danny,

The savings part is not that important. I'm used to lining up my code, so my IF also takes 5 positions.
But, I'm still using the IF statement more than the WHERE, probably because it is what I grew up with. You're right, WHERE used to be translated into a DEFINE, which is being executed after having filtered on the database values, so after any direct IF. Don't know if this is still the case, if it is, using IF where possible might improve performance (a little).


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
 
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007Report This Post
Expert
posted Hide Post
I apologise in advance for this but it's been begging to be written so here it is.

I prefer to use where where possible, although if I were to use if then where would I use if in preference to where and where would I use if? If I were you and where you are then I would probably not worry at all and decide where and if I’d use where or if.

Sorry again Winky

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Virtuoso
posted Hide Post
GamP, it was a joke, of course.

Tony, very nice! No need for apologies.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Silver Member
posted Hide Post
switching to the format:
IF &field EXACTLY &operator &value

allowed our heavily-parameterized reports to work fine even when the user entered special characters such as dollar signs or ampersands. this wasn't possible without a LOT of extra code when using WHERE.


---------------------
WebFOCUS 7.6
 
Posts: 41 | Registered: August 05, 2005Report This Post
Virtuoso
posted Hide Post
Danny,
Of course it was a joke, I saw through that.

Tony - great, could not have thought that one up - I'll keep it and use it if needed where and whenever I can.

Dan, nice thing this EXACTLY option. Didn't know it was there - Thanks!


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
 
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007Report This Post
Virtuoso
posted Hide Post
And another undocumented feature. Of course you can find them in the cases but why aren't they in the MANUAL???


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Expert
posted Hide Post
Careful Danny you're starting to encroach on Francis' domain WinkRazzer

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Member
posted Hide Post
Hello everyone, I am glad this post exists, because it talks to heart of our problem we just discovered. Thanks Dan, your IF &field EXACTLY &operator &value worked perfectly with our issue.

Now to my issue and hopefully your help. We have a lot of parameterized that contain listboxes of codes (Service, Discount, Package Etc..) The codes can be setup using any combination of enterable keyboard characters. We ran across the probem with the + sign and worked around that issue, but the $ sign is a problem. We used Dan's technique, but I was wandering if there is a setting to turn off the masking behavour associated with the $ sign?

For example code 3$: The SQL statment would be WHERE SERV_CDE LIKE '3_ ' instead of WHERE SERV_CDE = '3$' I now understand why this occurs and the other masking behaviours using $ and * together. We can use the IF logic, but it would be simpler if we could turn off the masking behaviour with some type of configuration setting similar to HTMLENCODE.

David


wf: 7.6.4
App. and reporting server: UNIX/AIX 5.3
 
Posts: 20 | Registered: June 01, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic


Copyright © 1996-2020 Information Builders