I suggest to create a bug report in our Issue Tracker and attach HAL code that is causing compile errors. Just looking at your code I don't see anything wrong with it so it likely should be investigated.
Hello!
You can mark it as closed as option. If document is connected with other documents you can not delete it so you will not be able to delete PO, as you will not be able to remove Goods receipt...