Assalamu Aliakum,
If he does this while fasting and it involves him doing an action or movement, this invalidates his fasting as it was predetermined and intentional.
But if he only thinks and ejaculates without any movement from his part, this doesn’t affect his fasting in sha Allah.