Hi Imran,
You need to check firstly if there is a transition possible to the new status from the current status as Gaurav has specified above.
In case it is possible then , you need to check if the transaction is getting locked because it is being replicated to ECC etc. Usually when you are saving transactions , then they start replicating to ECC as per your configurations , during the time of replication , the documents get locked temporarily in the status "to be distributed" . During that time period for 10 - 15 seconds , you can't edit the document or make any changes . In this scenario you might have to find some other place or enhancement to write down your logic.
/Hasan