In reply to lalithjithan:
I see probable issues in your code, but your example fails the Copy, Paste, Compile test, so I don’t know if your example really demonstrates your problem, or has entirely new problems of it’s own.
Provide an executable example that replicates the behavior: Minimal reproducible example - Wikipedia
Preferably one you can share on https://www.edaplayground.com