Hi Jayant,
If you modified the standard, why did you make an implicit enhancement?
This behavior is because you are using your variable out of your enhancement code, this is definitely unusual.
I suggest that you just remove the implicit enhancement, whereas the function is already open.
Regards,
Paulo.