Unable to create global variable on the fly

I was going through the documentation for creating the Global Variable on the fly but unfortunately, it is not working properly. Is anybody has any idea about how to create Global Variables on the fly?