rajesh_bamane
5th May 2009, 10:30
Hi,

I have developed new session in baan IV. Now customized function is working fine.
But when i am closing or saving the session using standard buttons, i am getting fatal error "Record is not locked"

Please suggest the solution to resolve this error


regards
Rajesh

sprasad
5th May 2009, 11:19
Hi Rajesh,
Is the session maintain or update,can you post the script.

Regards,
Sai Prasad

wiggum
5th May 2009, 11:25
You get this error if you're trying to update a record without selecting it for update or you have committed the transaction after selecting the record and before updating it.

rajesh_bamane
5th May 2009, 12:45
declaration:

table ttdnci041
table ttdpur041
table ttdpur045
extern domain tcorno tdnci041.pono
extern domain tfgld.lino tdnci041.lino
extern domain tfgld.amnt tdnci041.bpric
extern domain tfgld.amnt tdnci041.apric
domain tfgld.amnt bamnt

|****************************** Field section **********************************
field.tdnci041.lino:
when.field.changes:
get_Receipt()
field.tdnci041.bpric:
when.field.changes:
get_cost()
|****************************** Functions *************************************
functions:

function get_Receipt()
{


select tdpur041.pric,tdpur041.oqua,tdpur045.orno,tdpur045.item,tdpur045.reno from tdpur041 ,tdpur045
where
tdpur041.orno=tdpur045.orno and
tdpur041.pono=tdpur045.pono and
tdpur041.orno=:tdnci041.pono and
tdpur045.pono=:tdnci041.lino and
tdpur045.reno<>0
selectdo

tdnci041.pono=tdnci041.pono
tdnci041.lino=tdnci041.lino
tdnci041.reno=tdpur045.reno
tdnci041.item=tdpur045.item
tdnci041.qty=tdpur041.oqua
tdnci041.pric=tdpur041.pric

db.insert(ttdnci041,db.retry,db.skip.dupl)
commit.transaction()


endselect

}
function get_cost()
{
bamnt=tdnci041.bpric

db.retry.point()

select tdnci041.*
from tdnci041 for update
where
tdnci041.pono=:tdnci041.pono and
tdnci041.lino=:tdnci041.lino

selectdo

tdnci041.pono=tdnci041.pono
tdnci041.lino=tdnci041.lino
tdnci041.bpric=bamnt
tdnci041.gl=tdnci041.bpric-tdnci041.pric
tdnci041.lcost=bamnt
tdnci041.apric=tdnci041.apric
tdnci041.rate=tdnci041.bpric/tdnci041.qty

db.update(ttdnci041,db.retry,db.skip.dupl)
commit.transaction()

endselect

}

litrax
5th May 2009, 16:31
wiggum is right.

First you should set the db.retry.point().
Then you must select a table for update.
Then use db.update or db.insert or db.delete.
After that you must use commit or abort transaction.

Please look at this manual:
http://www.baanboard.com/programmers_manual_baanerp_help_functions_database_handling_locking
Roughly use the schema under "Delayed locks" there.

The most answers to your questions can be found in the Programmer's Manual.

mark_h
5th May 2009, 19:51
All are correct. Things I noticed -

(1) Get_receipt does not have a db.retry point.
(2) You are using when field changes - this starts a transaction. You might be able to get away with an execute(update.db) before the db.retry point on both functions. In my thinking this would save and commit the recent change ending the transaction, then execute the function to do your updates(which would be new transactions).

rajesh_bamane
6th May 2009, 10:18
Hi

After removing the db.update from script my code is working fine.
Std save is working fine

Regards
Rajesh