cherokee
7th October 2010, 17:20
Hello everyone,
I have to update a second table. It only works if the user tabs and goes on the next record of the form. If the user only changes the value of the field on the second table and try to save, old values are kept.
When debugging, I see that as soon the session gets in the main.io/before.rewrite(where I set other values) old values are back to the updated field.
Any idea
Thanks,
Hitesh Shah
7th October 2010, 20:03
Use do.occ / on.old.occ functions to get the actual values (old/new ) for actual.occ in main.table.io . This should help u .
rberti
7th October 2010, 20:35
Hi Carlos,
You can use the stndard variable "g.update.status". When the field of the second table changes, set g.update.status = 21 (modify set). It should make 4gl engine work as when you are changing a main table field.
Hope it helps!
Regards,
Rafael
cherokee
7th October 2010, 20:42
Fields from the second table are part of the actual.occ? or only the ones from the main table?
Thanks,
cherokee
7th October 2010, 21:10
This is my code.... I tried the g.update.status = 21 and doesn't work...
field.tiitm001.flag.cmc:
before.input:
read.item.data()
set.enum.values(tiflag.yes,tiflag.no)
if tiitm001.eitm = tcyesno.yes then
attr.input = false
endif
when.field.changes:
g.update.status = 21
tiitm986.logn = logname$
tiitm986.date = date.num()
field.tiitm001.ear.cmc:
before.input:
read.item.data()
when.field.changes:
g.update.status = 21
tiitm986.logn = logname$
tiitm986.date = date.num()
|****************************** main table section **********************************
main.table.io: |Main Table is tiitm986 <<-------
before.write:
do.occ(actual.occ, set.flag.to.yes)
before.rewrite: |As soon it gets in this section, the values in the
tiitm986.logn = logname$ |when.field.changes are overwriten by the old values
tiitm986.date = date.num()
on.old.occ(set.flag.to.yes)
| do.occ(actual.occ, set.flag.to.yes) |on and off for testing
functions:
function set.flag.to.yes()
{
if tiitm001.flag.cmc <> tiflag.yes and tiitm001.ear.cmc = tiear.tbd then
message("Item should be either FLAG = Yes or EAR Not Equal to TBD",1)
skip.io("")
return
endif
on.change.check(tiitm001.ear.cmc)
on.change.check(tiitm001.flag.cmc)
select tiitm001.* |Secondary table <<----
from tiitm001 for update
where tiitm001._index1 = {:tiitm986.item}
selectdo
if changed(tiitm001.flag.cmc) then
not.curr(tiitm001.flag.cmc)
endif
if changed(tiitm001.ear.cmc) then
not.curr(tiitm001.ear.cmc)
endif
db.update(ttiitm001, db.retry)
endselect
}
Thanks...
mark_h
7th October 2010, 22:23
I do not know if this will help - it reminds me of the problem I had with qkey and adding tables onto a form. What I did was use new external defined fields. I will post one of the scripts - in my case tccom970 was the secondary table. Notice the comment in the maintain io after.rewrite section. I also get the fields in the after.read section. I ran into this exact problem trying to use qkey and adding other tables - this is how they are all done today. Not sure if this helps or not.
declaration:
table ttccom970 | Supplier extension table
table ttccom020 | Suppliers
| Added form fields
extern domain tcdate supl.expd | Expiration Date
extern domain tcdate supl.k131 | KA131-1 Date 20070724
extern domain tcudi.taxt supl.taxt | Income tax type 20070724
extern domain tcyesno supl.appr | A&D Approved
extern domain tcmcs.str10 supl.ppic | Supplier Producer Price Index Code
extern domain tcmcs.str50 supl.mail | Supplier Email Address
extern domain tcnama supl.nama | Legal Tax return name
extern domain tcyesno supl.rfqable | RFQ Enable
extern domain tcyesno supl.purable | PUR Enable
extern domain tcyesno supl.statable | Status Enable
main.table.io:
| Read a record.
after.read:
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.read")
|#end add by QKEY
display_fields()
| Delete a record
after.delete:
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.delete")
|#end add by QKEY
delete_fields()
| Modify a record
after.rewrite:
| Hold this for after the update. During the update another
| table read is done which resets the displayed comment to
| the original. So save it for storing in the tisfc970 table.
|hold.ppic = tccom970.ppic
|doing.update = true
|#call
update_fields()
| Insert a record
after.write:
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.write")
|#end add by QKEY
|hold.ppic = tccom970.ppic
update_fields()
|#pobj added by QKEY 3.70
functions:
function display_fields()
{
select tccom970.*
from tccom970
where tccom970._index1 = {:tccom020.suno}
selectdo
supl.ppic = tccom970.ppic
supl.mail = tccom970.mail
supl.appr = tccom970.appr
supl.expd = tccom970.expd
supl.k131 = tccom970.k131 | Added KA131-1 date 20070724
supl.taxt = tccom970.taxt | Added income tax type 20070724
supl.nama = tccom970.nama
supl.rfqable = tccom970.rfqable | Added RFQ Enable indicator 20090119
supl.purable = tccom970.purable | Added PUR Enable indicator 20090119
supl.statable = tccom970.statable | Added Status Enable indicator 20090119
selectempty
|tccom970.ppic = ""
supl.ppic = ""
supl.mail = ""
supl.appr = empty
supl.taxt = empty | Added income tax type 20070724
supl.expd = 0
|supl.expd = tccom970.expd
supl.k131 = 0
supl.nama = "" | Added KA131-1 date 20070724
supl.rfqable = tcyesno.no | 20090119
supl.purable = tcyesno.no | 20090119
supl.statable = tcyesno.no | 20090119
endselect
|display("tccom970.ppic")
display.all()
}
function update_fields()
{
| db.retry.point()
select tccom970.*
from tccom970 for update
where tccom970._index1 = {:tccom020.suno}
selectdo
|tccom970.ppic = hold.ppic
tccom970.ppic = supl.ppic
tccom970.expd = supl.expd
tccom970.mail = supl.mail
tccom970.appr = supl.appr
tccom970.k131 = supl.k131 | Added KA131-1 date 20070724
tccom970.taxt = supl.taxt | Added income tax type 20070724
tccom970.nama = supl.nama
tccom970.rfqable = supl.rfqable | 20090119
tccom970.purable = supl.purable | 20090119
tccom970.statable = supl.statable |20090119
tccom970.date = date.num()
tccom970.user = logname$
db.update(ttccom970,db.retry)
selectempty
tccom970.suno = tccom020.suno
tccom970.ppic = supl.ppic
tccom970.expd = supl.expd
tccom970.mail = supl.mail
tccom970.appr = supl.appr
| tccom970.ppic = hold.ppic
tccom970.taxt = supl.taxt | Added income tax type 20070724
tccom970.nama = supl.nama
tccom970.rfqable = supl.rfqable | 20090119
tccom970.purable = supl.purable | 20090119
tccom970.statable = supl.statable |20090119
tccom970.date = date.num()
tccom970.user = logname$
tccom970.k131 = supl.k131 | Added KA131-1 date 20070724
db.insert(ttccom970,db.retry)
endselect
| commit.transaction()
}
function delete_fields()
{
|db.retry.point()
select tccom970.*
from tccom970 for update
where tccom970._index1 = {:tccom020.suno}
selectdo
db.delete(ttccom970,db.retry)
endselect
|commit.transaction()
}
cherokee
8th October 2010, 18:24
Hello Mark,
I practically copied your code. But for a reason it displays the same values in all occurances...
any idea?
Thanks...
mark_h
8th October 2010, 19:01
Yes - because yours is a multi-occurance form and mine was single occurence. Let me check one of the other sessions. I am sure I have one some where.
mark_h
8th October 2010, 19:25
Okay - for multi-occurance we moved the read to before.display. You can see that code in the field input.vtype. I did not realize how many qkey sessions we had - took forever to find a multi-occurance one with updates.
choice.user.0:
on.choice:
| Happens once after Initialize button clicked - these do not fire that main.table.io
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("on.choice.user.0")
|#end add by QKEY
hld.orno = tdilc501.orno
hld.cwar = tdilc501.cwar
initialize.button.updates()
choice.cont.process:
before.choice:
|my stuff here - flip flag
check.all.input()
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("before.choice.cont.process")
|#end add by QKEY
after.choice:
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.choice.cont.process")
|#end add by QKEY
| flip flag back
choice.update.db:
after.choice:
| Happens once after insert record, delete record or range of records, save after multi updates
| if try to update recd here, next record is current
| message ("choice.update.db %s %s", tdilc501.loca, tdilc501.item)
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.choice.update.db")
|#end add by QKEY
main.table.io:
after.write:
message("after.write %s %s %s %d", tdilc501.loca, tdilc501.item, hold.recd(1, actual.occ), actual.occ)
update.history()
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.write")
|#end add by QKEY
after.rewrite:
message("after.rewrite %s %s %s %d", tdilc501.loca, tdilc501.item, hold.recd(1, actual.occ), actual.occ)
| abort.transaction()
update.history()
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.rewrite")
|#end add by QKEY
after.delete:
| message("after.delete %s %s", tdilc501.loca, tdilc501.item)
delete.history()
|#call
|#pobj added by QKEY 3.70
_pobj_exe1("after.delete")
|***************************************************************************
|* Autogenerated subsections for main.table.io
|***************************************************************************
after.read:
_pobj_exe1("after.read")
before.write:
_pobj_exe1("before.write")
before.rewrite:
_pobj_exe1("before.rewrite")
|#end add by QKEY
|20100420.st
field.input.vtype:
before.display:
|message("before.display vtype")
select tdcyc100.orno, tdcyc100.sern, tdcyc100.ordt, tdcyc100.recnum, tdcyc100.vtype from tdcyc100
where tdcyc100._index1 = {:tdilc501.orno, :tdilc501.sern, :tdilc501.data}
and tdcyc100.stat <> tdcyc.stat.process
order by tdcyc100._index1 desc
as set with 1 rows
selectdo
input.vtype = tdcyc100.vtype
selectempty
input.vtype = tdcyc.vtype.none
endselect
cherokee
8th October 2010, 20:27
Yes, I put it in the before display, it works.
Thanks a lot.
joepte
13th April 2012, 22:50
Long time ago - but why do you put it in after display? Why does after display reset fields?
I have a multi occ session and all the fields change after an after.display (of unrelated fields and I am not sure why this is).
Thanks