SandraDiehl
7th February 2011, 21:27
I have a session I had developed that will update the item purchase and sales price based on an imput file that uses | as the separator. I have used the seq.open, seq.gets and string.scan to read the file and do the update on the item master. This all works great. BUT now I want for end users to be able to execute the application that won't require for them to have access to the server to place the input file, have the application read a local file directory.
I have found using the seq.open.local will open the file, using the seq.read.local reads the file, but it reads the entire file into the buffer. So when I attemp to use the string.scan it only gets the first line, have no clue how to read the buff for each record until EOF.
From what I have read so far I don't think I can mix the seq.open.local with the seq.gets, but if that isn't the case please tell me so and I will be able to use my old method to read and process the records.
Original Logic:
directory = "\\" & strip$(inp.path) & "\" & strip$(inp.file)
in.fp = seq.open(directory, "r+")
if in.fp <= 0 then
message("Error opening file")
else
read.main.table()
endif
function read.main.table()
{
scr.mess = ""
scr.mess = ("Processing input items")
display("scr.mess")
repeat
ret = seq.gets(buf, 200, in.fp)
ret = string.scan(buf, "%s|%s|%f",buf.item, buf.dsca, buf.prip)
align.data()
process.records()
scr.item = align.item
display("scr.item")
until seq.eof(in.fp)
commit.transaction()
}
New Version:
directory = trim$(inp.path) & "\" & trim$(inp.file)
in.fp = seq.open.local(directory, "r", 0)
if in.fp <= 0 then
message("Error opening file")
else
read.main.table()
endif
function read.main.table()
{
scr.mess = "Reporting items to process"
display("scr.mess")
repeat
ret = seq.read.local(buf, size, in.fp)
ret = string.scan(buf, "%s|%s|%f",buf.item, buf.dsca, buf.prip)
align.data()
validate.records()
rpt.item = buf.item
new.prip = buf.prip
if errors then
rpt.line = 2
else
rpt.line = 1
endif
rprt_send()
until seq.eof(in.fp)
scr.mess = ""
}
I have found using the seq.open.local will open the file, using the seq.read.local reads the file, but it reads the entire file into the buffer. So when I attemp to use the string.scan it only gets the first line, have no clue how to read the buff for each record until EOF.
From what I have read so far I don't think I can mix the seq.open.local with the seq.gets, but if that isn't the case please tell me so and I will be able to use my old method to read and process the records.
Original Logic:
directory = "\\" & strip$(inp.path) & "\" & strip$(inp.file)
in.fp = seq.open(directory, "r+")
if in.fp <= 0 then
message("Error opening file")
else
read.main.table()
endif
function read.main.table()
{
scr.mess = ""
scr.mess = ("Processing input items")
display("scr.mess")
repeat
ret = seq.gets(buf, 200, in.fp)
ret = string.scan(buf, "%s|%s|%f",buf.item, buf.dsca, buf.prip)
align.data()
process.records()
scr.item = align.item
display("scr.item")
until seq.eof(in.fp)
commit.transaction()
}
New Version:
directory = trim$(inp.path) & "\" & trim$(inp.file)
in.fp = seq.open.local(directory, "r", 0)
if in.fp <= 0 then
message("Error opening file")
else
read.main.table()
endif
function read.main.table()
{
scr.mess = "Reporting items to process"
display("scr.mess")
repeat
ret = seq.read.local(buf, size, in.fp)
ret = string.scan(buf, "%s|%s|%f",buf.item, buf.dsca, buf.prip)
align.data()
validate.records()
rpt.item = buf.item
new.prip = buf.prip
if errors then
rpt.line = 2
else
rpt.line = 1
endif
rprt_send()
until seq.eof(in.fp)
scr.mess = ""
}