Praise be to Allah.If a person enters the mosque and is praying the sunnah while the iqamah is called, then the best opinion in this case is that if he is in his second rak‘ah, he should shorten it, and if he is in the first rak‘ah, he should just break his prayer and enter the congregation with the Imam1. The evidence for this comes from what Imam Muslim has narrated in his Sahih:
Prophet (peace be upon him) said: If iqamah is called for the prayer then there is no prayer except the obligatory one.
(Sahih Muslim, 1/493)
So, if one has performed the ruku‘ for the second rak‘ah, then he should complete the prayer, and if not, then he should discontinue because what is left from his sujud and tashahhud is not needed any more. Moreover, he should break without salaam, and it is enough to have the intention in the heart, contrary to common misconception.