During Birkat Ha’mazon on Shabbat, we add the "Reseh" paragraph. If one forgot to add "Reseh" in Birkat Ha’mazon after one of the first two Shabbat meals, he must repeat Birkat Ha’mazon. (The situation of one who forgot to add "Reseh" in Birkat Ha’mazon after Se’uda Shelishit will be discussed, please G-d, in a separate edition of Daily Halacha.)
However, if one realized his mistake before reciting Hashem’s Name in the Beracha of "Boneh Yerushalayim" – meaning, he recited, "Ve’tibneh Yerushalayim Ir Ha’kodesh…Baruch Ata Hashem," and at that moment he realized he forgot "Reseh" – he can correct himself such that he will not have to repeat Birkat Ha’mazon. He should recite at that point, "Lamedeni Hukecha," such that he will have recited the phrase "Baruch Ata Hashem Lamedeni Hukecha," which is a complete verse from Tehillim (119:12). Since he did not complete the Beracha, he is able to then recite "Reseh" and continue as usual with "U’beneh Yerushalayim" and the rest of the Birkat Ha’mazon.
This is the ruling of the Ben Ish Hai (Rav Yosef Haim of Baghdad, 1833-1909), in Parashat Hukat (20). Although the Hid"a (Rav Haim Yosef David Azulai, 1724-1806) disagreed, Hacham Ovadia Yosef sided with the position of the Ben Ish Hai, and this is, indeed, the Halacha.
Summary: If one forgot to recite "Reseh" during Birkat Ha’mazon after one of the first two Shabbat meals, and he realized his mistake after saying the words "Baruch Ata Hashem," before concluding, "Boneh Yerushalayim," he should say the words "Lamedeni Hukecha," and then recite "Reseh" and proceed as usual with "U’beneh Yerushalayim."