Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
SceniX
Contributor
Contributor

Split tjavarow from 1 input in multiple rows

Hey, this is my first time that i need help 😄

i got a Function how give out this String as a unlimited String sperated by ; and ending with line feed. I used this Code to Break out the strings in Multipli rows looks like these:

input1=

"

18;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

19;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

1;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

19;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

18;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

195;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

145;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n

"

These String are devided by this Script:

String input = input1; // Assuming your input string is available in a field named "inputString"

String[] lines = input.split("\\n"); // Split the input into individual lines

for (String line : lines) {

  String[] fields = line.split(";"); // Split each line into fields based on the semicolon separator

  String field1 = fields[0]; // Retrieve the first field

  output_row.newColumn = fields[0];

  String field2 = fields[1]; // Retrieve the second field

  output_row.newColumn1 = fields[1];

  String field3 = fields[2]; // Retrieve the third field

  output_row.newColumn2 = fields[2];

  String field4 = fields[3]; // Retrieve the fourth field

  output_row.newColumn3 = fields[3];

  String field5 = fields[4]; // Retrieve the fifth field

  output_row.newColumn4 = fields[4];

  // Perform further processing or output the parsed fields as needed

  System.out.println("Field 1: " + field1);

  System.out.println("Field 2: " + field2);

  System.out.println("Field 3: " + field3);

  System.out.println("Field 4: " + field4);

  System.out.println("Field 5: " + field5);

}

If i try to give out to output_row i only get the last line of these output.

Can somone Help me or move my mind i a direction how to do it?

DB INPUT ==> TJAVAROW ==> tmap all rows how a given by

TJAVAROW from these Output

Thank you

SceniX

Labels (3)
1 Solution

Accepted Solutions
anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @Patrik Kajs​ 

 

I believe it's not possible to "create" rows from tJavaRow, because the code you write there only affects the "main" part of component execution. So any loop you define there will iterate over a single row and that's why you're getting only the last record of your input data. It is iterating over all the records on the input, but it only outputs data after completing the loop and then there's only the last values recovered during loop.

 

However, you can achieve this using tJavaFlex by spliting your code on Start, Main and End sections:

 

Start code:

 

String input1 = "18;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n19;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n1;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n19;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n18;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n195;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n145;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n";

 

String input = input1; // Assuming your input string is available in a field named "inputString"

 

String[] lines = input.split("\\n"); // Split the input into individual lines

 

for (String line : lines) { //just the loop header here to create rows for each record on the input data

 

Main code:

 

//now we can split the columns and output them, remember to replace the output_row by the corresponding output row name connecting tJavaFlex to next component

 

 String[] fields = line.split(";"); // Split each line into fields based on the semicolon separator

 

 String field1 = fields[0]; // Retrieve the first field

 

 row1.newColumn = fields[0];

 

 String field2 = fields[1]; // Retrieve the second field

 

 row1.newColumn1 = fields[1];

 

 String field3 = fields[2]; // Retrieve the third field

 

 row1.newColumn2 = fields[2];

 

 String field4 = fields[3]; // Retrieve the fourth field

 

 row1.newColumn3 = fields[3];

 

 String field5 = fields[4]; // Retrieve the fifth field

 

 row1.newColumn4 = fields[4];

 

 // Perform further processing or output the parsed fields as needed

 

 //System.out.println("Field 1: " + field1);

 

 //System.out.println("Field 2: " + field2);

 

 //System.out.println("Field 3: " + field3);

 

 //System.out.println("Field 4: " + field4);

 

 //System.out.println("Field 5: " + field5);

 

End code:

 

} //yes, just close the loop here

 

I hope this helps you.

Best regards,

 

Anselmo

View solution in original post

1 Reply
anselmopeixoto
Partner - Creator III
Partner - Creator III

Hi @Patrik Kajs​ 

 

I believe it's not possible to "create" rows from tJavaRow, because the code you write there only affects the "main" part of component execution. So any loop you define there will iterate over a single row and that's why you're getting only the last record of your input data. It is iterating over all the records on the input, but it only outputs data after completing the loop and then there's only the last values recovered during loop.

 

However, you can achieve this using tJavaFlex by spliting your code on Start, Main and End sections:

 

Start code:

 

String input1 = "18;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n19;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n1;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n19;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n18;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n195;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n145;25.05.2023;64;24.05.2023;2023-05-24 13:03:37.390\n";

 

String input = input1; // Assuming your input string is available in a field named "inputString"

 

String[] lines = input.split("\\n"); // Split the input into individual lines

 

for (String line : lines) { //just the loop header here to create rows for each record on the input data

 

Main code:

 

//now we can split the columns and output them, remember to replace the output_row by the corresponding output row name connecting tJavaFlex to next component

 

 String[] fields = line.split(";"); // Split each line into fields based on the semicolon separator

 

 String field1 = fields[0]; // Retrieve the first field

 

 row1.newColumn = fields[0];

 

 String field2 = fields[1]; // Retrieve the second field

 

 row1.newColumn1 = fields[1];

 

 String field3 = fields[2]; // Retrieve the third field

 

 row1.newColumn2 = fields[2];

 

 String field4 = fields[3]; // Retrieve the fourth field

 

 row1.newColumn3 = fields[3];

 

 String field5 = fields[4]; // Retrieve the fifth field

 

 row1.newColumn4 = fields[4];

 

 // Perform further processing or output the parsed fields as needed

 

 //System.out.println("Field 1: " + field1);

 

 //System.out.println("Field 2: " + field2);

 

 //System.out.println("Field 3: " + field3);

 

 //System.out.println("Field 4: " + field4);

 

 //System.out.println("Field 5: " + field5);

 

End code:

 

} //yes, just close the loop here

 

I hope this helps you.

Best regards,

 

Anselmo