cancel
Showing results for 
Search instead for 
Did you mean: 

how to pick up the last value of the input string

Former Member
0 Kudos

Hi there,

I have a requirement in which I have to pick up the last value of the input string.

I don't know the field length, it could be 10 line, it could be 4 line and it could be even 1 line.

Another problem is that the field contains all the alphanumeric values so the sort function is not working.

I believe I need to write a UDF but not sure exact what and how.

Can some body please help me solving this issue.

Input.

1.Abc

2.abc123atxx.com

3.(980)771-2341

4.

5.518VR50V58AD10DSAYBDSAFDSIEGHA:1

In that case I only need to pickup the last value i.e. 518VR50V58AD10DSAYBDSAFDSIEGHA:1

Output

518VR50V58AD10DSAYBDSAFDSIEGHA:1

Note:

1. Length is unknown

2. Alphanumeric data

Thanks,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi iqbal,

u can write the following UDF.it should work fine.

only 1 input is enough

queue type/Execution type = Queue;



int length = var1.length -1;
result.addValue(var1[length]);

regards

biplab

Former Member
0 Kudos

Thanks biplab das,

It is working fine.

I already gave you full Marks

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You can write a UDF.

int Length=Integer.parseInt(SourcevalueLength);

int requiredLength=Integer.parseInt(RequiredLength);

if(Length<=requiredLength)

return(SourceValue);

else

return SourceValue.substring((Length-requiredLength),Length);

just a heads up.

Cheers,

Karthick

Former Member
0 Kudos

Hi karthick Lakkar,

Thanks for your quick response but unfortunately I am getting mapping exception.

What I did is create a UDF with 2 input

INPUT

a string

b string

and then this code

int Length=Integer.parseInt(a);

int requiredLength=Integer.parseInt(b);

if(Length<=requiredLength)

return(a);

else

return a.substring((Length-requiredLength),Length);

I am wondering about the input as well.

At present I am doing

KTEXT + KTEXT --- UDF

+ does represent concat, means same input will go to the UDF

This is the error which I am getting

Exception:[java.lang.NumberFormatException: For input string: "Kevin Farrar"] in class com.sap.xi.tf._MM_XXXXXXXXXXXXXX_ method calculate[Kevin Farrar, Kevin Farrar, com.sap.aii.mappingtool.tf7.rt.Context@6dbf19db]

Former Member
0 Kudos

Hi,

Give 3 inputs.

1. Source value.

2. Source length.

3.Required length (last 7 chars, so give 7).

public String LastSubstring(String SourceValue, String SourcevalueLength, String RequiredLength, Container container) throws StreamTransformationException{

Cheers,

Karthick

Former Member
0 Kudos

Hi karthick Lakkar...

I am bit confused about the 3 point.

public String calculate(String SourcevalueLength, String RequiredLength, String SourceValue, Container container) throws StreamTransformationException

{

int Length=Integer.parseInt(SourcevalueLength);

int requiredLength=Integer.parseInt(RequiredLength);

if(Length<=requiredLength)

return(SourceValue);

else

return SourceValue.substring((Length-requiredLength),Length);

}

I am confused about the input now.

Could you please tell me the input which connects with the UDF

at present I am connecting all the 3 inputs of KTEXT to UDF.

Please advice.

Thanks

Former Member
0 Kudos

Hi,

If KTEXT is your source field. You need to taje ex: last 5 chars from the source value.

First input to UDF will be KTEXT.

2nd input would be KTEXT-->Length

3rd input would be constant (5). Suppose you need to take last 5 chars.

Cheers,

Karthick