
Products
Products
Commercial Products  Downloads
 Solutions
 Support & Services
 Customers
 Company
 Free Trial
Hi,
can i please request help on how to achive the below result using tmap
Input
A134
A134
A134
B235
B235
C129
Output
A13401
A13402
A13403
B23501
B23502
C12901
Thanks for your help.
Solved! Go to Solution.
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 A13401 A13402 A13403 B23501 B23502 C12901 [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 A13401 A13402 A13403 B23501 B23502 C12901 [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.
A13401
A13402
A13403
A13404
A13405
A13406
A13407
A13408
A13409
A134010
A134011
and i want output after 9 should be like
A13410
A13411
instead of
A134010
A134011
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.
thank you all for help.
@rhall_2_0, you're right, you have to know the max expected length to decide if you need to add 10, 100, 1000 and so on.
From my point of view, this is the same when you use MyUtils.returnZeroPrePaddedNumber as you must decide how many leading 0 are expected.
The advantage of this routine is that there is no truncation when the input value is too large (but in that case the result is not exactly what is expected as soon as a fixed length is required).
There is no perfect solution @TRF given the information we have. I just tried to make it a bit more flexible by setting a minimum length. The assumption being that numbers will not need to be truncated, but that you may always want at least 2 digits, for example.