Focal Point
[SOLVED] SET Variable Inside REPEAT - Not Working Properly

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

January 31, 2011, 03:37 AM
Ramkumar - Webfous
[SOLVED] SET Variable Inside REPEAT - Not Working Properly
Hi,

I am trying to execute the following code.

&SEL_A0 is the count of &SEL_A'N' s present.

-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';

-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A&COUNTER;
-END_REP

-TYPE &TOKENVAL

My Expected output is #10#11#97#99


But It is expecting a value for &SEL_A .

&SEL_A&COUNTER is eveluvated togather to form &SEL_A1, &SEL_A2, &SEL_A3 etc.

Is there any simple way to do this ?

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


Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
January 31, 2011, 03:44 AM
Tony A
quote:
-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A&COUNTER.EVAL;
-END_REP

That should get you further forward.

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 
January 31, 2011, 04:12 AM
Alan B
Or, as the syntax for indexed variables says:

-SET &name.&index[.&index...] = expression;

The '.' is the missing bit.
[Tony. you know I avoid .EVAL like the plague Wink]


Alan.
WF 7.705/8.007
January 31, 2011, 04:27 AM
Tony A
quote:
you know I avoid .EVAL like the plague ]

... and you have been plague free of recent years Wink

Except that neither of our responses actually take it forward Frowner too early?

T

This message has been edited. Last edited by: Tony A,



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 
January 31, 2011, 04:31 AM
Ramkumar - Webfous
  
-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';

-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.&COUNTER;
-END_REP

-TYPE &TOKENVAL




Hi Tony / Alan,

Thanks for your replies.

I tried both the suggestions. But, still It is expecting a value for &SEL_A .

What I need is to form the &VAR's name dynamically along with the counter...

Eg. &SEL_A1, &SEL_A2 like that...


But what I get is




Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
January 31, 2011, 04:39 AM
Tony A
Firstly, you need your -REPEAT terminated by a semicolon (doc'd syntax) and then -

-SET &ECHO=ALL;
-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';

-REPEAT END_REP FOR &Cnt FROM 1 TO &SEL_A0.EVAL;
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A&Cnt.EVAL;
-END_REP

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 
January 31, 2011, 05:02 AM
Alan B
-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';

-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.&COUNTER;
-END_REP

-TYPE &TOKENVAL


works perfectly for me. Using .EVAL still prompts.

-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';
-REPEAT END_REP FOR COUNTER FROM 1 TO 4
-SET &TOKENVAL = || '#' || 10;
-REPEAT END_REP FOR COUNTER FROM 1 TO 4
-SET &TOKENVAL = #10 || '#' || 11;
-REPEAT END_REP FOR COUNTER FROM 1 TO 4
-SET &TOKENVAL = #10#11 || '#' || 97;
-REPEAT END_REP FOR COUNTER FROM 1 TO 4
-SET &TOKENVAL = #10#11#97 || '#' || 99;
-REPEAT END_REP FOR COUNTER FROM 1 TO 4
-END_REP
-TYPE #10#11#97#99
#10#11#97#99


If the index variable doesn't work, i.e.
-SET &ECHO=ALL;
-SET &SEL_A0 = 4;
-*SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';

-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.&COUNTER;
-END_REP

-TYPE &TOKENVAL

results in:
-SET &SEL_A0 = 4;
 -*SET &SEL_A1 = 10;
 -SET &SEL_A2 = 11;
 -SET &SEL_A3 = 97;
 -SET &SEL_A4 = 99;
 -SET &TOKENVAL = '';
 -REPEAT END_REP FOR  COUNTER FROM 1 TO 4
 0 ERROR AT OR NEAR LINE     10  IN PROCEDURE ADHOCRQ FOCEXEC *
 (FOC295) A VALUE IS MISSING FOR: &SEL_A1



This is because parameter prompting is a pre-parser and does not see &SEL_A1. This is not seen until the process actually runs. For neither does parameter prompting come in to play.

(pressed POST too early…)

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
January 31, 2011, 05:19 AM
Alan B
Interesting.
-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';

-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.&COUNTER.EVAL;
-END_REP

-TYPE &TOKENVAL
causes parameter prompting.


Alan.
WF 7.705/8.007
January 31, 2011, 05:55 AM
j.gross
quote:
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.&COUNTER.EVAL;
-END_REP
...causes parameter prompting


Why? Simple:

After the EVALuation, you are left (on the first round) with:

-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.1;

Since "1" is not a reference to a variable, the syntax for indexing is not satisfied, and the "." just indicates catenation, to be performed after &SEL_A is evaluated.

Since &SEL_A is undefined, you get prompted.


- Jack Gross
WF through 8.1.05
January 31, 2011, 08:58 AM
Ramkumar - Webfous
Hi All,

Thanks for the Reply.

As said, .EVAL played it... It worked.

But Still,

Alan,

It is bit more Interesting that, In 7.6.9 It worked perfect, and in 7.1.4 This is is making a user prompt. Still... Donno Y.. ? Wink


Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
February 01, 2011, 04:47 AM
OPALTOSH
If you had used a -RUN after your -SETs your original would have worked fine (apart from the missing '.') because it would have forced the evaluation of the SETs before starting the REPEAT loop. Much simpler than .EVAL

-SET &SEL_A0 = 4;
-SET &SEL_A1 = 10;
-SET &SEL_A2 = 11;
-SET &SEL_A3 = 97;
-SET &SEL_A4 = 99;
-SET &TOKENVAL = '';
-RUN
-REPEAT END_REP FOR &COUNTER FROM 1 TO &SEL_A0
-SET &TOKENVAL = &TOKENVAL || '#' || &SEL_A.&COUNTER;
-END_REP

-TYPE &TOKENVAL
February 01, 2011, 06:04 AM
j.gross
-RUN
adds nothing for variables that are already set by -SET.


I suggest you play by the book.

Indexing, using the construct "&base.&index", is documented.

But "&base&index.EVAL", or even "&base.&index.EVAL", is not documented as a means to reference "indexed" variables, and its semantic interpretation may vary with the release.
February 01, 2011, 09:11 AM
Ramkumar - Webfous
hi Opaltosh/J.Gross,

It works fine in 769 with and without RUN.

But in 7.1.4 still doing a user prompt.


Thanks,

Ramkumar.
WebFOCUS/Tableau
Webfocus 8 / 7.7.02
Unix, Windows
HTML/PDF/EXCEL/AHTML/XML/HTML5
February 01, 2011, 10:05 AM
GamP
I take it it is still asking for the &SEL_A variable?
If so, since you're not really using that variable, try to do a -SET &SEL_A = ''; in the very top of your fex. That way the var is known and no prompting will take place. And then hope the rest of the fex still works ...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988