The make repair rings for this...they are hinged and when spread apart, you can position it into the notch, and when you close it up and screw it down, it's locked in place. Is that concrete under there or wood? If concrete, you would need a carbide bit to drill holes and then use something either like a Tapcon screw or make a bigger hole and use an anchor. Use either SS or brass screws so that they don't rust out along with a ring made of the same. Not sure I particularly love this one since it only has a place for two screws to hold it in place, but there are other companies that make them. This gives you an idea of what's out there, though.
View attachment 30642
Thanks, i got an Oatey Moss Bay brand one from an online retailor, with 6 screw holes that i secured with brass wood screws into the wood underlayment. I had a couple issues i wanted to point out to anyone like me who had never done this before and wants to give it a shot.
First, there is a notch on the ABS or PVC pipe, which is how the metal rings hold onto the plastic. Even though i'd pulled away all the metal i could see, my notch was still full of nasty rusty metal that took the better part of 2 hours to slowly chip out with a screw driver.
Secondly, since i had a second layer of underlayment, and tile over the layer of wood the flange was resting on, it was a real PITA to get the Oatey Moss Bay pieces to fit in and stay put while i screwed them in. I ended up having to use some really small shims to build up to the lip of the notch as best i could. If any the other replacement pieces are hinged with a way to tighten them onto the notch prior to screwing in, it would save you a lot of hassle.