On the global periodicity of discrete dynamical systems and application to rational difference equations