jcook331
3rd February 2006, 19:54
I have a maintenance session where I'm updating a field through a function. The function does a check and then updates a date field progammatically. When the function runs the date displays in the field, but is not written to the table on save. I think I have seen this before but don't remember what I did to fix it. Any ideas?
csecgn
3rd February 2006, 19:58
Call update.occ() after your changes. This should help.
Regards
csecgn
jcook331
3rd February 2006, 20:05
I tried the update.occ() and it still did not work. Thanks, though.
csecgn
3rd February 2006, 21:02
:confused: Did you try like:
update.occ() | a field has changed without user interaction
execute(update.db) | Update database
execute(interrupt) |refresh display
hth
Regards
csecgn
jcook331
3rd February 2006, 22:02
I had not done that, but when I tried that it still did not work. Here is the part of the code where I'm trying to update the table field.
if lflfa360.rvav = 0 then
lflfa360.rvav = date.num()
update.occ()
execute(update.db)
execute(interrupt)
display("lflfa360.rvav")
message("File Verified")
endif
lbencic
3rd February 2006, 23:09
Could you please post what sections the update call is made from? How you handle commits vs. update occ. can depend on what standard section you are calling the update from....
jcook331
3rd February 2006, 23:39
I am calling the function that updates the field from choice.user.4 (a button on the form). I found an old post that had a solution for this that works. Code is:
choice.user.4:
after.choice:
do.all.occ(check.for.file)
....
function check.for.file()
{
domain tcmcs.str100 pnam357
domain tcmcs.str15 cprj357
string network.path(210)
long num.bytes
long app.id
...
if lflfa360.rvav = 0 then
update.occ()
lflfa360.rvav = date.num()
execute(update.db)
display("lflfa360.rvav")
message("File Verified")
endif
...
}
mark_h
3rd February 2006, 23:58
Shouldn't these two lines be reversed or is it a typo:
update.occ()
lflfa360.rvav = date.num()
csecgn
4th February 2006, 12:43
Like Mark wrote: You are writing the update.occ before you update the field.Update.occ acts like db.update(...). I also think thats the problem.
...
if lflfa360.rvav = 0 then
lflfa360.rvav = date.num()
update.occ()
execute(update.db)
display("lflfa360.rvav")
message("File Verified")
endif
...
In your case you also have another opportunity: Select the table with the record where you are for update and write after the commit an execute(interrupt). This should also work.
...
db.retry.point()
select lflfa360.*
from lflfa360 for update
where lflfa360._index1 = {:lflfa360.<keyfield1>,...}
selectdo
lflfa360.rvav = date.num()
db.update(tlflfa360, db.retry)
endselect
commit.transaction()
execute(interrupt)
...
Another note: The do.all.occ works only for the visible records on your form. With this you cannot update the whole or a limited range of your maintable if it is not on the actual view.
hth
Regards
csecgn
toolswizard
6th February 2006, 20:42
Try changing the order.
Assign the field a value.
Display the field on the form.
Update the occurance.
Call the DB update.
You might be rereading the form value and it is resetting to the original value.
tmannais
10th December 2019, 11:36
I just had an issue similar to this.
I can confirm that using
update.occ()
execute(update.db)
works.
mark_h
10th December 2019, 15:03
I don't think the question in this case was update.occ() and execute(update.db) not working, but I think it was the order the commands were being called while setting values. So set you field values, then call update.occ and then the execute. Don't call the update.occ, then set variables then call execute. :)
OmeLuuk
10th December 2019, 15:22
choice.user.4:
after.choice:
do.all.occ(check.for.file)
Ehm, the choice.user sections...
I thought these sections are not executed in the 4GL transaction? IN that case you will need to start your own transaction (so in the before.choice: add db.retry.point() and after the do.all.occ() add a commit.transaction?