Hi Vinodh,
Probably Deepak Panangattiri's suggestion is the simplest one that works. If you want a logic on your own then you can use my code suggested else you can use the standard from SAP which should be always preferred.
I think you should have got the answer. Could you please close the thread as answered.
Thanks,
Naveen