APPX Software Library

Files, Streams and Other Software

What is the proper usage of --- STREAM READ LENGTH field?

I have a job that takes a tab-delimited file and reformats it to an appxio file. The STREAM READ only returns a valid record the first time, subsequent reads return varying data.

My simple subroutine looks like this:

SET      --- STREAM OPEN TYPE           =      r
SET      --- STREAM READ LENGTH         =
GOSUB    --- STREAM OPEN
SET      --- STREAM EOR SEQUENCE        =      LF
IF       --- STREAM RETURN CODE         NE     0
*
*        read tab file record
LABEL    :NEXT RECORD
TRAP
GOSUB    --- STREAM READ
IF       --- STREAM RETURN CODE         EQ     0
IF       --- STREAM BUFFER              EQ
GOTO     :NEXT RECORD

The field --- STREAM READ LENGTH is used for two things. If set to a value other than zero the READ subroutine will limit the data bytes it reads to no more than that many bytes. What gets you is that your READ routine also uses that field to tell you how many bytes it actually did read. So, the first time you call it the value was zero, it read in number of bytes (if you count the tab bytes) up to the linefeed and set that number of bytes into this field. Since you didn't reset it to zero that value carried forward to the next read. It read that number of bytes and stopped leaving the rest<lf> unread. The next time you called read it read the remaining number of bytes up to the linefeed and set the length to that number. And so on.....

So, you need to set this field to zero before each read attempt.