You have to do replacement of top rail for above ground pool when they rusted or corroded. The Rust is caused by rain and the sun, or from corrosive chemicals like salt, chlorine, acid, etc. Over time the effects damage on the coatings protecting the metal parts of the average above ground pool including top rail.
You can buy the top rail to do replacement by yourself or hire professional for your above ground pool. You need to know exactly size and type of your above ground pool top rails or your new rail will be unused. Maybe you will find your pool type is no longer produced, and your rail type is no longer available. Take a picture and send it to an experienced pool dealer and see if there are still available or suitable types is the simple and easy way.
You need to do top rail replacement when you see your top rails rusted with pieces falling into the pool. A quick and cheap way is to take rails off and clean grid with your drill and the spray a coat of the trench liner in a container. It turns into a sheet of rubber.