Conventional methods of compensating for self-distortion in liquid-crystal-on-silicon spatial light modulators (LCOS-SLM) are based on aberration correction, where the wavefront of the incident beam is modulated to compensate for aberrations caused by the imperfect optical flatness of the LCOS-SLM surface. Previously, we proposed an effective method to compensate for the distortion by displaying a compensation phase pattern obtained from interferometry However, the phase distribution of an LCOS-SLM varies with changes in ambient temperature and requires additional correction. The ambient temperature of LCOS-SLMs can vary under certain circumstances, i.e. equipped inside systems for field use or long-term operations. In this presentation, we discussed a novel phase compensation method under temperature-varying conditions based on an orthonormal Legendre series expansion of the phase distribution from viewpoint of multiple beam holographic generation. We found several Legendre coefficients that follow quadratic functions of ambient temperature. This prompted us to propose an algorithm for correcting the temperature dependency by displaying a phase pattern using two simple steps: an initializing step and a temperature correction step. We investigated the temperature dependency by controlling the ambient temperature with an incubator and successfully corrected for self-distortion in a temperature range of approximately 68°F to 122°F, giving an optical flatness of <λ /10. Our approach has the potential to be adopted in tight-focusing applications which require wavefront modulation with very high accuracy. Additionally, the concept of this method is extensible to the thermal behavior of other optical devices, such as lenses and mirrors, which have the possibility of causing unexpected aberrations.