null in the SAP PI mapping context queue
One of the things that really can get me up the red field is when I get an <null> element when working with a SAP PI mapping. Or I would say rather debugging, because of some strange incoming data. Why not give me something that I can us in way mapping to check for. The <null> gives a lot of issues for figuring out if the values work.
I’m not sure what causes this to be like it is. It may be a null string or something like it.
The build in function “isNil” delivered this result. I guess it checks if the values is XSI:Nil. I would have guess that this delivered a false value for this input.
So I had to create my own function to check for this.
The isNull function that I created looks like this:
for(int i=0;i<var1.length;i++){
if (var1[i]==null){
result.addValue(“true”);
}else{
result.addValue(“false”);
}
}
If I then want to do an OR function after this, where on input can be null then it does not solve my problem. false or <null> does give <null>. Dam. So I cannot use the function that I wanted.
So I just have to build in the length check into my null function, so it does support the extra function. I could also build an OR function to support this extra features, but that will not add a lot of extra value. I’m only using this
So the new function looks like this.
for(int i=0;i<var1.length;i++){
String tmp = var1[i];
if (tmp == null){
result.addValue(“false”);
}else{
result.addValue(tmp.length()>0);
}
}
I do hope that you find this helpful and it solve some of your problems. I’m working on creating a course around how to use SAP PI/PO. I have created some free videos around creating your first scenario that you can get on http://picourse.com
Hello Daniel
Nice info. Looking ahead for some more mapping blogs from you in coming days... 🙂
Have a great day.!
Regards,
Sunil
Hi Sunil.
Glad you liked it.
Hi Daniel.
Nice info... Thanks for the new concept... Hav a good day... :):)
Most welcome. You too.
Hi Daniel
One add on....
UDF To remove this <Null>
public void removeNull(String[] input,ResultList result,Container container){
for (int i = 0; i < input.length; i++) {
result.addValue(input[i]);
}
Thanks for sharing.
Yes it removed null. But then you dont have any values after it. So It could make challenges in your contexts if they should are important.
Hi Daniel,
thanks for nice blog, i am new to PI ,while creating this UDF which type we need to choose value, context or queue ?
Thanks & regards
Pavan
Hi
It needs to be context otherwise you will not have the array.
daniel
Hi Daniel,
Its really Nice blog, Thank you very much for the blog.. 🙂
Regards,
Naveen
Hi Daniel,
looks very good...thank you for the effort
Regards
Stefan
Hi Daniel,
Thanks for the nice information. We are waiting for new updates...
Hi Daniel,
Congratulations!! Thanks for sharing!
Kind regards
Carlos
Hi Daniel,
Thanks for sharing.
Regards
Nurhan
Hi Daniel,
How to check xsi:nil using the same UDF. I don't want to use built in "isNil" since it does not return true or false when the value is <null>. so I want to make use of above UDF along with xsi:nil validation.
Could you please help me with this.
Thanks,
Suman