turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Home
- :
- Talend Category
- :
- Community Discussions
- :
- Design and Development
- :
- Tmap adding sequence number

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2017
07:16 AM

09-21-2017
07:16 AM

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.

Solved! Go to Solution.

Labels:

2 ACCEPTED SOLUTIONS

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2017
10:19 AM

09-21-2017
10:19 AM

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.

TRF

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
06:30 AM

11 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2017
07:46 AM

09-21-2017
07:46 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2017
09:13 AM

09-21-2017
09:13 AM

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

.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2017
10:19 AM

09-21-2017
10:19 AM

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.

TRF

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
03:35 AM

09-22-2017
03:35 AM

Perfect, thanks worked like charm.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
04:35 AM

09-22-2017
04:35 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
05:32 AM

09-22-2017
05:32 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
06:30 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
06:57 AM

09-22-2017
06:57 AM

thank you all for help.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
07:03 AM

09-22-2017
07:03 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
07:14 AM

09-22-2017
07:14 AM

@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).

TRF

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-22-2017
08:10 AM

09-22-2017
08:10 AM

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.