One Star

LPAD/RPAD in tMap expression

Hi,
I want to reproduce the lpad and rpad functions of SQL in a tMap expresion but I can't find the correct way to do that.
Any help would be apreciated,
Regards,
Khor
8 REPLIES
One Star

Re: LPAD/RPAD in tMap expression

Hi Khor
You can try StringHandling.LEFT() and StringHandling.RIGHT().
Or create routine and define custom method in TOS.
Regards,
Pedro
One Star

Re: LPAD/RPAD in tMap expression

Hi pedro,
with lpad, for example if the number of characters is higher than the length of the string, it will put spaces (that's what I'm using it for). Like in this example:
lpad('ASD',9) -> 'ASD '
Would this java functions do the same, or just throw me a exception because the string is not long enough?
Thanks,
Khor.
One Star

Re: LPAD/RPAD in tMap expression

Hi
  public static String lpad(String s, int n, String replace) {
while (s.length() < n) {
s = replace+s;
}
return s;
}
public static String rpad(String s, int n, String replace) {
while (s.length() < n) {
s = s+replace;
}
return s;
}

Type this into custom routine.
Regards,
Pedro
One Star

Re: LPAD/RPAD in tMap expression

Hi pedro,
How to call this routine in tMap expression?
Regards,
Khor
One Star

Re: LPAD/RPAD in tMap expression

Hi Khor
You can find it in Expression Builder.
Regards,
Pedro
One Star

Re: LPAD/RPAD in tMap expression

Hi,
This is the first place where I lookd it for, but the routines are not there.
I have to do something to import the routines in the tMap?
Regards,
Khor
One Star

Re: LPAD/RPAD in tMap expression

Hi Khor
That means you didn't create routine correctly.
You can get more info about custom routine in document.
Regards,
Pedro
One Star

Re: LPAD/RPAD in tMap expression

Hi,
Thank for you help.
Regards,
Khor