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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Tmap adding sequence number

Hi,

 

can i please request help on how to achive the below result using tmap

 

Input

A134

A134

A134

B235

B235

C129

 

Output

A134-01

A134-02

A134-03

B235-01

B235-02

C129-01

 

Thanks for your help.

 

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Hi, 

The error is probably due to the datatype of the variable which should be an integer to receive the result of Numeric.sequence.

However, as you expect to keep leading 0 on indices, keep the var datatype as String and replace the formula by this one:

("100" + Numeric.sequence(row1.input, 1, 1)).substring(2) 

Here is the tMap configuration:

0683p000009Lqpa.png

And here is the result:

Starting job test at 18:13 21/09/2017.

[statistics] connecting to socket on port 3834
[statistics] connected
A134-01
A134-02
A134-03
B235-01
B235-02
C129-01
[statistics] disconnected
Job test ended at 18:13 21/09/2017. [exit code=0]

Hope this helps.

View solution in original post

11 Replies
Anonymous
Not applicable
Author

This one is quite straight forward. In your tmap use a tMap variable (from the section in between the input and output). In that variable put the following code....

Numeric.sequence(row.input, 1, 1)

I've used row. input to represent your input column. What this does is create a sequence for each different input.

Given it a go and let us know if it works for you
Anonymous
Not applicable
Author

thanks, sorry i am new to talend, is it possible to give step by step instruction or screenshot of tmap configuration, i get this error

.0683p000009LqpB.jpg

 

 

TRF
Champion II
Champion II

Hi, 

The error is probably due to the datatype of the variable which should be an integer to receive the result of Numeric.sequence.

However, as you expect to keep leading 0 on indices, keep the var datatype as String and replace the formula by this one:

("100" + Numeric.sequence(row1.input, 1, 1)).substring(2) 

Here is the tMap configuration:

0683p000009Lqpa.png

And here is the result:

Starting job test at 18:13 21/09/2017.

[statistics] connecting to socket on port 3834
[statistics] connected
A134-01
A134-02
A134-03
B235-01
B235-02
C129-01
[statistics] disconnected
Job test ended at 18:13 21/09/2017. [exit code=0]

Hope this helps.

Anonymous
Not applicable
Author

Perfect, thanks worked like charm.

Anonymous
Not applicable
Author

one small problem how do we deal with result that go beyond sequence 9

for example below 

 

right now i am getting result as  below.

A134-01

A134-02

A134-03

A134-04

A134-05

A134-06

A134-07

A134-08

A134-09

A134-010

A134-011

 

and i want output after 9 should be like

A134-10

A134-11

 

instead of 

A134-010

A134-011

 

Thnaks for yoru help.

 

 

Anonymous
Not applicable
Author

What happens if the number gets to 3 digits? I take it you don't want it truncated?

This method will help. Create a routine and add this method to the routine. Then you can use it in place of the code you are currently using.

   public static String returnZeroPrePaddedNumber(int length, String number){
    	String returnVal = number;
    	
    	while(returnVal!=null&&returnVal.length()<length){
    		returnVal = "0"+returnVal; 
    	}
    	
    	return returnVal;
    }

As an example of how to use it, at the moment you are using this.....

("100" + Numeric.sequence(row1.input, 1, 1)).substring(2) 

If you create a routine called "MyUtils", and add the method I gave you to it, you would use this code....

routines.MyUtils.returnZeroPrePaddedNumber(2, ("" + Numeric.sequence(row1.input, 1, 1))) 

This code takes an integer parameter which tells it how many digits are required as a minimum. The second parameter is a number as a String. If that number is less than the minimum number of digits, it adds 0s to the beginning until the minimum is reached. If the minimum is matched by the number (or the number has more digits), nothing happens to it.

TRF
Champion II
Champion II

Or just replace the expression by this one:

(""+(100 + Numeric.sequence(row1.input, 1, 1))).substring(1) 

And if you want 3 leading 0, replace 100 by 1000 and so on.

Anonymous
Not applicable
Author

thank you  all for help.

Anonymous
Not applicable
Author

That doesn't really work @TRF. That solution requires a different expression depending on the length of the number returned by the sequence.