Skip to Content

PI SAP UDF adding NULL Value

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 16, 2017 at 01:48 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 16, 2017 at 02:50 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 23, 2017 at 03:52 PM

    Cheers Sneha, that done the trick.

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

    Add comment
    10|10000 characters needed characters exceeded