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.
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, 2007
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.
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, 2007
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, 2007
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, 2006
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, 2006
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, 2007
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
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, 2004
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.
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.