Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] How to do for loop in Express code edit in tMap

I am evaluating on Talend DI for my company for efferent Data Integration tool. 
Following is a for loop in my project that using another Data Integration tool.
==============================================
' Fill SegmentArray for each record in process, the SegmentArray is a global array variable
SegeType = Records("R1").Fields("MARKET_SEGEMENT") ' Get the SegeType from the field MARKET_SEGEMENT
SegNumber = 100
for i = 1 to SegCount
  if SegmentArray(i,1) = "" then
    if SegNumber = 100 then
      SegmentArray(i,1) = SegeType
      SegNumber = i
    end if  
  elseif SegmentArray(i,1) = SegeType then
    SegNumber = i
  end if 
next i
SegmentArray(SegNumber,2) = SegmentArray(SegNumber,2) + 1
SegmentArray(SegNumber,3) = SegmentArray(SegNumber,3) + Val(Records("R1").Fields("BILLED_AMT"))
==============================================
I need to find out how to do this kind for loop in tMap Expressiong editor.
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Thank you very much. I found tJavaRow is a good component that allow me to add code for row by row transform.
tFileInputDelimited --->tMap--->tJavaRow--->tFileOutputDelimited.

View solution in original post

4 Replies
Anonymous
Not applicable
Author

Hi, YinZhong..
can you please explain what kind of data that you have and what do you want to achieve using more simple explanations?
this is just my guess, but maybe you can use tFlowToIterate component:
tFlowToIterate iterates on the input data and generates global variables.


0683p000009MACn.png
Anonymous
Not applicable
Author

Hi Shy_Angel:
My project is to map data for bill print. The source record have a field called Market_segment. There are about 10 Market_segment code used in the data file. Other than data map, I also need to create a report that can list summery data for each Market_segment. I create a array to save these data and gathering these data when tMap process each source records. That is why I need to do a for loop in expression code editor inside tMap.
Last time you have helped me to do if statement that is very helpful to my project. This time I want to see if it is possible to do for loop inside tMap or not.
Regards
Yin Zhong
Anonymous
Not applicable
Author

Hi, YinZhong..
tMap is an advanced component that transforms and routes data from single or multiple sources to single or multiple destinations.
since we all here didn't how your data structures look like, what can be done is, creating a Java routine to perform the looping part, something like:
eg:
int[] values = new int;
// Loop over all the elements in the values array
for (int i=0; i<values.length; i++) {
// Do something with values, such as print it
System.out.println( values );
}
OR
eg:
// Find-Max
// Given a non-empty array of ints, returns
// the largest int value found in the array.
// (does not work with empty arrays)
public int findMax(int[] nums) {
int maxCounter = nums; // use nums as the max to start
// Look at every element, starting at 1
for (int i=1; i<nums.length; i++) {
if (nums > maxCounter) {
maxCounter = nums;
}
}
return maxCounter;
}

so no, you cannot do a loop within tMap but yes, you can do the looping either with tLoop/other related components + Java routine to do the processing (eg: creating a loop and store the data inside an array, etc..)
that's the rough idea..
hmm, maybe other members here got a better idea? 0683p000009MACn.png
Anonymous
Not applicable
Author

Thank you very much. I found tJavaRow is a good component that allow me to add code for row by row transform.
tFileInputDelimited --->tMap--->tJavaRow--->tFileOutputDelimited.