[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: Function returns a FLOAT
Amy,
Depending on the output length you can replace the '^' with
carriage-return/linefeeds and write the new string as one record... they
will appear as multiple records in your output... if the output (after
replacing the '^' with CRLF) exceeds 32767 bytes you need to parse the
output individually and write eah record... below is an example that
determines which method to use... the sample works like a charm - I
didn't encounter the FLOAT problem you mentioned...
NOTE: The CTR-Func (returns number of occurances of '^' in the record)
and the REPL-Func (replaces each '^' with CRLF) can be found in my
custom SQR function library TDFUNC.SQC which can be found on my site -
http://www.sqrtools.com... many potential solutions to questions posted
on SQRUG can be found there...
...
open $I_file as #I_no for-reading record=32767:vary status=#I_stat
open $O_file as #O_no for-writing record=32767:vary status=#O_stat
...
let $crlf = chr(13) || chr(10)
while 1 = 1
read #I_no into $rec:32767
if #end-file = 1
break
end-if
let #len = length($rec) ! Set Record Length
do CTR-Func($rec, '^', #ctr) ! Count number of occurances
let #out = #len + #ctr ! Calculate Buffer Length
show ' Input: ' #len
show ' Count: ' #ctr
show 'Output: ' #out
! Method 1 - Replace '^' with CRLF then write record if <= 32767
if #out <= 32767
let $method = '1'
do REPL-Func($rec, '^', $crlf, $big)
write #O_no from $big
else
! Method 2 - Parse Individual Chunks and Write
let $method = '2'
! Force '^' at end of record if needed
if substr($rec, #len, 1) <> '^'
let $rec = $rec || '^'
end-if
let #ptr = 1
let #end = 1
while #end > 0
let #end = instr($rec, '^', #ptr)
if #end > 0
let #len = #end - #ptr
if #len > 0
let $chunk = substr($rec, #ptr, #len)
write #O_no from $chunk
end-if
let #ptr = #end + 1
end-if
end-while
end-if
display ' '
show 'Method: ' $method
display ' '
end-while
close #I_no
close #O_no
end-procedure
!**********************************************************************
!* Include Members: *
!**********************************************************************
#Include 'tdfunc.sqc' !Custom SQR Function Library
...
Regards,
Tony DeLia
http://www.sqrtools.com
> I have a file I am trying to read that is 1 long line. The length of > this
>line will vary all the time. It is actually a 210 file. I > wanted
> to read the file and write a new file with a new row for each > identifier.
>The end of each new identifier row has a carrot - '^'. I
> tried using the FIND or INSTR function but both of these functions > died
>after I got to the 1000th position because they return a
> FLOAT. Is there any other function I can try or do you have any >
>suggestions? My file I am trying to read is usually over 20000
> characters in length. I tried the declare-variable but it didn't do >
>anything for me. Below is my code. Any help is greatly
> appreciated.
>
> While #count <> 0
>
> let #end_pos = instr($CHR-Data,'^',#start_pos)
>! FIND '^' IN $CHR-Data #start_pos #end_pos
> let #start_pos = #end_pos + 1
>
> write 2 from $Line_Data
>
> If #end_pos = 0
> let #count = 0
> end-if
> end-while
>
>Amy Sablatura
>281/490-9546
>asablatura@imperialsugar.com
--
Tony DeLia
AnswerThink Consulting Group
PeopleSoft Solutions Practice - Delphi Partners
tdelia@erols.com
http://www.sqrtools.com