One Star

How to assign a context variable to loop condition from within loop

Hi all,
I still have the following issue and can't figure out of how to solve it.
In the first subjob I create all relevant data for the further subjobs, including the calculation of the number of loops the data later should be processed on. Each row created contains the actual salary values of an employee. The basic row will then be multiplied for budgeting and forecast reasons max. 25 times(=months) or less if an employee leaves before the end of the budgeting period. This is done in the second subjob.
Basically the whole thing is working with the exception, that the context variable (= max. amount of loops) seems always to be taken from the last employee in the list. To work correctly the context variable should be taken per employee and assigned a value for each iteration of the loop.
Actually, if the calculated number of loops is 25, the loop will run 25 times for all the employees. If the calculated number of loops is 6 then it will run 6 times per employee for all employees.
How can I assign the "To"-variable of the loop with the calculated value for the number of loops for every employee individually? The "To"-Value of the loop contains the variable "context.iterationCount", it's just the value of the context variable which is wrong. The loop should run for example like this:
- 1. employee  --> 25 times
- 2. employee  --> 25 times
- 3. employee  --> 4 times
==> This should result in a total number of rows of 54, with the actual setting it does it only 12 times
- 1. employee  --> 25 times
- 2. employee  --> 25 times
- 3. employee  --> 4 times
- 4. employee  --> 25 times
==> This should result in a total number of rows of 79, with the actual setting it does it 100 times
Below is the printscreen of the job design (using TOS 5.5.1)
 
Hope, anybody could give me a hint of how to make it work correctly.
Regards, Felix
3 REPLIES
Four Stars

Re: How to assign a context variable to loop condition from within loop

Based on the screenshot and the description above, I am not clear how you are calculating context.iterationCount variable..
- Are you using some context variable like context.iterationCount  = context.iterationCount +1 to increment the count?
- you can have a simple subjob which calculates this context.iterationCount  and use it inside toop for To...
Vaibhav
One Star

Re: How to assign a context variable to loop condition from within loop

Hi Vaibhav
The value that later will be assigned to context.iterationCount is calculated in the first subjob (where the note says "calculation of number of loops"). This value basically is calculated like Date2 (end of period) - Date1 (e.g. today), the result is in months. Like that I get a dataset per employee which looks like that:
employeeNr, value1, value2, ... , iterationCount
All of these datasets are written to the temporary file "tblLohn_outFile". This works absolutely fine.
In the loop I read this temporary File ("tblLohn_inFile"), assign the variable "iterationCount" to tJavaRow_2 and there to context.iterationCount.
The jJavaRow_1 sets context.iterationCount = 1 for the loop to run at least once. In the loop the value of context.iterationCount then should be changed to whatever value is read from the file "tblLohn_inFile". Unfortunately, TOS seems to read all employees first and the assigning the value of the last read employye to context.iterationCount and therefore iterating all employees with this value (see examples in previous post), which is wrong.
How can I make TOS read and assign the value for employee1, iterate it x-times, then read and assign the value for employee2, iterate it y-times, etc.?
Regards,
Felix
Four Stars

Re: How to assign a context variable to loop condition from within loop

Hi Felix,
I think you will need iterate component after tLoop.. or 
 In the loop the value of context.iterationCount then should be changed to whatever value is read from the file "tblLohn_inFile". 
>> if this is the case, then loop element can't be before reading the file, it needs to be next to the file...

Vaibhav