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.
I'm looking at an existing piece of code here (not mine) trying to figure out how it evaluates...
It contains something along these lines: DEFINE FILE x A/I1 = IF expr1 AND expr2 OR expr3 THEN 1 ELSE 0; END
Does that logical expression evaluate as:
(expr1 AND expr2) OR expr3, or as
expr1 AND (expr2 OR expr3)?
Can you also explain why it evaluates to that one instead of the other?
In the Help I found this list of logical expressions: Creating Reports With Report Painter > Writing Expressions > Writing Logical Expressions
But it doesn't say in what order they get evaluated or what their precedence is.This message has been edited. Last edited by: Wep5622,
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010 : Member of User Group Benelux :
Okay, thanks. That would mean that OR has precedence over AND.
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010 : Member of User Group Benelux :
Of course, you could also try to create a small procedure to check the precedence, like:
DEFINE FILE CAR
A/A1 = IF COUNTRY EQ 'ENGLAND' AND CAR EQ 'TRIUMPH' OR BODYTYPE EQ 'COUPE' THEN 'A' ELSE ' ';
B/A1 = IF (COUNTRY EQ 'ENGLAND' AND CAR EQ 'TRIUMPH') OR BODYTYPE EQ 'COUPE' THEN 'B' ELSE ' ';
C/A1 = IF COUNTRY EQ 'ENGLAND' AND (CAR EQ 'TRIUMPH' OR BODYTYPE EQ 'COUPE') THEN 'C' ELSE ' ';
END
TABLE FILE CAR
PRINT COUNTRY CAR BODYTYPE A B C
END
and then see what happens...
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
Posts: 1961 | Location: Netherlands | Registered: September 25, 2007
I couldn't come up with a simple reliable test-case, my brain is currently too numb with a lot of DIY-work at home after my day-job...
An extra benefit is of course that this is now documented in Google.
The results are:
COUNTRY CAR BODYTYPE A B C
------- --- -------- - - -
ENGLAND JAGUAR CONVERTIBLE
ENGLAND JAGUAR SEDAN
ENGLAND JENSEN SEDAN
ENGLAND TRIUMPH HARDTOP A B C
JAPAN DATSUN SEDAN
JAPAN TOYOTA SEDAN
ITALY ALFA ROMEO SEDAN
ITALY ALFA ROMEO COUPE A B
ITALY ALFA ROMEO ROADSTER
ITALY MASERATI COUPE A B
W GERMANY AUDI SEDAN
W GERMANY BMW SEDAN
W GERMANY BMW SEDAN
W GERMANY BMW SEDAN
W GERMANY BMW SEDAN
W GERMANY BMW SEDAN
W GERMANY BMW SEDAN
FRANCE PEUGEOT SEDAN
From which the conclusion can be drawn that AND takes precedence over OR, as implementations 'A' and 'B' behave the same.
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010 : Member of User Group Benelux :
Assuming WF uses the same precendence as the other languages, ...
The headwaters of FOCUS expression semantics lie in FORTRAN. (And Dialog Manager syntax is rooted in VM's EXEC I, but that's another discussion).
Just to eliminate the possibility that FOCUS gives AND and OR equal precedence, combining the terms in lexical order (a la APL, my eldest son's first computer language):
DEFINE FILE CAR A/A1 = IF (COUNTRY EQ 'ENGLAND') AND (CAR EQ 'TRIUMPH') OR (BODYTYPE EQ 'COUPE') THEN 'A' ELSE ' '; a/A1 = IF (BODYTYPE EQ 'COUPE') OR (CAR EQ 'TRIUMPH') AND (COUNTRY EQ 'ENGLAND') THEN 'a' ELSE ' '; B/A1 = IF (COUNTRY EQ 'ENGLAND' AND CAR EQ 'TRIUMPH') OR BODYTYPE EQ 'COUPE' THEN 'B' ELSE ' '; C/A1 = IF COUNTRY EQ 'ENGLAND' AND (CAR EQ 'TRIUMPH' OR BODYTYPE EQ 'COUPE') THEN 'C' ELSE ' '; END TABLE FILE CAR PRINT COUNTRY CAR BODYTYPE A a B C END
a is seen as equivalent to A, so the equivalence to B is (indeed) based on precedence rather than lexical order
- Jack Gross WF through 8.1.05
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005
I knew there was more to it! Thanks for confirming that.
WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010 : Member of User Group Benelux :
Obligitory posting that it is always best practice to use brackets to group items so they are are forced to eval as intended versus relying on the interpreter to do the needful.
Or, as your coworker: Make this easy so I don't have to think about it.