I wish to split an order to generate multiple work orders depending on the Optimum Lot Quantity (OLQ) meaning the sum the quantity in a work order would not exceed the OLQ.
Here is my order Table sample data:
Order Item Product Qty
OR-01 I-001 PRD-01 70
OR-01 I-001 PRD-02 15
OR-01 I-001 PRD-03 55
The OLQ for this order is 30 and therefore the sum of the qty of work order should not exceed 30. But the work order can has multiple products of the same item (item is the parent for product).
Here is how I wish to split this order to create work orders on the basis of OLQ:
Order WorkOrd Seq Item Product Qty
OR-01 WO-0001 001 I-001 PRD-01 30
OR-01 WO-0002 001 I-001 PRD-01 30
OR-01 WO-0003 001 I-001 PRD-01 10
OR-01 WO-0003 002 I-001 PRD-02 15
OR-01 WO-0003 003 I-001 PRD-03 5
OR-01 WO-0004 001 I-001 PRD-03 30
OR-01 WO-0005 001 I-001 PRD-03 20
Note that WO-0003 has three products with 10, 15 and 5 amounting to 30. Also note that the last Work order WO-0005 has only 20 qty (which is the remaining).
In the attachment I have highlighted the work orders in different colors for easy understanding.
Kindly help me to achieve this.
Thanks in advance.
I dont like working with cursors, but sometimes they are handy.
Here you go: