SandraDiehl
6th February 2012, 22:00
NOTE: our environment is windows not UNIX and this company having issues uses notepad rather than the baan text editor.

I have this custom program that reads input from a file, and is suppose to read the routing table based on the routing item and operation then update the routing text or create a routing text adding the last value from the input file.
I have performed this in both companies where one uses the BaaN text editor and the one that uses notepad. The company that uses BaaN text editor seems to be fine, the company that uses notepad I have ran into some quirky stuff

This company has two text groups that is being used:
small (2, 3, 31 x 23)
standard (2, 3, 80 x 23)

Observation of issue:
I have starting text that will be two lines, after I run my update that is adding a single line such "Required Tooling: JFF1234" and I will end up with a text file that has more than 3 lines, some I find has more than 1600 lines with them all being blank.

I need to see if there is something wrong with my code that I am not seeing, or is this an issue within BaaN using windows/notepad? Any suggestion would be helpful.

Source code:

function process.notes()
{
domain tcmcs.str6 buf.cprj
domain tcitem temp.item

repeat
ret = seq.gets(buf, 200, in.fp)
ret = string.scan(buf, "%s|%d|%s|%s", buf.mitm, buf.opno, buf.sitm, buf.cust)
ret = tt.align.according.domain(buf.sitm, align.sitm, "tcitem")
if buf.cust = "Y" then
buf.cprj = buf.mitm(1;6)
temp.item = buf.mitm(8;16)
ret = tt.align.according.domain(temp.item, align.mitm, "tcitem")
ret = tt.align.according.domain(buf.cprj, align.cprj, "tccprj")
update.cus.routing.notes()
else
ret = tt.align.according.domain(buf.mitm, align.mitm, "tcitem")
update.std.routing.notes()
endif

until seq.eof(in.fp)
}

function update.std.routing.notes()
{
string text.buffer(60, 900)
string temp.file.name(100)
string temp.text.line(4096)
string tgroup(8)
string edit_opt(15)
long temp.file.numb
long text.buffer.lines
long curr.line

db.retry.point()

select tirou102.*
from tirou102 for update
where tirou102._index1 = {:align.mitm}
and tirou102.opno = :buf.opno
selectdo
ret = text.to.buf("tirou102.txta", "2", 900, text.buffer)
text.buffer.lines = ret

if ret <> 0 then
ret = text.defaults("tirou102.txta", tgroup, edit_opt)
endif

temp.file.name = creat.tmp.file$(bse.tmp.dir$())
temp.file.name = strip$(temp.file.name)
temp.file.numb = seq.open(temp.file.name, "w+")

if text.buffer.lines > 0 then
for curr.line = 1 to text.buffer.lines
temp.text.line(1;60) = text.buffer(1, curr.line)
ret = seq.puts(temp.text.line, temp.file.numb)
endfor
endif

temp.text.line = "Tooling Required: " & align.sitm
ret = seq.puts(temp.text.line, temp.file.numb)
ret = seq.close(temp.file.numb)

if ret = 0 then
if tirou102.txta = 0 then
ret = text.write("tirou102.txta", "2", "Operation Text", align.mitm, "Operation" & str$(tirou102.opno),
"", "standard", "standard", temp.file.name)
else
ret = text.rewrite("tirou102.txta", "2", "Operation Text", align.mitm, "Operation" & str$(tirou102.opno),
"", tgroup, tgroup, temp.file.name)
endif
endif
db.update(ttirou102, db.retry)
endselect

commit.transaction()
}

mark_h
7th February 2012, 15:46
We use UNIX and it looks like your OS is windows. We do not have this problem, but we write 2 files then cat them together into one file and write that file back into the text. The question I have is - Are the text.buffer.lines coming back correctly? What happens in debug mode after the seq.close? Can you look at the temp file to see if those extra lines are there? It looks like this should work.

I am also just wondering if you could write the text straight to the temp file(using text.read) and open it with "a" parameter seq.open. Then just append your text with the seq.puts. Not sure how that works on windows.

Included some old code from one of our sessions - in this case we actually append two separate texts together into one. We have other sessions kind of like yours.

function append.text(domain tcmcs.str16 some.field)
{
string temp.file1(500), temp.file2(500), cmd(1024)
string kw1(17),kw2(17),kw3(17),kw4(17),tgrp(8),eopt(15)
long write.return, ret.code

temp.file1 = creat.tmp.file$(bse.tmp.dir$())
temp.file1 = strip$(temp.file1)
write.return = text.read("tdudi010.txtn", "2", kw1, kw2, kw3, kw4, tgrp, eopt, temp.file1, 0)

temp.file2 = creat.tmp.file$(bse.tmp.dir$())
temp.file2 = strip$(temp.file2)
write.return = text.read(some.field, "2", kw1, kw2, kw3, kw4, tgrp, eopt, temp.file2, 0)

cmd = sprintf$("cat %s>>%s", temp.file1 , temp.file2)
ret.code = shell(cmd, SHELL_NO_OUTPUT)

write.return = text.rewrite(some.field, "2", kw1, kw2, kw3, kw4, tgrp, "", temp.file2)
commit.transaction()
ret.code = seq.unlink(temp.file1)
ret.code = seq.unlink(temp.file2)
}

SandraDiehl
7th February 2012, 20:42
Thanks Mark for the reply...after a terrible night dreaming this code I had a thought that went back to the fact we have two main text groups with both of different sizes.
Recall I stated we had one that was 31X23 and the other 80X23. My code originally was just dealing with the group that was 80X23, so what it ended up doing is attempting to slam 80 characters into the text that had the text group defined at 31X23.

Got the confirmation of my dream by doing debug and seen that the temp lines at the point of the seq.put was correct, the temp file on the network didn't show any additonal lines, it was when it was actually in the text file in BaaN.

function update.std.routing.notes()
{
string text.buffer(80, 900)
string tmp.file(80)
string temp.file.name(100)
string temp.text.line(80)
string tmp.small.line(31)
string tmp.line(80)
string tgroup(8)
string edit_opt(15)
string kw1(17)
string kw2(17)
string kw3(17)
string kw4(17)
long temp.file.numb
long text.buffer.lines
long curr.line
long no.lines
long tmp.len

db.retry.point()

select tirou102.*
from tirou102 for update
where tirou102._index1 = {:align.mitm}
and tirou102.opno = :buf.opno
selectdo
tmp.small.line = ""
temp.text.line = ""
text.buffer(80,900) = ""
tmp.line = ""
ret = text.to.buf("tirou102.txta", "2", 900, text.buffer)
no.lines = text.read("tirou102.txta", "2", attr.textkw1$, attr.textkw2$, attr.textkw3$, attr.textkw4$, tgroup, edit_opt, tmp.file, 0)
if ret > 0 then | Save the original text default values.
text.buffer.lines = ret
kw1 = attr.textkw1$
kw2 = attr.textkw2$
kw3 = attr.textkw3$
kw4 = attr.textkw4$
else
kw1 = "Operation Text"
kw2 = align.mitm
kw3 = "Operation" & str$(tirou102.opno)
kw4 = ""
tgroup = "standard"
edit_opt = "standard"
endif

temp.file.name = creat.tmp.file$(bse.tmp.dir$())
temp.file.name = strip$(temp.file.name)
temp.file.numb = seq.open(temp.file.name, "w+")

if trim$(tgroup) = "small" then
if text.buffer.lines > 0 then
for curr.line = 1 to text.buffer.lines
tmp.small.line(1;31) = text.buffer(1, curr.line)
ret = seq.puts(tmp.small.line, temp.file.numb)
endfor
endif
tmp.line = "Tooling Required: " & trim$(align.sitm)
tmp.len = len(trim$(tmp.line))
if tmp.len > 31 then | Need this check to break up the new line if it's bigger than the text default size.
tmp.small.line = "Tooling Required: "
ret = seq.puts(tmp.small.line, temp.file.numb)
tmp.small.line = trim$(align.sitm)
ret = seq.puts(tmp.small.line, temp.file.numb)
else
ret = seq.puts(tmp.line, temp.file.numb)
endif
ret = seq.close(temp.file.numb)
else
if text.buffer.lines > 0 then
for curr.line = 1 to text.buffer.lines
temp.text.line(1;80) = text.buffer(1, curr.line)
ret = seq.puts(temp.text.line, temp.file.numb)
endfor
endif
temp.text.line = "Tooling Required: " & align.sitm
ret = seq.puts(temp.text.line, temp.file.numb)
ret = seq.close(temp.file.numb)
endif


if ret = 0 then
if tirou102.txta = 0 then
ret = text.write("tirou102.txta", "2", kw1, kw2, kw3, kw4, tgroup, edit_opt, temp.file.name)
else
ret = text.rewrite("tirou102.txta", "2", kw1, kw2, kw3, kw4, tgroup, edit_opt, temp.file.name)
endif
endif
db.update(ttirou102, db.retry)
endselect

commit.transaction()
}

For those curious of what I had to do this is my final code and it seems to now be working updating over 19,000 text records without adding a bunch of blank lines:

mark_h
7th February 2012, 21:04
Thanks for posting the solution. We use different text groups, but I think they are all defined the same.

Now if you could just dream the numbers for the lottery for me. :)