It is OK to glue a flange inside a 4" pipe. This does not reduce the drain size enough to cause a problem. If your pipe was a 3", you could not do this because that would reduce the drain size too much. If you cut the existing flange off flush with the existing floor then install a new floor, the new flange has enough length to go well inside of the pipe. There is no need to caulk around the flange. Be very sure the new flange sets solidly on the finished floor and that it is oriented correctly so the flange bolts that hold the toilet in place are parallel with the back wall so that the toilet will not set cockeyed. After gluing the new flange into the pipe, it should be anchored through the flooring and into the concrete. There are several ways of doing this. Many like Tapcon bolts, and they certainly do work. My preferred method of anchoring screws into concrete is to use lead inserts and stainless steel sheet metal screws. This does require a small rotary-hammer drill to drill the holes for the inserts. I own one of these drills, which probably explains why I like this method.