cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in UDF

Former Member
0 Kudos

Hi ,

I have a string coming in which looks like this

abcdeefghijkl#ksjdakfjasf#ajshdfakl~.

For each occurence of # or ~ I am suppose to introduce a context change and hence create a new line and # oe ~ has to be replaced with ' '.

Can anyone help me out with a udf .

Regards

Deepak

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Sharma,

Check this weblog for some help:

/people/dennys.hsieh/blog/2006/11/20/how-to-parse-xxyyzzaabbcc112233-in-message-mapping

You can use the UDFs which defined in this weblog to solve your issue.

---Satish

Former Member
0 Kudos

Hi ,

The idea is ...for any occurence of these characters in a string I have to introduced

a context change

hence the result should prouce that many lines.

for e.g.

abcd#efgh#ghji~klm

should result in

abcd

efgh

ghij

klm

each in a different line.

besides

I have a queue of such strings

justin_santhanam
Active Contributor
0 Kudos

Deepak,

StringTokenizer st = null;

for(int i=0;i<input.length;i++)

{

st= new StringTokenizer(input<b>[</b>i<b>]</b>,"#~");

while (st.hasMoreElements())

{

result.addValue(st.nextElement());

}

result.addContextChange();

}

For exampe if the input is

abcd#efgh#ghji~klm

1234#56789890432

then you will get the o/p as

abcd

efgh

ghji

klm

<b>[contextchange]</b>

1234

5678

9890

432

Hope it helps!!!!

Best regards,

raj.

Former Member
0 Kudos

Hi Raj,

I am getting errors with this code

is it because i am not using the right arguments .

public void ForamtNrw(String[] a,ResultList result,Container container){

//here is the code you have given

}

justin_santhanam
Active Contributor
0 Kudos

Deepak,

The only difference btw my code and ur argument is a. In my code I used input as the argument, did u changed that.

Change your argument <b>a</b> to <b>input</b> or change the code <b>input</b> to <b>a</b>.

If still u get errors, kindly tell me the error details.

<b>Note:</b> Sorry I forgot to say ,import java.util.*;

Best regards,

raj.

Message was edited by:

Raj

Former Member
0 Kudos

Actually I did change it (input) to a ..

Now the code looks like this

import java.util.*;

StringTokenizer st = null;

for(int i=0;i<a.length;i++)

{

st = new StringTokenizer(a<i>,"#~");

while(st.hasMoreElements())

{

result.addValue(st.nextElements());

}

result.addContextChange();

}

the error that I am getting is illegal start of expression

import java.util.*;

I have just added this line import java.util.*;

at the top of the code inside the fm

justin_santhanam
Active Contributor
0 Kudos

Deepak,

You have to write java.util.; in the top of the UDF Panel u can see Import and textbox.In textbox give java.util.; not in the code.

also give st = new StringTokenizer(a<b>[</b>i<b>]</b>, "#~"); u have given as

st = new StringTokenizer(a,"#~");

Best regards,

raj.

Former Member
0 Kudos

I have tried writing it in the top as well

the error that I get then is

addValue(java.lang.String) in

com.sap.aii.mappingtool.tf3.rt.ResultList cannot be applied to

(java.lang.object)

result.addValue(st.nextElement());

justin_santhanam
Active Contributor
0 Kudos

StringTokenizer st = null;

String var="";

for(int i=0;i<a.length;i++)

{

st= new StringTokenizer(a<b>[</b>i<b>]</b>,"#~");

while (st.hasMoreElements())

{

var =(String)st.nextElement();

result.addValue(var);

}

result.addContextChange();

}

//Note : U used st.nextElements(), in ur UDF see my UDF in the first , actually the result.addValue expects string , hence I typecasted into string. Copy and paste the above code it works pefectly.

Best regards,

raj.

Former Member
0 Kudos

Hi

I replaced st.hasMoreElements with st.hasMoreTokens & st.st.nextElement

with st.nextTokens.

It is working now thanks .

justin_santhanam
Active Contributor
0 Kudos

Deepak,

Its workin with the hasMoreElements() and nextElement() also.

Best regards,

raj.

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Deepak,

Can u give the structure?

Best regards,

raj.