Two Stars

tMap Pad String with Leading 0

I have been wrestling with this all day.  StringHandling.LPAD(row2.SAP_ID, 6, "0")  tests without error in the Expression Builder however isn't inserting the leading 0's in my field.  Any suggestions?

 

Many thanks!

6 REPLIES
Twelve Stars TRF
Twelve Stars

Re: tMap Pad String with Leading 0

Strange! Did you check using tLogRow or something else? Can you share your component configuration?

TRF
Two Stars

Re: tMap Pad String with Leading 0

1.png

Twelve Stars TRF
Twelve Stars

Re: tMap Pad String with Leading 0

Pad methods are unavailable from TOS 6.4.1, so I can't try but you can do what you want with:

StringHandling.RIGHT("000000" + row2.code, 6) 

It works.

 


TRF
Two Stars

Re: tMap Pad String with Leading 0

Alllllll day.........    Thank you so much!!!!!   That did it!

Twelve Stars TRF
Twelve Stars

Re: tMap Pad String with Leading 0

You're welcome.
Please, don't forget to mark the solution as accepted.
Kudos are also accepted.

TRF
Ten Stars

Re: tMap Pad String with Leading 0

other solution - is add to project routines library StringUtils from Exchange (plus dependencies - Apache common-lang-2.6)

 

it include many useful function and handle null values more proper than some Talend functions

 

 * StringUtils.leftPad(null, *, *)     = null	
 * StringUtils.leftPad("", 3, 'z')     = "zzz"	
 * StringUtils.leftPad("bat", 3, 'z')  = "bat"	
 * StringUtils.leftPad("bat", 5, 'z')  = "zzbat"	
 * StringUtils.leftPad("bat", 1, 'z')  = "bat"	
 * StringUtils.leftPad("bat", -1, 'z') = "bat"	

and use it in tMap

it work

 

 

-----------