ltannous
2nd July 2003, 20:55
I am trying to upload a file from our UNIX server to a baan table using a session update script. I can get the file into baan, but there are end of line characters messing up the data entry.

The first line inserted is blank
The second line inserted has a unrecognized charachter at the end.(end of line, then a new line character)

The file is created in Unix by ls * > listing.txt


before.program:

path = "/apps/baan/bse/edi/logs/listing.txt"

functions:

function read.main.table()
{
db.retry.point()

select wtedi011.*
from wtedi011 for update
selectdo
fp = seq.open(path,"rt")

if fp < 1 then
message("Error, cannot open file")
endif
if fp >= 1 then
while seq.EOF(fp) = 0
seq.read(reln,18,fp)
wtedi011.reln = reln

db.insert(twtedi011, db.retry)
| endif
| endif

endwhile
endif
seq.close(fp)
commit.transaction()
endselect

}

NPRao
2nd July 2003, 21:08
Change your code to -

fp = seq.open(fname, "r")
if fp < 0 then
mess("zmadms0010", 1)
|* File Handling Errors
return
endif
while not seq.gets(buffer, 1024, fp)
do.something()
endwhile


Refer to the link - seq.gets() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_directory_file_operations_seq_gets)

You can choose different mode options -

mode
Use this optional argument to specify the read mode for seq.gets(). Possible values are:

GETS_NORMAL


The function continues reading characters until either the buffer (line) is full, a new line character is read, or EOF is reached.

If the buffer is full, any remaining characters on the line being read are discarded.

This is the default mode.


GETS_ALL_CHARS
The function continues reading characters until either the buffer (line) is full, a new line character is read, or EOF is reached.

If the buffer is full, the next seq.gets() call starts reading at the point where the current seq.gets() finished. The use of this mode ensures that all characters available in input file are eventually returned.


GETS_SKIP_ALL
This is the same as GETS_NORMAL, except that if the last line in the file does not end with a new line character, that line is discarded completely and EOF is returned.

there.was.more
When characters are discarded in GETS_NORMAL or GETS_SKIP_ALL mode, or when more characters are available in the line (but the buffer is full) in GETS_ALL_CHARS mode, this argument is set to 1. Otherwise, the argument returns 0.

ltannous
2nd July 2003, 22:35
I had 5 lines in the file,only the second line got loaded?
I made the following changes:


before.program:

path = "/apps/baan/bse/edi/logs/listing.txt"

functions:

function read.main.table()
{
db.retry.point()
string buffer(256)


fp = seq.open(path, "rt")

if fp < 0 then
message("Error, cannot open file")

return
endif


while not seq.gets(buffer, 1024, fp)
select wtedi011.*
from wtedi011 for update
selectdo
seq.gets(reln,18,fp)
wtedi011.reln = reln
db.insert(twtedi011, db.retry)

endselect
seq.close(fp)
endwhile
commit.transaction()

}

NvanBeest
2nd July 2003, 22:43
You're reading two lines in the first iteration, and then closing it before the next iteration!

while not seq.gets(buffer, 1024, fp) | read first line
select wtedi011.*
from wtedi011 for update
selectdo
seq.gets(reln,18,fp) | read second line
wtedi011.reln = reln
db.insert(twtedi011, db.retry)
endselect
seq.close(fp) | close the file
endwhile

Change it to:

while not seq.gets(buffer, 1024, fp)
select wtedi011.*
from wtedi011 for update
selectdo
wtedi011.reln = buffer(1;18)
db.insert(twtedi011, db.retry)
endselect
endwhile
seq.close(fp)

ltannous
2nd July 2003, 23:38
It worked with some minor tweeking.

ltannous
4th July 2003, 17:27
I can upload the file to a table, but only if the table has at least one record in it.

I need to send a db.clear.table first, and then load the table from a file.
Why can't I load the data if the table is empty?

choice.cont.process:
on.choice:
clear.table()
read.main.table()
remove.file()

|****************************** function section ****

before.program:

path = "/apps/baan/bse/edi/logs/listing.txt"

functions:

function read.main.table()
{
db.retry.point()
string buffer(256)


fp = seq.open(path, "rt")

if fp < 0 then
message("Error, cannot open file")

return
endif
select wtedi011.*
from wtedi011 for update
selectdo

while not seq.gets(buffer, 1024, fp)

wtedi011.reln = buffer(1;17)
db.insert(twtedi011, db.retry)

commit.transaction()
endwhile
endselect
seq.close(fp)


seq.close(fp)

message("Files Update")
}

function remove.file()

{

file.rm("/apps/baan/bse/edi/logs/listing.txt")


}


function clear.table()

{
db.clear.table(twtedi011,0,210)

}

NvanBeest
4th July 2003, 17:32
The reason is that the enclosing select statement returns "false".

Change the code to:


db.clear.table(...)
select ...
where ...
selectdo
selectempty
while ...
endwhile
endselect