rmarles
23rd January 2004, 15:25
Hello all,
Trying to perform an update (or an insert) of text onto a sales order header however the help text isn't very helpfull for these functions (the examples are terrible).
I'm trying to come up with a way to put tracking numbers from shipments into the order text; or, if the shipment has been voided, remove the appropriate line from the order text.
I'm not really looking for someone to program this, however provide a better example of how the text write & rewrite functions work (for example, in the case of text.rewrite, I obviously already know the text number, but where do I pass it to the function?).
I'm also looking for ideas as to how I'd remove a line of text (possibly a string of text in the middle of valid text sort of deal - I'd know the string I need removed)
Thanks in advance!
mark_h
23rd January 2004, 15:58
Here is a search (http://www.baanboard.com/baanboard/search.php?s=&action=showresults&searchid=196929&sortby=lastpost&sortorder=descending), you can do the same thing for text and text.rewite. Also below is some code from one program I knew that did something like you are asking. Not sure if it works and this is not my code.
add.line.text()
db.insert(ttirou102,db.retry)
commit.transaction()
|Remove the pipe if you add back the statement refering to ignoring the
|zero setup and run times.
| endif
}
function add.line.text()
{
rturncd= 0
t.numrecs= 0
rewrite.return = 0
rturncd = text.to.buf("tirou102.txta","2",900,t.buf)
if rturncd > 0 then
t.numrecs = rturncd
endif
temp.file = creat.tmp.file$(bse.tmp.dir$())
temp.file = strip$(temp.file)
temp.return = seq.open(temp.file, "w+")
fp2 = temp.return
tmp.rec(1;80) = "TIM3"
temp.return = seq.puts(tmp.rec,fp2)
for i = 1 to t.numrecs
tmp.rec(1;80) = t.buf(1,i)
temp.return = seq.puts(tmp.rec,fp2)
endfor
temp.return = seq.close(fp2)
if rturncd > 0 then
rewrite.return = text.rewrite("tirou102.txta",
"2","Operation Text",hold.mitm(1,rout.index),
"Operation"&str$(tirou102.opno),
" ","routing","text",temp.file)
endif
if rewrite.return < 0 then
message("Txt r/w error #%d", return.code)
execute(end.program)
endif
}
rmarles
23rd January 2004, 16:54
Mark
Thanks for the reply - I did a quick search prior to posting and didn't find any helpfull information.
In regards to your source sample, what did you delcare t.buf as (ie string t.buf(4096)?)?
I don't understand the purpose of pumping 'tmp.rec(1;80) = "TIM3"' to the temp file prior to concatenating the buffer (t.buf) to the tmpfile - could you explain please?
Thanks
rmarles
23rd January 2004, 20:17
Alright;
I have managed to get my project working - a few more problems - now that it's working, whenever I enter the sales order text that has been modified by my session, the normal 60x15char text editor is gone, and it's in Full Screen mode.
Also, I found that performing a text.delete doesn't seem to work - I called the text.delete function on a sales order, went to the sales order, and "Text :" still had "Yes" in the field - upon entry, there was no text, and upon exit it updated the session.
(Problem was it was considered a write change, and since the s/o's customer was blocked, it wouldn't let me move off the order unless I "U"ndid the 'Write') Suggestions?
rmarles
23rd January 2004, 20:19
(Any suggestions on tightening the code would be appreciated!)(I'm also not sure how to make the source appear with highlighted keywords)
file.numb = seq.open(file.name, "r")
if file.numb => 1 then
repeat
wordcount = seq.gets(buffer, 1024, file.numb)
if wordcount = 0 then
ret.err = string.scan(buffer,
"%s,%s,%s,%s,%s",
TrackingNumb,
ShipmentReference1,
ShipmentReference2,
ShipPrice,
VoidIndicator)
if sq(VoidIndicator) = "N" then
set.tracking.number( sq(TrackingNumb),
sq(ShipmentReference1),
sq(ShipmentReference2))
else
remove.tracking.number( sq(TrackingNumb),
sq(ShipmentReference1),
sq(ShipmentReference2))
endif
endif
until wordcount < 0
ret.err = seq.close(file.numb)
else
message("cannot open " & file.name,1)
clean.mess()
endif
rmarles
23rd January 2004, 20:21
function set.tracking.number( string trackno(25),
string ps.str(6),
string orno.str(6))
{
domain tcorno orno.l
long ret.err
long temp.file.numb
string temp.file.name(100)
string text.buffer(60,900)
long text.buffer.lines
string temp.text.line(4096)
long curr.line
orno.l = lval(orno.str)
db.retry.point()
select tdsls040.*
from tdsls040 for update
where tdsls040._index1 =
{:orno.l}
selectdo
ret.err = text.to.buf("tdsls040.txta","2",900,text.buffer)
text.buffer.lines = ret.err
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.err = seq.puts(temp.text.line, temp.file.numb)
endfor
endif
temp.text.line = "Tracking # " & trackno & " / For PS:" & ps.str
ret.err = seq.puts(temp.text.line, temp.file.numb)
ret.err = seq.close(temp.file.numb)
if ret.err = 0 then
if tdsls040.txta = 0 then
ret.err = text.write( "tdsls040.txta",
"2",
"Sales",
"Order header",
str$(tdsls040.orno),
tdsls040.refa,
"txt",
"3",
temp.file.name)
else
ret.err = text.rewrite( "tdsls040.txta",
"2",
"Sales",
"Order header",
str$(tdsls040.orno),
tdsls040.refa,
"txt",
"3",
temp.file.name)
endif
endif
db.update(ttdsls040, db.retry)
endselect
commit.transaction()
}
rmarles
23rd January 2004, 20:23
function remove.tracking.number(string trackno(25),
string ps.str(6),
string orno.str(6))
{
domain tcorno orno.l
long ret.err
long temp.file.numb
string temp.file.name(100)
string text.buffer(60,900)
long text.buffer.lines
string temp.text.line(60)
string trac.text.line(60)
long curr.line
long line.count
orno.l = lval(orno.str)
db.retry.point()
select tdsls040.*
from tdsls040 for update
where tdsls040._index1 =
{:orno.l}
and tdsls040.txta <> 0
selectdo
ret.err = text.to.buf("tdsls040.txta","2",900,text.buffer)
text.buffer.lines = ret.err
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+")
trac.text.line = "Tracking # " & trackno & " / For PS:" & ps.str
line.count = 0
for curr.line = 1 to text.buffer.lines
if strip$(text.buffer(1,curr.line))
<> trac.text.line then
temp.text.line(1;60) = text.buffer(1,curr.line)
ret.err = seq.puts(temp.text.line, temp.file.numb)
line.count = line.count + 1
endif
endfor
ret.err = seq.close(temp.file.numb)
if ret.err = 0 then
if line.count = 0 then
ret.err = text.delete( "tdsls040.txta",
"2")
else
ret.err = text.rewrite( "tdsls040.txta",
"2",
"Sales",
"Order header",
str$(tdsls040.orno),
tdsls040.refa,
"txt",
"3",
temp.file.name)
endif
endif
db.update(ttdsls040, db.retry)
endselect
commit.transaction()
}
function string sq(string instr(1024))
|"strip quotes"
{
string temp.str(1024)
temp.str = instr(2;(len(instr)-2))
return(temp.str)
}
Any suggestions as to why I would have that problem would be greatly appreciated.
Thanks.
mark_h
23rd January 2004, 23:44
From looking at one of our programs I see something like this:
function delete_text()
{
text = hold.txta(rout.index)
noofdellines = text.delete("text","2")
if noofdellines <= 0 then
message ("we have a problem with deleting text",
val(str$(hold.txta(rout.index))))
endif
commit.transaction()
}
So I would probably move that db.update to inside the statement and after the text.rewrite. And t.buf was declared as string t.buf(80,900). We were inserting a line into our manufacturing text that said tim3. I do not recall what that meant to our ME's.
Mark
avpatil
27th January 2004, 00:03
Hi,
This just a suggestion.
I am not sure why you are looking to put tracking number in text. I would prefer to store in some table. In my system I am storing the tracking numbers in a custom table, and the user can click on the tracking button to see the actual tracking. It goes to UPS/FEDEX and some other trucking companies website for tracking. We also send a shipment notification email that contains all the hyperlinked tracking numbers. I guess, you can get more funtionality if you start defining them in table rather thanin text. The uses are unlimited. You can store all the freight information etc.
Again this is just a suggestion.
Arvind
mark_h
27th January 2004, 00:40
That is an excellent suggestion. I guess when I read the original post I was thinking it was like our situation. Our users come to us and say our standard text says "see disclosure statement xxxx" and now we need it to say "see discloure statement yyyy". Basically a mass update on text for only those items that need it.
Mark
rmarles
27th January 2004, 20:56
An excellent suggestion; I'm investigating how this would affect our system as it's aging and I'm not sure how it would be supported by making these changes.
Part of the reason I wanted to insert it into text is because it means that it will use standard functionality when printing out the different order paperwork as they all have text included in them.
Thanks for your help!