On Mon, Sep 8, 2014 at 2:01 PM, Bill Godfrey <[email protected]> wrote:
> On Mon, 8 Sep 2014 09:08:47 -0500, John McKown <[email protected]> 
> wrote:
>>
>>Possible REXX program:
>>
>>/* rexx */
>>data=''
>>CRLF='0D25'X
>>do forever
>>   "execio 1 diskr sysut1"
>>   if rc <> 0 then leave
>>   parse pull record
>>   data=data||record
>>   i=pos(CRLF,data)
>>   do while i <> 0;
>>      output=left(data,i-1);
>>      queue output
>>      "execio 1 diskw sysut2"
>>      data=substr(data,i+2)
>>      i=pos(CRLF,data)
>>   end
>>end
>>i=pos(CRLF,data)
>>do while i <> 0;
>>   output=left(data,i-1);
>>   queue output
>>   "execio 1 diskw sysut2"
>>   data=substr(data,i+2)
>>   i=pos(CRLF,data)
>>end
>>"execio 0 diskr sysut1(finis"
>>"execio 0 diskw sysut2(finis"
>>
>
> You know REXX better than I do - I couldn't have written this in such a short 
> time. But is it not possible that in rare cases the original data might have 
> been split into separate records right between the '0D'X and the '25'X, in 
> which case this would produce problematic results? Just wanted to mention it.
>

Sure that can happen. No, it is not a problem. Why? Because if the
variable "data" ends with a x'0d', the code will NOT split it. If will
be in the "left over" portion of data. And the line: data=data||record
will put the contents of the _next_ record immediately _after_ any
"left overs". Which will be what is wanted because the x'25' which
starts the next record will then be right after the x'oD' left over at
the end of "data". And the next go though of the DO WHILE will then
use that to split the data. It's hard to show, but assume that ^
stands for x'0D' and ~ stands for x'25'. Suppose the data in the file
looks like:

abc^~def^
~ghi^~qr^b^~

The code will read abc^~def^ into record. Concatenate to data, which
is initially ''. So this results in output being abc (and written out)
and data being def^. It reads again & concatenates. result is
def^~ghi^qr~b , DO WHILE will split this into def and ghi^~qr~b,
output def, then loop. 2nd time through, split is ghi and qr~b. Output
ghi. data now qr^br^~ which has a ^~ and so loop 3rd time, output
qr^b, leaving data ''. No ^` in data, so exit DO WHILE. continue DO
FOREVER. EXECIO failes because of EOF, so exit DO FOREVER. execute
second DO WHILE but nothing output because data is still ''. Hum, the
code does have a bug. If the data in the input file does not exit with
x'0D25', the last record will not be written.

> Bill



-- 
There is nothing more pleasant than traveling and meeting new people!
Genghis Khan

Maranatha! <><
John McKown

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to