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

Save Variables As Global Array

Hi all,

 

My job like this:

tMap -------R180----> tlogow-------itreate---->tFlowToIterate

         -------R200----->tlogrow------itreate------>tFlowToIterate----------->tjava

 

The problem: How can I save multiple variables come from tMap(R180) in one var as array

and then call these variables in tjava(R200)

 

For example the input to tmap:

R180;1;tt

R180;2;uu

R180;3;yy

R200;2;kfefeeuk

R200;1;refg

R200;3;ertyu

 

I tried to link through the ID in R180 and R200, tjava output:

tt:refg

uu:kfefeeuk

yy:ertyu

 

 

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Thanks billimmer for reply, I put the ArrayList into the globalMap like this:
globalMap.put("myList", myArrlist);

and get it whenever you want it
ArrayList<??> ml = (ArrayList<??>)globalMap.get("myList");

View solution in original post

2 Replies
billimmer
Creator III
Creator III

Here is a tjavaflex that I use to put fields from a main input into and array for use later in a tloop.  Notice that I use a different variable for each field I collect.  In the below case I'm processing an entire line of text with no fields, but this could be modified to work with any schema from the main flow.

 

Start code:

int i = 0;
String s;

boolean myStart = false;
boolean myRecCntFlag = false;

int startPos;
int endPos;
String subS;

List<String>  listFilenames = new java.util.ArrayList<String>();
List<Boolean> listmyRecCntFlags = new java.util.ArrayList<Boolean>();

globalMap.put("myFilename", "nothing");
globalMap.put("myRecCntFlag", false);

 

Main Code:

s = row7.line;

if(!myStart) {
 if(s.contains("^^^BREAK-ETL-BEGIN")) {
  myStart = true;
  
  // IndexOf returns -1 if there nothing is found
  startPos = s.indexOf(":");
  endPos = s.indexOf(":", startPos + 1);
  //System.out.println(startPos + "-" + endPos);
  if(startPos>=0 && endPos>=0 && startPos < endPos) {
   subS = s.substring(startPos + 1, endPos);
  } else {
   subS = Integer.toString(i);
  }
  
  subS = subS + ".sql";
    
  listFilenames.add(subS);
  globalMap.put("myFilename", subS);
  s = "";
  i++;
 }
} else {
 if(s.contains("^^^BREAK-ETL-END^^^")) {
  listmyRecCntFlags.add(myRecCntFlag);
  globalMap.put("myRecCntFlag", myRecCntFlag);

  myStart = false;
  myRecCntFlag = false;
  s = "";
 } else {
  if(s.contains("RecCnt")) {
   myRecCntFlag = true;
  }
 }
}

row9.line = s;

 

End Code:

globalMap.put("myManafestFilenames", listFilenames);
globalMap.put("myManafestRecCntFlags", listmyRecCntFlags);

 

 

Then I loop through this code using tloop:

Declaration: int i=0

Condition: i<((List)globalMap.get("myManafestFilenames")).size()

Iteration: i++

Anonymous
Not applicable
Author

Thanks billimmer for reply, I put the ArrayList into the globalMap like this:
globalMap.put("myList", myArrlist);

and get it whenever you want it
ArrayList<??> ml = (ArrayList<??>)globalMap.get("myList");