Gaith1
26th November 2015, 18:46
Hi,

I'm pretty sure that's not possible but may be someone can confirm or suggest another way to do it

Can I use dynamic variables to do insertion in specific field

example below: variable test content field sagen901.user (custom table) and after in my selectempty I have test = user.i (to assign user.i to sagen901.user.

function void update.main.table()
{
domain tcmcs.str15 test

test = sagen901.user |************************

select sagen901.*
from sagen901 for update
where sagen901._index1 = { :dati.i, :user.i, :sess.i }
selectdo
if timi.i < sagen901.timi then
sagen901.timi = timi.i
endif
if dato.i >= sagen901.dato and timo.i > sagen901.timo then
sagen901.timo = timo.i
endif
if dato.i > sagen901.dato then
sagen901.dato = dato.i
sagen901.timo = timo.i
endif
sagen901.cntr = sagen901.cntr + 1
db.update(tsagen901, db.retry)
update.ctr.f = update.ctr.f + 1
selectempty
test = user.i |************************
sagen901.sess = sess.i
sagen901.dati = dati.i
sagen901.timi = timi.i
sagen901.dato = dato.i
sagen901.timo = timo.i
sagen901.comp = comp.i
sagen901.cntr = 1
db.insert(tsagen901, db.retry)
insert.ctr.f = insert.ctr.f + 1
endselect
rec.ctr.i = rec.ctr.i + 1
if rec.ctr.i > COMMITINT then
rec.ctr.i = 0
display("inctr.f")
display("insert.ctr.f")
display("update.ctr.f")
display("skip.ctr.f")
commit.transaction()
endif
}

thanks

RedBatz
26th November 2015, 19:09
Hi,

To assign user.i to sagen901.user, it has to be sagen901.user=user.i (at selectempty section), instead of test = user.i.

Gaith1
26th November 2015, 19:33
Ok thanks,

You means this is not possible to assign (use a variable in the selectempty) , I should use the field itself (sagen901.user = user.i )

RedBatz
27th November 2015, 00:17
Hi,

db.insert() is for inserting a record. A variable is not a table column.

JaapJD
27th November 2015, 09:22
Use this code:

put.var(pid, test, user.i)

to assign a value to a variable of which the name is in another variable.
See also thread (http://www.baanboard.com/baanboard/showthread.php?t=61296).

vamsi_gujjula
27th November 2015, 09:55
To be frank i really did not understand your requirement !!!!!!

what i understand is you want to update an existing record(on some conditions) and if it does not you want to insert.

i feel its quite possible

Gaith1
27th November 2015, 15:45
thanks to each of you , I have my confirmation that's not possible.

thanks