timb25
21st September 2009, 19:15
Our employee table (tccom001) is created in 6 companies. It cannot be shared across all because of other business reasons. So, when someone creates a new employee, they have to perform the same function 6 times.
I wrote a custom session linked off the maintain employee session that allows you to insert the other companies you want to create the employee.
Starting in company 100, the employee (100123) is created, saved, and all is good. Then you open this session which displays employee 100123 and you set to update/insert company 310, 320, 330, 340. Refer to screen shot.
And here is the abridged version of the code:
function read.main()
{
result = switch.to.company(base.comp)
fill.current.employee() |Fills variables with employee table field values
x = 1
while x < 99 and comp.t(x) <> 0 |Loop thru each desired company
update.employee.record()
x = x + 1
endwhile
}
function update.employee.record()
{
result = switch.to.company(comp.t(x))
db.retry.point()
select tccom001.*
from tccom001 for update
where tccom001.emno = :emno.t | current employee
selectdo
assign.table.fields.from.variables()
result = db.update(ttccom001,db.retry)
selectempty
assign.table.fields.from.variables()
result = db.insert(ttccom001,db.retry)
endselect
commit.transaction()
}
I realize it's redundant going though company 100. But I do a switch.to.company and 310 should be the next company to evaluate. It determines there is no record in 310 so it will perform a db.insert. The result of the db.insert is 100 (duplicate record). I do not understand why......??
I wrote a custom session linked off the maintain employee session that allows you to insert the other companies you want to create the employee.
Starting in company 100, the employee (100123) is created, saved, and all is good. Then you open this session which displays employee 100123 and you set to update/insert company 310, 320, 330, 340. Refer to screen shot.
And here is the abridged version of the code:
function read.main()
{
result = switch.to.company(base.comp)
fill.current.employee() |Fills variables with employee table field values
x = 1
while x < 99 and comp.t(x) <> 0 |Loop thru each desired company
update.employee.record()
x = x + 1
endwhile
}
function update.employee.record()
{
result = switch.to.company(comp.t(x))
db.retry.point()
select tccom001.*
from tccom001 for update
where tccom001.emno = :emno.t | current employee
selectdo
assign.table.fields.from.variables()
result = db.update(ttccom001,db.retry)
selectempty
assign.table.fields.from.variables()
result = db.insert(ttccom001,db.retry)
endselect
commit.transaction()
}
I realize it's redundant going though company 100. But I do a switch.to.company and 310 should be the next company to evaluate. It determines there is no record in 310 so it will perform a db.insert. The result of the db.insert is 100 (duplicate record). I do not understand why......??