on 05-26-2008 1:55 PM
Hi,
I need a UDF that concats the values in each context to one string.
Ex.
SUPPRESS
123456
CONTEXTCHANGE
123
654
789
CONTEXTCHANGE
012
321
CONTEXTCHANGE
I want to have the output like this...
SUPPRESS
123456
CONTEXTCHANGE
123, 654, 789
CONTEXTCHANGE
012, 321
CONTEXTCHANGE
I hope you can help me out here.
Thank you!
Sten
Hi,
try this code it will work,
String[] store = new String[1];
for(int i=0;i<var1.length;i++)
{
store[0] = store[0]+var1<i>;
}
result.addValue(store[0]);
var1 is input field containing numbers(123, 654, 789
)
Regards,
Rohit
Reward points if helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you all for your help!
Best regards,
Sten
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create a UDF o type(cache) Context, pass an string to it (your input value)
String final = null;
for(i=0;i<a.length;i++) // a = input array
{
final = final+a<i>;
}
return final;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sten,
Try with this UDF.
/**
* Concatenates values from a queue or context to a String
*
* @param texts values
* @param separators strings to be placed between the values in <code>values</code> to build the final String
* @return concatenation of all the values in <code>values</code>
*/
public static String[] flattenContext(String[] texts, String[] separators) {
StringBuffer contextBuffer;
ArrayList result;
contextBuffer = new StringBuffer();
result = new ArrayList();
for(int i = 0; i < texts.length; i++) {
String text;
text = texts<i>;
if(!text.equals(ResultList.SUPPRESS)) {
if(!text.equals(ResultList.CC)) {
if(contextBuffer.length() > 0) {
int bindersIndex;
bindersIndex = Math.min(i, separators.length - 1);
contextBuffer.append(separators[bindersIndex]);
}
contextBuffer.append(text);
} else if(text.equals(ResultList.CC) && contextBuffer.length() > 0) {
result.add(contextBuffer.toString());
result.add(ResultList.CC);
contextBuffer = new StringBuffer();
}
}
}
result.add(contextBuffer.toString());
return (String[]) result.toArray(new String[result.size()]);
}
Don't forget apply the rewards point !
Regards,
Martin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got some errors...
Do I need to import something?
usr/sapxxx_.java:1373: cannot resolve symbol symbol : variable contextBuffer location: class com.sap.xi.tf._xxx_ contextBuffer = new StringBuffer();
/usr/sapxxx.java:1374: incompatible types found : java.util.ArrayList required: com.sap.aii.mappingtool.tf3.rt.ResultList result = new ArrayList();
/Sten
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.