I want to run job using tloop component for 5 times and want to increase a context variable by one for each loop. The context variable is a integer and it,s initial value 1.
I am increasing the context variable by tjava component it is not being updated for next loops. hence getting value 1 for every loop. please find the screen shot.
I have also tried with globalMap.put()
@TRF , I don,t want to pass the variable to parent job . I want the get my incremented context varible within same job. please check my screenshots
What @TRF said is good advice, but it might not have been very clear. You need to pass the value of the context variable TO the child job and OUT of the child job. Everything that is initiated within the child job will be reinitialised for every time it is run. You cannot expect the values to be held between runs. As such, by sending an initial value in, incrementing and then returning it, you can achieve your goal.
As ab example, lets say you have a context variable called myValue. If you set myValue to 0 in a tJava before your tLoop in your parent job. Then pass the value to the child job's myValue context using the tRunJob config. Now every time that job is fired, it will have the current value of the myValue variable passed to it. Now all you need to do is use a tBufferOutput in your child job to pass the newly amended value out of the child job. Then you could use a tJavaFlex to set the parent job's myValue context variable to the value passed out by the child job. Then, in the next iteration that value will be passed back to the child job.
I think @rhall_2_0 have understand by requirement . but even i am unable to get the required my output.
for every loop i want to load a csv file with the incemented value . I am able to incement value in tjavaflex but
for every loop it is again initialises to the default value i.e one . hence i am getting only 2 as incemented value for each loop.
please find the export if you can import in ur talend it will be better . it is a simple job. please find the sample file as well
I don't think I have misunderstood the requirement. I think you are stuck with the flow of data. The context variable will always reset because you are initiating a new variable with every instantiation of the child job. As such, to keep the value, you need to pass the value out of the job (using the tBufferOutput) and use that value to set the value of a context variable defined in your parent. Then use that parent context variable to pass back to the child job. Use it to set the initial state of the child job's context variable which is ultimately passed out.
@rhall_2_0 , I have said u understood the problem not misunderstood.
I have implement the same thing as u said. but tloop is again setting it to default value so there is no point if passing value from child to parent.
I have passed variable fro child to parent but tloop is again setting variable to default one.
I feel it,s a bug in talend... because it should not reset context variable while looping.
Sorry, I must have misread what you put. I'm having a bit of a busy day today :-)
Can you post a screenshot of your tRunJob config for your child job and where you return the value from the child job. There are a couple of things that this is likely to be, but it is difficult to identify quickly without seeing the state of the job. Once I have seen these images, I may ask for more. Please check the result returned by the child job by including a tLogRow so you can see what is returned.
I have included my workflows and sample file in the above chat. You can import this into your talend. I have also included the screen shot at the beginning of this chat.
I have tried all possible scenarios as you are telling.
I think your child job seems to be OK - you are setting the seqrun from parent job to +1 every time. You need to pass the incremented seqrun value from parent so that child can add +1 to the incremented value. what i would suggest is
-> In trunjob uncheck "Transmit Whole Context" and create a context Param and include the "context.runseq" from Child and set its value to globalMap variable "CURRENT_ITERATION" .
-> Makes sure the runseq variable is declared as Integer.
Hope it will work. Thanks.