Answer:
1.He had been studying the report.
2.He was writing an e-mail when the phone rang.
3.When the phone rang, he was writing an e-mail.
4.I was preparing dinner while Melanie was working upstairs.