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 = ""
}

vinceco252
7th February 2011, 22:28
You might want to look at the client2server function. This copies a file from the client to the server, then you can process the file locally using the seq.gets function. If you do a search on client2server you should get quite a few results.

Thanks,

Vince

SandraDiehl
8th February 2011, 17:36
Yes after I posted the question and doing more research I went ahead and used the client2server function and removed the file from the server after I did the processing.

Now here is another need; When I do the processing I use an application called Toad and I create a backup of the Item Master before I do the mass price changes. If the end users are going to execute now, is there a way in the program to back up the Item Master before the processing?

In Toad I use the command to create the table:

create table ttiitm001_420_20110208_1028 as select * from ttiitm001420;

and once the process is done and I have confirmation I use this command to delete the table:

drop table ttiitm001_420_20110208_1028;

NPRao
8th February 2011, 23:40
Now here is another need; When I do the processing I use an application called Toad and I create a backup of the Item Master before I do the mass price changes. If the end users are going to execute now, is there a way in the program to back up the Item Master before the processing?
You can use the Baan's bdbpre to back up the table data.
drop table ttiitm001_420_20110208_1028;
You can also use the db.drop.table() Tools function in your script.
This way you do not have to do things manually and the program handles it. Why do you like to take the backup of the table?