Ha Dominik,
Good that you're making some progress
I have a few remarks, before I come to your problem.
When I see this code, I think you'll have to start to make a construction in which you use a table, in which you store per product which sources you'll need. If you have too many products and you'll have to code them all in a case-statement, it will be almost impossible to maintain. And I you create a table in which place one product variant per column and on the rows the different sources, you can indicate with a 0 or a 1 if they are needed or not.
Then you can simple loop over the rows, and perform a check on the content if the cell value is a 1. I think you even already have this table, so that would give something like (I didn't test the code, but only to give an idea):
Code: Select all
Do(
var([valCol], vbValue),
valCol := InList(Label([pVariant], i), 1, 81, .......),
If(
valCol = 0,
Error([Product variant is not found]),
Do(
Repeat(
nRows(refTable_ChState),
If(
Cell(count, valCol, refTable_ChState) = 1,
{Part needed}
If(
Content(In(count, c)) >= Label([Quantity], i),
Do(
Label([t-curqty], in(count, c)) := Label([CurrentBatch],i), {Perhaps you want to use a different label name, so you won't mix them up}
OpenOutput(in(count, c))
)
)
)
)
)
)
)
You use dUniform in the Arrival List (Quantity). So this will create 5 orders to be created. Don't you want to use the dUniform to define how many parts you'll need of a certain type to create a product? I'm not entirely sure what your goal is here. But you might want to set this at the OnExit of the source.
And now the problem. I think the problem is that the label that you set on the Queue is of value 0. So the first product that leaves this queue, the label becomes -1, and the If statement is not true, so the queue is never closed again. You could use a "Trace" to check this:
Code: Select all
Do(
Trace([Variant], Label([Pvariant], i), [Batch size:], Label([CurrentBatch],i)),
Case(
InList(Label([Pvariant], i), 1, 81) + 1,
Do(
{0: the chosen product variant doesn't exist.}
Error([This variant], Label([Pvariant],i), [isn't recognized])
),
Do(
{1: Variant 1}
if(
and(
content(in(2,c)) >= Label([CurrentBatch],i),
content(in(3,c)) >= Label([CurrentBatch],i),
content(in(4,c)) >= Label([CurrentBatch],i),
content(in(5,c)) >= Label([CurrentBatch],i)
),
Do(
Label([t-curqty],In(2, c)) := Label([CurrentBatch],i),
OpenOutput(in(2, c)),
Label([t-curqty],In(3, c)) := Label([CurrentBatch],i),
OpenOutput(in(3, c)),
Label([t-curqty],In(4, c)) := Label([CurrentBatch],i),
OpenOutput(in(4, c)),
Label([t-curqty],In(5, c)) := Label([CurrentBatch],i),
OpenOutput(in(5, c))
)
)
),
Do(
{81: Variant 1}
if(
and(
content(in(10,c)) >= Label([CurrentBatch],i),
content(in(11,c)) >= Label([CurrentBatch],i),
content(in(12,c)) >= Label([CurrentBatch],i),
content(in(13,c)) >= Label([CurrentBatch],i)
),
Do(
Label([t-curqty],In(10, c)) := Label([CurrentBatch],i),
OpenOutput(in(10, c)),
Label([t-curqty],In(11, c)) := Label([CurrentBatch],i),
OpenOutput(in(11, c)),
Label([t-curqty],In(12, c)) := Label([CurrentBatch],i),
OpenOutput(in(12, c)),
Label([t-curqty],In(13, c)) := Label([CurrentBatch],i),
OpenOutput(in(13, c))
)
)
)
)
)
I hope this helps you a bit further to search what is going wrong.
Good luck,
Harry
P.S.
I saw some code on the initialize to close the output. An alternative is (in which I also reset the labels):
Code: Select all
do(
Repeat(
NrIc(c),
Do(
CloseOutput(in(count, c)),
Label([t-curqty] , in(count, c)) := 0
)
)
)