The 940 comes from the depositor's order system. It names the ship-to, the carrier or service level, the wanted date, and the lines: item, quantity, unit of measure, sometimes lot or packing requirements. It is an instruction rather than a purchase order; the depositor already owns the goods and is saying where to send them.
The 945 goes back once the warehouse has picked, packed and loaded. It repeats the order identifiers so the depositor's system can match it, then adds what happened: quantity shipped per line, the carrier, the tracking or PRO number, the ship date, cartons and weights, and the SSCC of each carton or pallet when the depositor needs those for its own ASN downstream.
Between them the two close a loop. The 940 moves an order to 'released to warehouse'; the 945 moves it to 'shipped', which is what lets the depositor invoice its customer and send its own 856. Until the 945 lands, the depositor's system does not know the goods have gone, so a late 945 surfaces as a customer-service complaint before anyone thinks to call it an EDI problem.