cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping (Substring)

Former Member
0 Kudos

Hi All,

I am using a standard substring in my message mapping to get the first 4 characters of the incoming text. This work fine except when the incoming text is less than 4. I get an error.

Is there a way that i can accomplish the above despite the length of the word?

Thank you in Advance,

Danny

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Before concatenating the field for 1st 4 chars, please concat the 4 blank spaces with constant and then use substring so it will manipulate with the field value of shorter length also.

Field-->Concat (" ")Constant ---> Substr --->target field

No need of udf to calculate the length of field value

Thanks

Swarup

Edited by: Swarup Sawant on Feb 12, 2008 12:59 PM

Former Member
0 Kudos

Thank you all for the feedback.

Kind Regards,

D

justin_santhanam
Active Contributor
0 Kudos

Swarup,

I think it won't work. If his string length is 3 or more than 3, then ur solution is good. What happens if the input string length is 1 or 2? do u think will it work? Please correct me if I misunderstood ur code..

Danny,

I would say as suggested as Prateek, write a simple UDF and check for the length and return if it's less than length <=4 or substring if length is >4 . If you don't want to write UDF then

Use Stadard functions

Input -


>length--->greater & Constant(4) -


>and -
>If then else-->Output

In if then else then part do substring, else part pass input directlty.

And function Accepts two input, first parameter is output of greater, second parameter is Constant(4).

Hope it helps!

raj.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Danny,

UDF can be written for achieving your functionality but if you want to use Graphical functions only, you can map it this way.

Use the Length function and obtain the length of the Field which is then checked with the Less function by putting Constant 4. It so happens that if this is true, you map Field directly to the Target field else use the Substring function and map that.

Basically you make use of the if-then-else function.

If the length is less than 4, then you simply map the Field with the target, else you use Substring.

Hope this helps.

Regards,

Lavita.

P.S. Do reward points if the information is useful.

Former Member
0 Kudos

Hi,

Try to do some own UDF,take this eg if neccessary.

public class SubStringDemo {

public static void main(String[] av) {

String a = "Java is great.";

System.out.println(a);

String b = a.substring(5); // b is the String "is great."

System.out.println(b);

String c = a.substring(5,7);// c is the String "is"

System.out.println(c);

String d = a.substring(5,a.length());// d is "is great."

System.out.println(d);

}

}

regards

sasi

award pts if useful

prateek
Active Contributor
0 Kudos

Write a small udf to check the length. Use it in mapping. If the length less than 4, then map directly, else use substring

Regards,

Prateek