Six Stars

Print variables from inside tMap

I have a situation on the picture. How can I print out variable that was created in a tMap? Untitled.png

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: Print variables from inside tMap

I am confused by this. Why do you want to print them out in the tJavaRow without passing them to the tJavaRow? What is the issue with supplying them to the tJavaRow? The reason I ask is that you will not be able to achieve this without seriously compromising the "timing" of the flow of data. If you have 100 rows being processed by the tMap, you cannot assume that when the flow gets to the tJavaRow for row 1, that the value in the Var.var1 will be valid for row 1. It may very well be processing row 100 at that point, or may have finished.

 

"Row" links and "Iterate" links work in different ways and what you are wanting would require an "Iterate" link. Unfortunately tMap components do not supply these.

 

Now, you can use some Java and extend the first solution I sent you to achieve this, but it really sounds like an awful lot of work to achieve something for a reason I cannot fathom with the information you have given. But here is the approach you could use to solve this if you do need it.....

 

1) Create a routine method similar to the one I gave, but this time load the Var variable to a HashMap with a "key" which is unique in your dataset. The HashMap should be available to the whole routine.

2) Create another routine method which will return the value of the HashMap element when supplied the correct "key"

3) In your tJavaRow call the second method (see above) and supply the "key" field. This will return the value for your Var that relates to that particular datarow.

 

As you can see, all your are really doing here is circumnavigating the normal flow in order to do something that would be easier done by simply passing the value.

 

What is the reason that it needs to be done this way?

Rilhia Solutions
14 REPLIES
Twelve Stars

Re: Print variables from inside tMap

I'm not sure I entirely understand this requirement, but if you are trying to simply print the value of a variable and use it in the tMap, you could try a little trick with a routine. For example....

 

public static String printStringValue(String data){
     System.out.println("My variable:"+data);
     return data;
}

Not the most elegant of methods, but it will works for Strings. Just create a new routine and add the above code. Then call that routine in your tMap when you use the variable. It will pass it back to the tMap untouched and print out to the output window.

Rilhia Solutions
Six Stars

Re: Print variables from inside tMap

please explain your scenario briefly.....

Six Stars

Re: Print variables from inside tMap

I have a tMap and inide I created some variables(in the middle column), Now I would like to print out those variable with tjava row?

Twelve Stars

Re: Print variables from inside tMap

The code I have given you is intended to be used when you use your tMap variables. So when you create them in the box in the middle, you will either use them in  further variables or in the output. With the method I have given you above (for Strings only) you can use your variables and print them out. For example, if you are concatenating as String in your tMap variable, it might look like this.....

 

row1.val1 + "_"+row1.val2

The above variable might be called "concatString". You may want to output that to the job AND see what it holds. With the method I have given you, you can simply add this code to your output column....

 

routines.MyTalendRoutines.printStringValue(Var.concatString)

I've assumed the name of the routine as "MyTalendRoutines".

Rilhia Solutions
Six Stars

Re: Print variables from inside tMap

Can you create an example job, export it and upload it ?

Twelve Stars

Re: Print variables from inside tMap

Take a look at the attached job.....

Rilhia Solutions
Six Stars

Re: Print variables from inside tMap

Can you have a look at this pictures and I have a question at the bottom. This is from the example you sent me.

variable to printvariable to printI would print var1 in this tJavaRow, is that possible?I would print var1 in this tJavaRow, is that possible?

 

Twelve Stars

Re: Print variables from inside tMap

Maybe I have assumed you want to do something a little more complicated. All you need to do is add ....

 

Var.var1

...to your out12 newColumn expression. Then in your tJavaRow just use the following code....

System.out.println(input_row.newColumn);

The example I gave you enables you to print the value of your variable to the output from within your tMap. This is useful in debugging. I assumed that is what you wanted this for

Rilhia Solutions
Six Stars

Re: Print variables from inside tMap

Is it possible to print

Var.var1

without passing it to the out12 newColumn expression ?

Twelve Stars

Re: Print variables from inside tMap

Yes, in the first way I showed you

Rilhia Solutions
Six Stars

Re: Print variables from inside tMap

I mean not inside the tMap but inside tJavaRow?

Twelve Stars

Re: Print variables from inside tMap

I am confused by this. Why do you want to print them out in the tJavaRow without passing them to the tJavaRow? What is the issue with supplying them to the tJavaRow? The reason I ask is that you will not be able to achieve this without seriously compromising the "timing" of the flow of data. If you have 100 rows being processed by the tMap, you cannot assume that when the flow gets to the tJavaRow for row 1, that the value in the Var.var1 will be valid for row 1. It may very well be processing row 100 at that point, or may have finished.

 

"Row" links and "Iterate" links work in different ways and what you are wanting would require an "Iterate" link. Unfortunately tMap components do not supply these.

 

Now, you can use some Java and extend the first solution I sent you to achieve this, but it really sounds like an awful lot of work to achieve something for a reason I cannot fathom with the information you have given. But here is the approach you could use to solve this if you do need it.....

 

1) Create a routine method similar to the one I gave, but this time load the Var variable to a HashMap with a "key" which is unique in your dataset. The HashMap should be available to the whole routine.

2) Create another routine method which will return the value of the HashMap element when supplied the correct "key"

3) In your tJavaRow call the second method (see above) and supply the "key" field. This will return the value for your Var that relates to that particular datarow.

 

As you can see, all your are really doing here is circumnavigating the normal flow in order to do something that would be easier done by simply passing the value.

 

What is the reason that it needs to be done this way?

Rilhia Solutions
Six Stars

Re: Print variables from inside tMap

I thought this could be done easily. I thought that I saw how to do this somewhere on the internet. Thank for your reply.

Twelve Stars

Re: Print variables from inside tMap

I think you are confusing tMap variables with globalMap variables. You get globalMap variables created when you use a tSetGlobalVar and tFlowToIterate components. globalMap values are available anywhere in the job after they have been set. However when used with a tFlowToIterate, they are only valid for the iteration following the tFlowToIterate

Rilhia Solutions