July 25, 2005, 08:59 PM
pruittlr-Repeat question
I'm using WF 5.33 on Windows 2000.
I have a -READ within a loop (-REPEAT). I need the repeat to loop until the end of file on the read. Is there a way to loop until &IORETURN NE 0? I haven't been able to make that work, keep getting an error. Got any ideas? Thanks.
Raelene
July 25, 2005, 09:22 PM
susannahmake sure you -READ filename NOCLOSE
otherwise that sucker just reads the same record over and over and...
then &IORETURN will at some point NE 0
July 25, 2005, 09:34 PM
pruittlrI have the NOCLOSE on the read. The -REPEAT requires number of times, or a while condition, or a from-to value. I just want it to repeat until eof.
July 26, 2005, 09:01 AM
Tony ATry this syntax which reads ahead (age old data processing requirement
) and set &IORETURN immediately after your -READ thereby trapping and EOF situation.
TABLE FILE CAR
PRINT MODEL
ON TABLE HOLD AS CALENDAR FORMAT ALPHA
END
-RUN
-* Read ahead to prime the &IORETURN
-READ CALENDAR, NOCLOSE &Model
-REPEAT Read_It WHILE (&IORETURN EQ 0)
-TYPE Model is &Model
-READ CALENDAR, NOCLOSE &Model
-Read_It
END
July 26, 2005, 09:09 AM
HÃ¥kanTry this:
APP FI TEST lidholh/test.txt
-RUN
-*
-WRITE TEST Record 1
-WRITE TEST Record 2
-WRITE TEST Record 3
-WRITE TEST Record 4
-WRITE TEST Record 5
-RUN
-*
-SET &IORETURN = 0;
-REPEAT :end_read WHILE &IORETURN EQ 0;
-READ TEST,&LINE
-IF &IORETURN NE 0 GOTO :end_read;
-TYPE &IORETURN &LINE
-:end_read
It will give you the following output:
0 Record 1
0 Record 2
0 Record 3
0 Record 4
0 Record 5
July 26, 2005, 01:20 PM
pruittlrThanks, H Lidholm, it worked. My syntax was similar, guess I was missing something.