Thanks for writing to us with your health concern.
He did not ejaculate, and it was just 4 days before your period.
I do not think there is any chance for pregnancy
An infection is more likely given the cramps.
Have a gynaecological assessment after your periods.