As long as your compiler supports that chip, the compiler shoudd take care of any minor differences - presumably there's a 'migration document' on MicroChip explaining any changes?.
The 16F887 has a lot more hardware modules, which makes it a much better chip, and it is cheaper.
However that means you will need to change the source code a little bit as some things need to be turned off in the 887, and those things are not in the 877. I can;t remeber exactly but it will likely involve the ADC and analog pins, and the comparators.
So you can't just program a 16F877 HEX file into a 16F887.