Focal Point
Using OR in IF THEN ELSE

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

June 27, 2007, 11:42 AM
KK
Using OR in IF THEN ELSE
Can we do something like this using IF

If &TEST EQ '1' or '2' or '3' then "Red"
ELSE If &TEST EQ '4' or '5' or '6' then "Yellow"

Thank you


Test - Webfocus 7.6.7
Prod - Webfocus 7.6.7
Win2003
Sql Server 2000 and 2008
June 27, 2007, 12:18 PM
Leah
quote:
If &TEST EQ '1' or '2' or '3' then "Red"
ELSE If &TEST EQ '4' or '5' or '6' then "Yellow"

Thank you



Do it all the time in defines, what are you trying to do? ((of course or is OR) sorry couldn't resist).


Leah
June 27, 2007, 12:54 PM
Darin Lee
and it doesn't hurt to use parentheses to clarify. I've found that sometimes WF likes it better as well.


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
June 27, 2007, 01:15 PM
KK
Leah,

It worked, there was a syntax error.

Darin,

I will try to do that.

Thanks much.


Test - Webfocus 7.6.7
Prod - Webfocus 7.6.7
Win2003
Sql Server 2000 and 2008
June 28, 2007, 03:28 AM
Alan B
If this is a DEFINE/COMPUTE, the syntax would be:
fld/A10 = IF '&TEST' EQ '1' OR '2' OR '3' THEN 'Red'
     ELSE IF '&TEST' EQ '4' or '5' or '6' THEN 'Yellow' 
     ELSE 'defaultValue';

And because I am not a fan of 'lazy' OR processing, another approach:
fld/A10 = IF '1,2,3' CONTAINS '&TEST' THEN 'Red'
     ELSE IF '4,5,6' CONTAINS '&TEST' THEN 'Yellow' 
     ELSE 'defaultValue';

If it is DM,
-SET &fld = IF &TEST EQ '1' OR '2' OR '3' THEN 'Red'
-      ELSE IF &TEST EQ '4' or '5' or '6' THEN 'Yellow' 
-      ELSE 'defaultValue';

or
-SET &fld = IF '1,2,3' CONTAINS &TEST THEN 'Red'
-      ELSE IF '4,5,6' CONTAINS &TEST THEN 'Yellow' 
-      ELSE 'defaultValue';

or
-SET &fld = DECODE &TEST(1 Red 2 Red 3 Red 4 Yellow 5 Yellow 6 Yellow ELSE default);

Always supplying a value if the tests fail, the last ELSE.


Alan.
WF 7.705/8.007
June 29, 2007, 11:39 AM
KK
Alan,

quote:
Always supplying a value if the tests fail, the last ELSE


I did this mistake and figured out later.

Just curious, are there any advantages of decode vs IF ?

Thank you for the syntax.

KK


Test - Webfocus 7.6.7
Prod - Webfocus 7.6.7
Win2003
Sql Server 2000 and 2008
July 02, 2007, 09:11 AM
jgelona
Since DECODE is essentially a nested IF...THEN...ELSE statement, you can test a lot more values with DECODE. Nested IF used to have a limit of 16 but I think is higher now. DECODE has the option of using a file with a size limit of 32K (which might be higher now), which depending of the size of the data, allows the testing of hundreds of values. Back in early day of PC FOCUS where memory usage could be critical, if I remember correctly, DECODE uses less memory than nested IF statements.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.