Hi Sathyamurthy,
The code which you have written is correct but just check once in debugging what is happening and you can find the issue clearly.
Note: Instead of nested IF..ELSEIF you can move to CASE it increase performance of the program as well as it makes good readability to others.
Regards,
Chakradhar.