Focal Point
Creating a Variable for LOOP counting from a Table File command

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

November 18, 2004, 01:46 AM
<AUSSIE_SEAGULL>
Creating a Variable for LOOP counting from a Table File command
Does anyone have sample code that can create a variable to be used to set the number of times a LOOP will execute based on the result of a count of records, eg:

DEFINE FILE TABLE1
COUNT/I3 = 1;
END

TABLE FILE TABLE1
SUM COUNT
ON TABLE HOLD AS XYZ
END
-RUN

and use the value of the count to set the variable that controls the number of times a sunsequent LOOP will run further down the code?

All suggestions welcome !
November 18, 2004, 03:02 AM
<Pietro De Santis>
DEFINE FILE CAR
COUNT/I3 = 1;
END

TABLE FILE CAR
SUM COUNT
CAR NOPRINT
ON TABLE HOLD AS XYZ FORMAT ALPHA
END
-RUN

-READ XYZ &ZCOUNT.I3.
-TYPE &ZCOUNT

-REPEAT END_LOOP1 FOR &I FROM 1 TO &ZCOUNT

-TYPE COUNT IS &I

-END_LOOP1
November 18, 2004, 09:29 PM
reFOCUSing
&LINES or &RECORDS could work for you. They are variables that are created by FOCUS after every table call which contains the number of row in the data set (&LINES) and how many lines was read from the database (&RECORDS).
November 19, 2004, 02:10 AM
susannah
g'day, i use &LINES.
TABLE FILE CAR
BY MODEL
ON TABLE HOLD
END
-RUN
-SET &NUMCARS = &LINES ;
-REPEAT MYENDLOOP &NUMCARS TIMES
TABLE FILE somethingelse
...do stuff
END
-RUN
-MYENDLOOP
-**** or use explicit kounter
-SET &KOUNTER = 0;
-MYTOPLOOP
-SET &KOUNTER = &KOUNTER + 1;
TABLE FILE something
..do stuff
END
-RUN
-IF &KOUNTER LT &NUMCARS GOTO MYTOPLOOP;
-*you're allright now
November 23, 2004, 10:09 PM
<AUSSIE_SEAGULL>
Thanks all for your suggestions, I have only checked the posts now (been up to the eyeballs in work!) I'll leave the subject open and let you know how I go .

Thanks again ....
November 26, 2004, 02:13 AM
<AUSSIE_SEAGULL>
Susannah your suggestion has worked a treat, thank you very much, I have solved not just the coding issue but provided a tool to really boost productivity in a few key business areas I deal with.
November 26, 2004, 06:15 AM
susannah
great to know. Congratulations.
Take a look at Pietro's suggestion...its slightly different, and also very important technique that will give you alot more ideas...You can not only count how many somethings there are...you can actually make a list of them, read them 1 at a time, and loop with an actual value of variable, not just a loop kounter.
Be sure and come to Tech Summit in May in LasVegas and pick up lots more great ideas from everyone!