Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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:
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.
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
.
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:
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.
Perfect, thanks worked like charm.
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.
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.
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.
thank you all for help.