eric.dizon
22nd January 2014, 23:10
Hello,
I am trying to insert inverse of a record using DAL. I have two fields Item A and Item B. What i need to achieve is when a user enters like ABC in Item A and DEF in Item B. Automatically inside the DAL I would like to create another new record for that table with an inverse value like Item A: DEF | Item B: ABC. The code below does not work, in the insert.inverse function; it does not return proper values and does not insert a new record.
table tcxitm100 | Related Items
domain tcmcs.long l.riid
domain tcitem l.itma
domain tcitem l.itmb
function extern long before.save.object(long type)
{
on case type
case DAL_NEW:
select max(cxitm100.riid):l.riid
from
cxitm100
selectdo
cxitm100.riid = l.riid + 1
selectempty
cxitm100.riid = 1
endselect
l.itma = cxitm100.itma
l.itmb = cxitm100.itmb
break
endcase
return(0)
}
function extern void after.commit.transaction()
{
long i.ctr
insert.inverse(l.itma, l.itmb)
}
function long insert.inverse(domain tcitem t.itma, domain tcitem t.itmb)
{
long i.ctr
|db.retry.point()
select cxitm100.*
from cxitm100
where cxitm100._index3 = {:t.itma, :t.itmb}
selectempty
cxitm100.itma = t.itmb
cxitm100.itmb = t.itma
db.insert(tcxitm100, DB.RETRY, elocked)
commit.transaction()
selectdo
i.ctr = 1
endselect
return(0)
}
I am trying to insert inverse of a record using DAL. I have two fields Item A and Item B. What i need to achieve is when a user enters like ABC in Item A and DEF in Item B. Automatically inside the DAL I would like to create another new record for that table with an inverse value like Item A: DEF | Item B: ABC. The code below does not work, in the insert.inverse function; it does not return proper values and does not insert a new record.
table tcxitm100 | Related Items
domain tcmcs.long l.riid
domain tcitem l.itma
domain tcitem l.itmb
function extern long before.save.object(long type)
{
on case type
case DAL_NEW:
select max(cxitm100.riid):l.riid
from
cxitm100
selectdo
cxitm100.riid = l.riid + 1
selectempty
cxitm100.riid = 1
endselect
l.itma = cxitm100.itma
l.itmb = cxitm100.itmb
break
endcase
return(0)
}
function extern void after.commit.transaction()
{
long i.ctr
insert.inverse(l.itma, l.itmb)
}
function long insert.inverse(domain tcitem t.itma, domain tcitem t.itmb)
{
long i.ctr
|db.retry.point()
select cxitm100.*
from cxitm100
where cxitm100._index3 = {:t.itma, :t.itmb}
selectempty
cxitm100.itma = t.itmb
cxitm100.itmb = t.itma
db.insert(tcxitm100, DB.RETRY, elocked)
commit.transaction()
selectdo
i.ctr = 1
endselect
return(0)
}