Focal Point
[SOLVED] If statement with an in condition

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

January 06, 2014, 10:37 AM
Daniel G
[SOLVED] If statement with an in condition
Can you use the IN condition with an if statement?

 -SET &FOUND_VALUE = IF &VALUE IN ('01a','01b') THEN 1 ELSE 0;
 


Thanks,

Daniel

This message has been edited. Last edited by: <Kathryn Henning>,


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
January 06, 2014, 11:42 AM
Wep5622
I don't think so.

You can however do this:
-SET &FOUND_VALUE = IF &VALUE EQ '01a' OR '01b' THEN 1 ELSE 0;



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 :
January 06, 2014, 11:52 AM
Daniel G
I don't think the if or statement will help me. I have a variable that is equal to '01a' and I need to see if it is in a string that is equal to '01a OR 01b OR 02'.

Daniel


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
January 06, 2014, 11:53 AM
Daniel G
'01a OR 01b OR 02' is dynamic and will change it is not a set variable.


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
January 06, 2014, 12:05 PM
susannah
quote:
I have a variable that is equal to '01a' and I need to see if it is in a string that is equal to '01a OR 01b OR 02'.

If that is your question, then that is def NOT what your code is asking.
Reread your code carefully.
and use .QUOTEDSTRING b/c you're just freaking me out w/o it.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
January 06, 2014, 12:28 PM
Daniel G
Sorry for freaking you out. What does .QUOTEDSTRING do? I know its a newbie question but I am new to webfocus.


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
January 06, 2014, 12:33 PM
Daniel G
quote:
.QUOTEDSTRING
worked thank you so much.


In Focus since 2012
WebFOCUS 8.0.07
Windows, All Outputs
January 06, 2014, 01:25 PM
susannah
.QUOTEDSTRING does just what it sounds like
it puts a temporary set of quotes around the string, doesn't change the string, just for purposes of the command being executed.

it tells the command (among other things) that this is a parameter we're testing, not a name of some variable.
really critical in a drilldown, eg.
its just good practice




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
January 06, 2014, 01:44 PM
j.gross
Try this:
-SET &FOUND_VALUE = &MyLittleList CONTAINS '01a';



- Jack Gross
WF through 8.1.05
January 07, 2014, 03:56 AM
Wep5622
I think a small warning about .QUOTEDSTRING is in order here; don't just blindly apply that everywhere.

For starters, if you use that in a variable substitution in a FOCUS WHERE-clause (ie. WHERE MYFIELD EQ &MYVARIABLE.QUOTEDSTRINGWink, the variable-value FOC_NONE (meaning "ignore this line") gets transformed into the string 'FOC_NONE' and treated as a value from then on (the above then reads WHERE MYFIELD EQ 'FOC_NONE') - the line is no longer ignored. Most likely that will cause your TABLE-request to return no rows.

There are good uses for .QUOTEDSTRING, but it can lead to surprising (unwanted) results. Personally, I usually limit usage of .QUOTEDSTRING to drilldown definitions, which is FOCUS code where you may actually want the value FOC_NONE to be passed on to the next procedure. But even there, it's possibly better to leave that to a -DEFAULT in the next procedure and let the FOC_NONE value cause the line with the relevant parameter to be ignored.

With regards to using .QUOTEDSTRING in dialog manager code - what's the point? DM treats everything as strings already anyway, adding .QUOTEDSTRING does nothing there. There are exceptions of course, usually when you need to add explicit quoting or to escape quotes within the string value.

My advice: Don't use .QUOTEDSTRING unless you actually need it. That's opposite of what Susannah advices, I know Wink


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 :
January 07, 2014, 10:20 AM
Dave
I agree with Wep. ( Hi, Wep ! )

We used to do this:

Get the values...
Then add a ' at the beginning and at the end. And replace all , with ' OR '

or when the values already are quoted also replace all ' with ''

Effectively turning 01a,01b into ''01a' OR '01b''

Or even better...

Did you get the values from HTML?
In that case use a TEXTAREA instead of a INPUT. This will open the possibility to switch on the "multiple" option. And the 'add quotes' option.

This will allow the end-user to either enter:

01a,02b

or

01a;02b

or even

01a
02b

G'luck,
Dave


_____________________
WF: 8.0.0.9 > going 8.2.0.5