Focal Point
[SOLVED] Variable listing values for use in multiple WHEREs

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

November 24, 2010, 11:41 AM
Erin2
[SOLVED] Variable listing values for use in multiple WHEREs
Is it possible to use a variable for a list for use in several WHEREs throughout a fex? If so, can somebody help me out with syntax?

Using "WHERE field IN ('value1','value2',...)" works, but if my fex needs to apply this WHERE to 4 tables, changing the values requires changing them in each WHERE line.

Using a FILEDEF with "WHERE field IN file" works also, but having to update/upload a file every time I want to change values is overkill and cumbersome.

Seems to me that it should be possible to define a variable at the top of the fex with whatever values, then just stick that variable in as many WHEREs as I need. But I can't get this to work and I'm not finding any answers in the help docs or existing forum posts.

-* =====A. This works=====
TABLE FILE CAR
SUM CNT.MODEL
BY COUNTRY
WHERE COUNTRY IN ('JAPAN','ITALY');
END
-*
TABLE FILE OTHERTBL
SUM CNT.FOO
BY COUNTRY
WHERE COUNTRY IN ('JAPAN','ITALY');
END

-* =====B. This works=====
FILEDEF CTRYLIST DISK Z:/WHATEVER/CTRYFILE.TXT
TABLE FILE CAR
SUM CNT.MODEL
BY COUNTRY
WHERE COUNTRY IN FILE CTRYLIST;
END
-*
TABLE FILE OTHERTBL
SUM CNT.FOO
BY COUNTRY
WHERE COUNTRY IN FILE CTRYLIST;
END

-* =====C. I want something like this but I can't get it to work=====
-SET &CTRYLIST=('JAPAN','ITALY');
TABLE FILE CAR
SUM CNT.MODEL
WHERE COUNTRY IN &CTRYLIST;
END
-*
TABLE FILE OTHERTBL
SUM CNT.FOO
WHERE COUNTRY IN &CTRYLIST;
END

This message has been edited. Last edited by: Kerry,


WebFOCUS 7.6
Windows, All Outputs
November 24, 2010, 11:53 AM
Francis Mariani
When providing values to Dialogue Manager variables that contain quotes, you need to include more quotes:

-SET &ECHO=ALL;

-SET &CTRYLIST = '(''JAPAN'',''ITALY'')';

TABLE FILE CAR
SUM CNT.MODEL
WHERE COUNTRY IN &CTRYLIST;
END

TABLE FILE OTHERTBL
SUM CNT.FOO
WHERE COUNTRY IN &CTRYLIST;
END
I'm not sure what the term for this is or where it's documented. You may be able to play with QUOTEDSTRING, but my suggestion is the easiest.


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
November 24, 2010, 11:55 AM
Francis Mariani
-SET assigns a literal value, or a value that is computed in an arithmetic or logical expression, to a variable.

Single quotation marks around a literal value are optional unless it contains an embedded blank, comma, or equal sign, in which case you must include them.

The syntax is:

-SET &[&]name= {expression|value};

where:

&name - Is the name of a variable whose value will be set.

expression - Is a valid expression. Expressions can occupy several lines, so end the command with a semicolon.

value - Is a literal value assigned to the variable. If the literal value contains commas or embedded blanks, you must enclose the value in single quotation marks. If the value contains a single quote, place two single quotes where you want one to appear.


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
November 24, 2010, 12:35 PM
Erin2
Thank you! I put in more quotes like you said and it works now!


WebFOCUS 7.6
Windows, All Outputs