/*
Lists a material receipt and the shipment(s) where the received goods where shipped.
Shipments and receipts are matched if at least one of the recieved HUs was shipped.
Doesn't work if all HUs were split or e.g. issued to a production order. It same to be the *same* HU.
Still, this SQL is simple and helpful in many cases.
*/SELECTDISTINCTio_r.DocumentNo,io_r.IsSOTrx,iol_r.Line,iol_r.MovementQty,io_r.DocStatus,io_s.DocumentNo,io_s.IsSOTrx,iol_s.Line,iol_s.MovementQty,io_s.DocStatusFROMM_Inoutio_rJOINM_InOutLineiol_rONio_r.M_InOut_ID=iol_r.M_InOut_IDJOINM_HU_Assignmenthua_rONhua_r.AD_Table_ID=get_table_id('M_InOutLine')ANDhua_r.Record_ID=iol_r.M_InOutLine_IDJOINM_HUhuONhu.M_HU_ID=hua_r.M_TU_HU_IDJOINM_HU_Assignmenthua_sONhua_s.M_TU_HU_ID=hua_r.M_TU_HU_IDANDhua_s.AD_Table_ID=get_table_id('M_InOutLine')ANDhua_r.M_HU_Assignment_ID!=hua_s.M_HU_Assignment_IDJOINM_InOutLineiol_sONhua_s.Record_ID=iol_s.M_InOutLine_IDJOINM_InOutio_sONio_s.M_InOut_ID=iol_s.M_InOut_IDWHEREtrueANDio_r.DocumentNo='<material receipt document no>'ANDhu.HUStatus='E';/* HUs that were shipped */