sant123
12th March 2003, 20:58
I have an input ascii file with the part no and a 60char long text(String) seperated by a delimiter, I have written a session to load the Item Text in Baan, I am not sure that is the optimal way of doing it, hence I need some inputs. The steps are as follows:

Read the input Ascii file,
( format Item1~someString
Item1~someString1
Item3~somestring2
........etc
)

Open a tempfile for write

Read each input line and write the text string to the temp file, after all the text lines are written for an Item use text.write() function to write the Baan Text and commit.

For text.write there has to be an input file, Is there anything else I can do to avoid this file processing, or Is there anyother way of loading text to Baan ( apart from Baan Exchange).

Appreciate any help.

KDrysch
13th March 2003, 16:12
We just recently converted onto Baan Vc and we used Exchange to load text. That was the only option available other than writing your own program (as you did).

pandy1909
3rd October 2003, 13:36
I have to update my Item text from an ascii file with data say as follows:

Item Code ~ Line1Text~Line2Text~Line3Text
Item Code1 ~ Line1Text~Line2Text
Item Code2 ~ Line1Text~Line2Text~Line3Text~Line4Text
........

Going through this and other posts, i intend to try the following:

1. Read the seq file.
1a. while not eof

create a temporary file

|* tempfile.name = creat.tmp.file$(bse.tmp.dir$())
|* tempfile.seq = seq.open(tempfile.name,"w")

{
2. write each text between the separating charector as a text line
to a temporary file (basically i intend to read the each line char by char, till i encounter the ~ sign and then upto the point, write the buffer.
(Q. If anyone knows a better method of reading a file , where fields are delimeted by a char, please advise)
}

|* e = seq.puts(tmp_buf,80,tempfile.seq)
|* seq.close(tempfile.seq)

3.now update the item text with the temp created text file in step 2

|* rc = text.write("tiitm001.txta","lang","","","","","","",tempfile.name)


Do you think this would work? Will it create the text with as many lines as there are in text file ?

I do not want to use exchange.

thanks for you help

SP

NvanBeest
3rd October 2003, 15:15
Should work OK. Just one change in step 3:if tiitm001.txta = 0 then
text.write(...)
else
text.rewrite(...)
endif
As for the number of lines, the function text.write will write the whole file to the text field, regardless of the number of lines. Parsing into lines can be done better as well:function long parse(string inputstr(1024), string seperator(1), long outfile)
{
string linestr(80)
long numlines

numlines = 0
while (len(inputstr) > 0)
linestr = inputstr(1;pos(inputstr, seperator) - 1)
inputstr = inputstr(pos(inputstr, seperator) + 1;1024)
if numlines = 0 then
| This is the item number
numlines = numlines + 1
else
seq.puts(linestr, outfile)
numlines = numlines + 1
endif
endwhile

return(numlines)
}

NvanBeest
3rd October 2003, 15:20
Oops! Forgot something. The text.(re)write functions creates or updates the text, but not the item table. Thus, the first piece of code should be:

db.retry.point()
item = inputstr(1;pos(inputstr, "~") - 1)
select tiitm001.*
from tiitm001 for update
where tiitm001.item = :item
selectdo
if parse(inputstr, "~") > 0 then
if tiitm001.txta = 0 then
text.write(...)
else
text.rewrite(...)
endif
db.update(ttiitm001, db.retry)
endif
endselect
commit.transaction()