Focal Point
MULTISELECTION

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

June 12, 2006, 04:58 PM
Evgenia
MULTISELECTION
Hello everybody,
Please take a look at the following:
 WHERE COMPANY_CODE EQ &COMPANY
-IF &COMPANY0.EXISTS NE 1 THEN GOTO NOMULSELCOM;
-REPEAT NOMULSELCOM FOR &COUNTER FROM 2 TO &COMPANY0;
OR '&COMPANY.&COUNTER'
-NOMULSELCOM


This code is supposed to retrieve values from the select dropdown in both case - when there is only one value passed and when there are more then one company selected. Default for the COMPANY is '$*', which should run report for all companies. And it does not. I get the following error:
 (FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: $
 


I tried to put &COMPANY in quotes
 WHERE COMPANY_CODE EQ '&COMPANY' 

Then I get
 (FOC280) COMPARISON BETWEEN COMPUTATIONAL AND ALPHA VALUES IS NOT ALLOWED
 

COMPANY_CODE is I4 data type.

What am I doing wrong?
Thank you

This message has been edited. Last edited by: Evgenia,
June 12, 2006, 05:36 PM
j.gross
The $* mask works only for character variables.

Skip the test entirely when the user selects 'all'. Assuming that's the topmost option, it would be the first selection:

-IF &COMPANY EQ '$*' GOTO -NOMULSELCOM;
WHERE COMPANY_CODE EQ &COMPANY
-IF &COMPANY0.EXISTS NE 1 THEN GOTO NOMULSELCOM;
-REPEAT NOMULSELCOM FOR &COUNTER FROM 2 TO &COMPANY0;
OR '&COMPANY.&COUNTER'
-NOMULSELCOM


- Jack Gross
WF through 8.1.05
June 12, 2006, 05:55 PM
Evgenia
Thanks, j.g.,
Here is the error message I get:
  -IF $* EQ '$*' GOTO -NOMULSELCOM;
 0 ERROR AT OR NEAR LINE     45  IN PROCEDURE drillordFOCEXEC *
 (FOC281) ALPHA ARGUMENTS IN PLACE WHERE NUMERIC ARE CALLED FOR
 

June 13, 2006, 04:27 AM
venu
Remove '-' after the GOTO statment
-IF &COMPANY EQ '$*' GOTO NOMULSELCOM;
June 13, 2006, 10:18 AM
Evgenia
Thank you very much, j.g. and venu.
It worked.

Evgenia
June 13, 2006, 11:28 AM
Evgenia
OK, it works. But there is a problem with semantics.
Both, for all companies and for a single one the code:
 -IF &COMPANY EQ '$*' GOTO NOMULSELCOM;
WHERE COMPANY_CODE EQ &COMPANY
-IF &COMPANY0.EXISTS NE 1 THEN GOTO NOMULSELCOM;
-REPEAT NOMULSELCOM FOR &COUNTER FROM 2 TO &COMPANY0;
OR '&COMPANY.&COUNTER'
-NOMULSELCOM 


works fine. Here is the echo when single company is selected:
  -IF 001 EQ '$*' GOTO NOMULSELCOM;
 WHERE COMPANY_CODE EQ 001
 -IF NOT 0 THEN GOTO NOMULSELCOM;
 -NOMULSELCOM 


Here &COMPANY has 001 in it.

But then with multiselect the following code where I also test if multiselection exists:
 -IF &COMPANY0.EXISTS THEN GOTO X2;
-TYPE 'COMPANY VALUE IS &COMPANY'
-GOTO SKIPIT3
-X2
-TYPE 'COMPANY0 VALUE EXISTS AND IS &COMPANY0'
-SKIPIT3
-IF &COMPANY EQ '$*' GOTO NOMULSELCOM;
WHERE COMPANY_CODE EQ &COMPANY
-IF NOT &COMPANY0.EXISTS THEN GOTO NOMULSELCOM;
-REPEAT NOMULSELCOM FOR &COUNTER FROM 2 TO &COMPANY0;
OR '&COMPANY.&COUNTER'
-NOMULSELCOM 


produces echo:
   -IF 1 THEN GOTO X2;
 -X2
 -TYPE 'COMPANY0 VALUE EXISTS AND IS 2'
 'COMPANY0 VALUE EXISTS AND IS 2'
-IF $* EQ '$*' GOTO NOMULSELCOM;
 -NOMULSELCOM 


My understanding is that &COMPANY in the case of multiselect retains the default value of '$*' and that is why the loop is not executed.

I tried to trick it with:
 -IF &COMPANY EQ '$*' AND NOT &COMPANY0.EXISTS GOTO NOMULSELCOM;
WHERE COMPANY_CODE EQ &COMPANY
-IF NOT &COMPANY0.EXISTS THEN GOTO NOMULSELCOM;
-REPEAT NOMULSELCOM FOR &COUNTER FROM 2 TO &COMPANY0;
OR '&COMPANY.&COUNTER'
-NOMULSELCOM 


But it comes back with '(FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: $' error.

I thought with multiselect &COMPANY is the same as &COMPANY1???

Does anyone see a way around it?
Thanks,
Evgenia
June 14, 2006, 07:59 AM
venu
If you select more than one item in multiselect list then the amper variable by the name name of the list does not exist when the form is posted.
i.e in your case If you select only one value then &COMPANY exists
If you select more than one value then
&COMPANY0 contains howmany values are selected.
ANd individual values will be &COMPANY1 etc.,
However &COMPANY value does not exists at all.

Your case seems to be like you have defined a default value
-DEFAULTS &COMPANY='$*';

And so when you select more than one value Both parts of the statement
-IF &COMPANY EQ '$*' AND NOT &COMPANY0.EXISTS GOTO NOMULSELCOM;
pass the test and you get to WHERE COMPANY_CODE EQ $*

AS j.g. has mentioned you cannot use $* for numeric field comparisions.
June 14, 2006, 08:06 AM
Tony A
Venu,

Your comments are true only if you are on release 7.1.3 or later (as of 30 May). Prior to release 7 (5.3 etc.) &COMPANY would exist as well.

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 
June 14, 2006, 09:05 AM
venu
Tony, thanks for info. I am on 7.1.3, so now wonder my vision is obscured!!!

Anyhow for the current problem the If clauses should be little refined.

-IF NOT &COMPANY0.EXISTS GOTO SINGLESELECT
-* multi select code here
WHERE COMPANY_CODE EQ &COMPANY1
-REPEAT MULSELCOM FOR &COUNTER FROM 2 TO &COMPANY0;
OR &COMPANY.&COUNTER
-MULSELCOM
-GOTO ENDCLAUSE

-SINGLESELECT
-IF &COMPNAY EQ '$*' THEN GOTO ENDCLAUSE;
WHERE COMPANY_CODE EQ &COMPANY
-ENDCLAUSE
June 14, 2006, 10:06 AM
Tony A
Evgenia,

As it has not been asked, I'll ask it now ....

Why bother using '$*' for all values when there is a perfectly good internal value of 'FOC_NONE' for this situation (depending upon your release of course). The advantage of using 'FOC_NONE' is that WebFOCUS will ignore lines where 'FOC_NONE' is in the selection or a field name ..

e.g.

-SET &ByField = 'FOC_NONE';
TABLE FILE CAR
SUM RCOST
DCOST
BY COUNTRY
BY &ByField
WHERE &ByField EQ 'ENGLAND'
END

will ignore both the BY &ByField and the WHERE clause.

In addition, if, when you create your SELECT, you choose to add the all option, WebFOCUS will insert the value 'FOC_NONE' when the all option is selected and therefore you have less worries.

You could extend the above code to deal with multiple selects as follows :-

-DEFAULT &COMPANY = 'FOC_NONE'
-SET &ByField = 'FOC_NONE';
TABLE FILE CAR
SUM RCOST
DCOST
BY COUNTRY
BY &ByField
-IF &COMPANY EQ 'FOC_NONE' AND NOT(&COMPANY0.EXISTS) GOTO :EndSelect;
-SET &Cnt = IF &COMPANY1.EXISTS THEN '1' ELSE '';
WHERE COUNTRY EQ '&COMPANY&Cnt.EVAL'
-IF &COMPANY0.EXISTS EQ 0 THEN :EndSelect;
-REPEAT :EndSelect FOR &Cnt FROM 2 TO &COMPANY0;
OR '&COMPANY&Cnt.EVAL'
-:EndSelect
END

Substitute the 'FOC_NONE' in the DEFAULT for 'ENGLAND' to see the results.

Hope this has helped.

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 
June 14, 2006, 10:46 AM
Evgenia
Thank you very much, guys.
I did find a way around it. But I definitely will keep your comments in mind.

Tony, I am a beginner at WebFOCUS trying to develop reports consulting already existent code and modifying it. Sometimes I need to write my own piece, but again, I am learning. Now I know a thing or two about FOC_NONE. Thank you.

Thanks,
Evgenia