Focal Point
Loop while changing a variable each iteration

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

June 19, 2006, 04:26 PM
jcs1226
Loop while changing a variable each iteration
I want to run the same code multiple times but change a variable within the code each time it is run.
I am thinking focus could read a list of variables (numbers), run the code using the first variable in the list, output the file for that variable, set the variable using the second on the list, run the code using this variable for the second iteration, output, repeat multiple times. Anyone got suggestions on the code?


WebFocus 7.6.6 Win 2K
June 19, 2006, 07:18 PM
wf1998
create a array with the list of variables
EX:
Array name LST: LST1, LST2, LST3 ..LST.N
LST0 = NO. OF variables in the array.

use the -REPEAT command.

-REPEAT LSTLP01 FOR LCTR FROM 1 TO &LST0;
-SET LIST = &LST.&LCTR;

TABLE FILE CAR
PRINT
-* print fields

ON TABLE HOLD AS &LIST
END
-LSTLP01




Env Prod:WebFOCUS 7702 ,Windows xp on 64, SQL Server 2008, IRF Tool
Env 1 Local: DevStudio 7702 - MS Windows XP SP2 - Apache Tomcat 5.0.28
Output: HTML, Excel and PDF
June 20, 2006, 06:46 AM
<JG>
A simple NOCLOSE on the READ is all you need

TABLE FILE CAR
BY COUNTRY
ON TABLE HOLD AS COUNTRIES FORMAT ALPHA
END
-RUN
-SET &LOOPS=&LINES;
-REPEAT ENDREPEAT &LOOPS TIMES
-READ COUNTRIES NOCLOSE &COUNTRY.A10.
TABLE FILE CAR
PRINT MODEL
BY COUNTRY
WHERE COUNTRY EQ '&COUNTRY'
END
-ENDREPEAT
June 20, 2006, 09:05 AM
Leah
Out of curiosity, what is the purpose of your report, to generate separate reports each time or a report that needs multiple selection that doesn't fit a normal from-to selection.

To those who submitted answers, thanks for the education. -read is one of the verbs I've not had a lot of education on.


Leah
June 20, 2006, 09:20 AM
jcs1226
Thanks for all the replies. I will try these today.
My hope it to generate a report on each iteration (generate seperate reports each time).
In a nutshell I want to run the same code, only replacing the doctor number (&DOCNUM) on each iteration. So the outputs would be a report for each doctor number that I have on a list.


WebFocus 7.6.6 Win 2K
June 20, 2006, 02:23 PM
jcs1226
JG,
Thanks for the help! This works great.
The only problem I am running into now is that the file name is the same. So it does not output a different excel file for each iteration. It only outputs one at the end that is using the last PCDOCNUM.
I am able to get it to stack all the information in HTML format but unable to get it to ouput a seperate excel file (with different names) for each PCDOCNUM. Any suggestions?


WebFocus 7.6.6 Win 2K
June 20, 2006, 04:10 PM
JimRice
Try this. It should create three different spreadsheets with country being a part of the name.

TABLE FILE CAR
BY COUNTRY
WHERE COUNTRY IN ('ENGLAND', 'FRANCE', 'JAPAN')
ON TABLE HOLD AS COUNTRIES FORMAT ALPHA
END
-RUN
-*
-SET &LOOPS=&LINES;
-SET &P_COUNTRY=' ';
-*
-REPEAT ENDREPEAT &LOOPS TIMES
-READ COUNTRIES NOCLOSE &P_COUNTRY
-SET &NEW_FILE = 'CAR_FILE_' || &P_COUNTRY || '.XLS';
FILEDEF NEWFILE DISK &NEW_FILE
TABLE FILE CAR
PRINT MODEL
BY COUNTRY
WHERE COUNTRY EQ '&P_COUNTRY'
ON TABLE HOLD AS NEWFILE FORMAT EXL2K
END
-ENDREPEAT

Jim


WF DevStu 5.2.6/WF Srv 5.2.4/Win NT 5.2
June 20, 2006, 05:03 PM
jcs1226
Thank you Jim!! Worked exactly as needed.


WebFocus 7.6.6 Win 2K