Focal Point
Loop --reading a value

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

May 18, 2005, 04:12 PM
<delvegas>
Loop --reading a value
Hi guys

Is there a way to read data from a single column

like I have a Table X1 which contains 4 rows of data like
Field1
A
B
C
D
under a sigle field1.

what i need is to read the data from each row at a time. and store it in &variable and type.

Field Data is dynamic. ie:- it can contain 10 or 50 Rows of data.

Thanks
May 18, 2005, 10:44 PM
dwf
Something like this:

DEFINE FILE X1
X/A1 WITH FIELD1 = 'X';
END
TABLE FILE X1
PRINT FIELD1 X
ON TABLE SAVE
END
-RUN

-REPEAT READLOOP FOR &NDX FROM 1 TO 1000
-READ SAVE &FIELD&NDX.EVAL.A20.

-IF &IORETURN NE 0 THEN GOTO EOF;
-TYPE &FIELD&NDX.EVAL
-GOTO READLOOP

-EOF
-SET &DUMMY = 1000;

-READLOOP
-? &


Notes:

I assumed a format of A20 for FIELD1.

The -RUN after the TABLE FILE is essential.

If you don't print X, then the records you create will be of variable length (unless the text in FIELD1 is always the same number of characters, or numbers). If the first record in SAVE is, for example only 15 characters wide, and you read it into a variable 20 characters wide (.A20.), FOCUS will grab the first 5 characters of the of the second record. The second time you encounter -READ, FOCUS will read the third record, not the second record. The X at the end (in the 21st position) assures that this will not happen.

The 1000 in the REPEAT loop is arbitrary. Pick a number that is greater than the number of records you will EVER print from X1.

It is &IORETURN that tells you when you are done reading the file. YOu could simply jump to some point outside the REPEAT loop, but I have quaint preference for completing the loop.

The -GOTO READLOOP takes you to the end of the loop. When FOCUS encoutners -READLOOP, it returns back to the top of the loop.

The -? & at the end will display your variables and their values.
May 20, 2005, 08:23 AM
<JG>
Change
-REPEAT READLOOP FOR &NDX FROM 1 TO 1000
to
-SET &LOOP=&RECORDS;
-REPEAT READLOOP FOR &NDX FROM 1 TO &LOOP

This will perform the loop the exact number of times and you can then delete the following lines of code
-IF &IORETURN NE 0 THEN GOTO EOF;
-GOTO READLOOP
-EOF
-SET &DUMMY = 1000;


By the way -SET &DUMMY = 1000; should be -SET &NDX = 1000;

Also to force a fixed length file all you need to do is filedef the file as follows before the request
FILEDEF SAVE DISK SAVE.FTM (LRECL 20 RECFM F
-RUN

This will allow you to remove the define and field x from the request
May 22, 2005, 04:08 AM
TexasStingray
delvegas,

What are you trying to do with the variable(s)? WebFOCUS has a lot of powerful features that can be used to help you complete your task and there may be a better way to accomplish the task you are trying to complete. Cool