Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Generate a incremental counter based on the key values

Need help with configuring this scenario.
I have Delimited File with ID and data associated with it. And I have DB2 table with ID and SeqNbr as primary key and data columns. While reading Delimited File and inserting to DB2 I need to generate SeqNBr.
Sample of how the Delimited file looks:
ID
-----
ABC
ABC
ABC
XYZ
XYZ
DEF
LMN
LMN
Here is how I need to generate Seq nbr
ID      SeqNBR
-----  ----------
ABC   1
ABC   2
ABC   3
XYZ   1
XYZ   2
DEF   1 
LMN  1
LMN  2
Can you please suggest how to achieve this?
Thanks,

Labels (2)
2 Replies
Anonymous
Not applicable
Author

This can be achieved with a tJavaFlex and a HashMap. It will require a bit of Java code. You need to instantiate the HashMap in the Start Code section. Then in the Main Code section, for every row you will check the HashMap to see if the ID exists in the HashMap. If it does, then you will retrieve the count, add 1 to it and put it back into the HashMap. If it does not exist, you will add it to the HashMap with a value of 1. 
Anonymous
Not applicable
Author

Thank You. I tried using TJavaRow and it worked with little bit of coding.