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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Generating multiple rows with tJava

I've read similar threads to this, but nothing that quite answers my question. I'm trying to create a tJava that takes in a table and outputs a table for use by a tmap that will grab data from other tables. I need it to do this:

for (in_row : plan_row) {

    for (int i = in_row.StartYear;i <= in_row.EndYear;i++) {

        out_row.plan_id = in_row.id;
        out_row.year = i;
        makeThisARow(out_row);

    }
}
So input can look like this:
plan_id start_year end_year
1, 2016, 2018

And output like this:
1, 2016
1, 2017
1, 2018

I don't understand how to interact with the components connected to the tJava. How do I tell it 'give me each row' and 'create a row'?

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I think this might lead you in the right direction. You just need to change the code in the tJavaFlex to accommodate your requirements.

https://www.rilhia.com/quicktips/quick-tip-row-multiplication

View solution in original post

6 Replies
Anonymous
Not applicable
Author

I think this might lead you in the right direction. You just need to change the code in the tJavaFlex to accommodate your requirements.

https://www.rilhia.com/quicktips/quick-tip-row-multiplication
Anonymous
Not applicable
Author

rhall_2.0 wrote:
I think this might lead you in the right direction. You just need to change the code in the tJavaFlex to accommodate your requirements.


I found this link earlier and have been trying to solve the problem that was as well, but that gives me a different problem:

//start
for(short i = ((Short)globalMap.get("StartYear")).shortValue();i<((Short)globalMap.get("EndYear")).shortValue(); i++){  
//main
map_row.plan_id = ((Integer)globalMap.get("id")).intValue();
map_row.year = i;
//end
}

How do I get 'i' inside the main.

On a related note, is there some way to tell the IDE to show me the generated code?
Anonymous
Not applicable
Author

That code should work. What error are you getting?

You will see a "code" tab in the bottom left hand corner of the design window. Click that to see the code.
Anonymous
Not applicable
Author

rhall_2.0 wrote:
That code should work. What error are you getting?

You will see a "code" tab in the bottom left hand corner of the design window. Click that to see the code.

Arg, that should have been obvious.

java.lang.NullPointerException, globalMap("StartYear") is null for some reason.
Anonymous
Not applicable
Author

OK, if you followed my tutorial I suspect that is being set in the tMap. Is that correct? Can you take a screenshot of your job and your tMap so that I can see what might be wrong?
Anonymous
Not applicable
Author

I see what it is now...someone actually set a StartYear to null. I thought there was a constraint against that (there should be).
It works now. Thanks for your help!