on 05-14-2012 5:08 PM
Hi,
can you help me in getting UDF for splitting payload, The payload gets into one of the field and i need to check if legth of the field is greater than 255 i need to take down to next line.
If next line is also greater than 255 then need to split next part of 255 into another line.
I tried using this UDF and its not workning.
for(;ln>255;pos= pos+255)
{
result.addValue(field[0].substring(pos,pos+255));
if (ln>255)
{
ln=ln-255;
}
result.addValue(field[0].substring(pos));
Thanks,
CH
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chandra,
You don't need two loop control variables (ln and pos), one is enough and it can be controlled by the loop itself. Moreover, you cannot exceed the size of the string with the substring function, since it causes an error. Finally, make sure your input is called "field" and it only has one value - if not, you would need one more loop around your code.
Try with this modification to your original code:
for (int pos = 0; pos < input.length(); pos += 255){
int len = 0;
if (pos + 255 < input.length()) len = 255;
else len = input.length() - pos;
result.addValue(field[0].substring(pos, pos + len));
}
Regards,
Greg
Hi Chandra,
I can see some inconsequence in my code, the input variable is called field once, and input other times. You have to adjust it according to the input variable name. My suggestion is to set the execution type: single values, call the input parameter input and use exactly the following code:
for (int pos = 0; pos < input.length(); pos += 255){
int len = 0;
if (pos + 255 < input.length()) len = 255;
else len = input.length() - pos;
result.addValue(input.substring(pos, pos + len));
}
Regards,
Greg
it worked fine but i need the the header node also to be replicated the number of likes like how many it splits.
suppose the XML payload length is 1020 which it has to be splitted into 4 lines in target field.
which is 1020/255 = 4
My target structure is <Line> 0.... Unbounded and in that <Text> is 0 to 1.
So the expected result is some thing like <Line>
<Text>
<Line>
<Text>
<Line>
<Text>
<Line>
<Text>
By udf i am getting only one which is <Line>
<Text>
You can follow Greg's code already pointed by Amit's reply. In this case change your size = 255 and rest are all pretty much same. Dont forget to use splitbyvalue function after UDF as shown in the screenshot of that thread http://scn.sap.com/thread/3160240
@Inaki: Just few cents... array length is specified without parenthesis ()
Hope that helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Baskar,
When i wrote the parenthesis is for the string length (fieldSource[i].length()), pay attention to the brackets [].
I suppose an array with multiples strings, for different source elements that it will be split in only one step (all values in queue).
I made a "for" for the arrays of strings and another "for" for the string. May be the string could be parsed more efficiently.
Regards.
Hi Chandra,
Another aproximation, with mode all values in queue:
public void splitField(String[] fieldSource,ResultList result,Container container){
int k = 0;
String stringConcatenated = "";
for (int i = 0; i < fieldSource.length; i++){
for (int j = 0; j < fieldSource[i].length(); j++){
if ((k < 254) && (j < fieldSource[i].length() -1 )){
stringConcatenated += fieldSource[i].charAt(j);
k = k + 1; }
else {
stringConcatenated += fieldSource[i].charAt(j);
result.addValue(stringConcatenated);
result.addContextChange();
k = 0 ;
stringConcatenated = ""; }
}
}
}
If you have multiple fields to split, it could be useful for you.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need the node to be also generated that many times like for eg:
suppose the XML payload length is 1020 which it has to be splitted into 4 lines in target field.
My target structure is <Line> 0.... Unbounded and in that <Text> is 0 to 1.
So the expected result is some thing like <Line>
<Text>
<Line>
<Text>
<Line>
<Text>
<Line>
<Text>
By udf i am getting only one which is <Line>
<Text>
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.