How to cancel an order status programmatically from an external ERP system?

A post was split to a new topic: How to set an order as shipped programmatically from an external ERP system?