cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping

Former Member
0 Kudos

Is it possible to have UDF do the following:

I have a queue e.g.

A

B

C

<ContextChnage>

D

E

F

<ContextChange>

G

H

I basically want the UDF to take all the values of one context and concatenate them together and return the result.

So the result should be.

A B C

<ContextChnage>

D E F

<ContextChange>

G H

Could someone let me know how to do this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mendez,

Use this UDF:

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

int len=a.length;

String temp[]=new String[len];

int k=0;

String val="hai";

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

{

if (!(a<i>.equalsIgnoreCase(ResultList.CC)))

{

val+=a<i>;

}

else

{

temp[k]=val;

k++;

val="";

}

}

temp[k]=val;

k++;

for(int i=0;i<k;i++)

{

result.addValue(temp<i>);

//result.addContextChange();

}

}//end of the function

Put the cache value as context.This would work.

Thanks,

Bhargav.

Note:Award Points if found useful.

Edited by: bhargav gundabolu on Mar 5, 2008 3:52 PM

Edited by: bhargav gundabolu on Mar 5, 2008 3:54 PM

Edited by: bhargav gundabolu on Mar 5, 2008 3:55 PM

Former Member
0 Kudos

hi i tries this and it also gave errors...

is this code plug and play or do I need to edit it in some way... if so please let me know where?

I will award top points as soon as this is solved

Former Member
0 Kudos

Hi,

What was the error that you got.

You need to only copy the code between

public void myudf(String[] a,ResultList result,Container container){ and the closing brace(}//end of the function) ignoring these.

In the secoond line put len between two square braces ( [] ).

Thanks,

Bhargav

Former Member
0 Kudos

Yes I tried it but I got the following error:

Source code has syntax error:

/usr/sap/XXX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc200ca30eac911dcb3df000d60de069c/source/com/sap/xi/tf/_MM_Back_2_.java:98: 'class' or 'interface' expected public static void main(String[] args) throws Exception{/!_$ClNRep_/_MM_Back_2_ st = new /!_$ClNRep_/_MM_Back_2_(); st.testExecute(); } ^

/usr/sap/XXX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc200ca30eac911dcb3df000d60de069c/source/com/sap/xi/tf/_MM_Back_2_.java:99: 'class' or 'interface' expected } ^

/usr/sap/XXX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc200ca30eac911dcb3df000d60de069c/source/com/sap/xi/tf/_MM_Back_2_.java:100: 'class' or 'interface' expected ^ 3 errors

Former Member
0 Kudos

Hi,

This is because you might have not removed the last closing brace ( '}' ).remove that and test it.

This error occurs when you have opening which is not closed properly at the end or if any extra closing braces occur.

In this UDF the first opening brace should occur after the String temp[] decleration statement.

and after the result.addValue(temp); there should be only one closing brace.

Thanks,

Bhargav.

justin_santhanam
Active Contributor
0 Kudos

Mendez,

Here you go


StringBuffer sb=new StringBuffer("");
 for(int i=0;i<value.length;i++)
{
	if(!(value<i>.equals("__cC_")) || (i==value.length-1))
	{
	sb.append(value<i>);
	}
	if(value<i>.equals("__cC_") || i==value.length-1)
	{
	result.addValue(sb.toString());
		if(i!=value.length-1)
		{
		result.addContextChange();
		}
	sb=new StringBuffer("");
	}
}

UDF: http://www.flickr.com/photos/23855877@N07/2311960865/sizes/o/

Results:http://www.flickr.com/photos/23855877@N07/2311960861/sizes/o/

raj

Former Member
0 Kudos

I removed the brace at the end and get the following:

Source code has syntax error: /usr/sap/XXX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map43d000e0eace11dc9654000d60de069c/source/com/sap/xi/tf/_MM_Back_2_.java:72: cannot resolve symbol symbol : method equalsIgnoreCase (java.lang.String) location: class java.lang.String[] if (!(a.equalsIgnoreCase(ResultList.CC))) ^

/usr/sap/XXX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map43d000e0eace11dc9654000d60de069c/source/com/sap/xi/tf/_MM_Back_2_.java:88: addValue(java.lang.String) in com.sap.aii.mappingtool.tf3.rt.ResultList cannot be applied to (java.lang.String[]) result.addValue(temp); ^ 2 errors

Former Member
0 Kudos

Raj I tried your code... copied and paste exactly as is and got millions of errors... sorry!

justin_santhanam
Active Contributor
0 Kudos

Mendez,

>Millions of errors?

What do you mean, Have u seen the output? Which I've shown in the URL?

raj.

Former Member
0 Kudos

Sorry Raj... I couldn't log on to that bit... i just did from another oc and corrected it...

Thank you soi much you are a legend

agasthuri_doss
Active Contributor
0 Kudos

Hello Mendez,

You are Right,

Raj is very Strong in mapping and excellent in UDF.

Hello Raj,

Keep it up and thanks a lot for sharing and trouble shooting lot of issues.

Regardsd

Agasthuri Doss

justin_santhanam
Active Contributor
0 Kudos

Hello Mendez,

Thanks for you appreciation. I really appreciate it!

By the way, I'm not legend, there are millions of legend there in our forum. Gabriel( My brother name is also Gabriel ) and Bhargav also Legend. I really appreciate there effort.

raj.

justin_santhanam
Active Contributor
0 Kudos

Dear Doss,

Thanks for the feedback and your support. I will try to keep up the good work.

raj.

Former Member
0 Kudos

Hi,

Sorry for the mistake u need to put a<i> and temp<i> instead of a and temp.Sorry for the miscommunication.

Anyhow good that your problem is answered.

Thanks,

Bhargav

Edited by: bhargav gundabolu on Mar 5, 2008 5:59 PM

Answers (2)

Answers (2)

GabrielSagaya
Active Contributor
0 Kudos

function myudf(String a[],ResultList result,Container container)

{

String temp[];

int k=0;

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

{

if (!(a.equalsIgnoreCase(ResultList.CC)

{

temp[k]=new String[30];

temp[k]=temp[k]+a;

k++;

}

}

for(int i=0;i<k;i++)

result.addValue(temp);

}

Former Member
0 Kudos

Hi I tried this and I am gettign errors... any idea why? does this work for you?

Edited by: Mendez on Mar 5, 2008 2:59 PM

GabrielSagaya
Active Contributor
0 Kudos

function myudf(String a[],ResultList result,Container container)

{

String temp[];

int k=0;

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

{

if (!(a<i>.equalsIgnoreCase(ResultList.CC)

{

temp[k]=new String[30];

temp[k]=temp[k]+a<i>;

k++;

}

}

for(int i=0;i<k;i++)

result.addValue(temp<i>);

}