Focal Point
FOCUS 7.2.3 Looping Question

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

November 08, 2004, 05:04 PM
cbm
FOCUS 7.2.3 Looping Question
I have an external data set. I'm using a "READ" function to read the first position, which I am using as an indicator to branch to various parts of the focus program. I am also using the &LINES variable to route to the end if there are no records in the data file as well as to compare a "COUNTER" variable to. I have an "-IF" section that analyzes the value of the indicator and then routes it to the appropriate section...or it should. It works fine for the first record, but how and what is the syntax to get this to occur for every record? I thought perhaps I could use the "REPEAT" function, but not having used it before has me somewhat confused with how and where it should be placed in relation to my "IF" statements. The final result should be a series of hold files that will later be appended. Any thoughts would be most appreciated. Thnx in advance!
November 08, 2004, 06:01 PM
susannah
make sure you use NOCLOSE
-READ filename NOCLOSE &myvar.a80
that means that when you branch back to the top of your loop, you won't be re-reading the first record .
Then, if you already know how many times you're going to be looping, you can use REPEAT.
The syntax is REPEAT statementlabel n TIMES
-SET &KOUNTER = 0;
-REPEAT MYENDLABEL 10 TIMES
-SET &KOUNTER = &KOUNTER + 1;
-READ MYFILE NOCLOSE &MYVAR.A80... whatever
-IF &IORETURN NE 0 GOTO IMOUTOFHERE ;
...do stuff with that &myvar, your IFs can go here. You can have whole wads of focus code here, if you need to.
-MYENDLABEL
-IMOUTOFHERE
optionally, you can put your kounter check in,
perhaps right after you increment it.
but if you're real sure of your loop , you don't need it.
(I use K for Kounter rather than C because i'm a math geek and we use I, J, K for integer incrementers.)

oh, &LINES isn't going to do anything for you here. What you want to check for is &IORETURN
After each read, issue a check on &IORETURN to see if you're at endof file. (EOF=&IORETURN NE 0)
November 09, 2004, 10:52 AM
cbm
Thnx so much Susannah...I'll give it a try!
-carolyn