Thanks for your replies. The issue is now resolved. I was not getting sqlcode 180 or anything else. The query was failing with an sqlcode 100.
The logic to calculate timestamp is perfect.
There was a logic error in the code.
For people interested to know what was the problem.
The extension of lock was happening only once initially, but it is changed to extend the lock twice now. But the catch is that while extending the lock second time only first two digits of micro seconds in timestamp is taken into account and not the last four and the lag between the first and second extension would be such that it would be only in the last four digits of micro seconds.
So whenever the load was more on db2 the lag would ve reached upto first two digits of microseconds that time i was not gettting any error but in the other cases.