I suggest you probably have a problem with your programmer or software? (you don't mention what either of them are), but you can't protect a 16F877 so you can't erase it. Part of the erasure process (or programming process for that matter) wipes the program and data memory, then wipes the config fuses (including the code protect fuse). It can only be done in that order, you can't easre the fuse settings without erasing all the data first (for obvious security reasons).