Skip to Content
0

PI SAP UDF adding NULL Value

Feb 16, 2017 at 01:11 PM

89

avatar image

Hi,

I have a simple UDF to add all the values into a string seperated by a ,

String[] pc = new String[1];

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

{

pc[0] = pc[0] + plants[i];

if (i != (plants.length -1))

pc[0] = pc[0] + ";";

}

result.addValue(pc[0]);

}

So if I have the values

IDOC

1

2

3

It should give me 1,2,3

However I get back null1,2,3

where is the extra bull coming from ? it is not a null segment as there is none in the idoc

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Sneha Subramanyam Feb 16, 2017 at 01:48 PM
1

Hi Brian,

Please try the following code :

String[] pc =new String[1];
pc[0]="";
for(int i=0;i<plants.length;i++)
{
pc[0] =pc[0]+ plants[i];
if (i != (plants.length -1))
pc[0] = pc[0]+ ";";
}
result.addValue(pc[0]);

Regards,

Sneha

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Feb 16, 2017 at 02:50 PM
0

Hi Sneha!

Couldn't you please explain why you create String array if you gonna use only one element? Why not just to create String variable which has "" value by default?

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded
Brian Ward Feb 23, 2017 at 03:52 PM
0

Cheers Sneha, that done the trick.

@Evgeniy, it was orginally going to be an array so we set it up that way

Share
10 |10000 characters needed characters left characters exceeded