on 04-10-2013 5:03 AM
Hi Team,
I have to add fields’ value in to target single field. I cannot use “add” because it does not work for empty value and I can also not add”mapwithdefault”. I am using SAP PI 7.1. Could you please suggest if there is any UDF for this.
Source Structure:
Source1
Field1
Field2
Field3
Field4
Source2
Field12
Field22
Field32
Field42
There are two source nodes, two Idoc will be generated in my scenario. I have to add Field1, Field2 & Field3 in to target single Idoc field. And same for Source2 for another Idoc.
Thanks in advance for your response!
Kumar
Hi Kumar,
You have not mentioned the data type of the input fields (floating point,integer etc). In any case the following UDF is sufficient to meet your requirement.
public static String addValues(String v1,String v2,String v3)
{
double sum=0;
String s="";
if(v1!=null && !v1.equals(""))
{
sum=sum+new Double(v1).doubleValue();
}
if(v2!=null && !v2.equals(""))
{
sum=sum+new Double(v2).doubleValue();
}
if(v3!=null && !v3.equals(""))
{
sum=sum+new Double(v3).doubleValue();
}
if(sum-(int)sum<=0.0)
{
s=""+(int)sum;
}
else
{
s=""+sum;
}
return s;
}
Another problem is that UDF will not get called, if fields are not present in source XML.Thus I would further suggest to use the UDF like this
f1----->mapwithdefault(0)------\
f2----->mapwithdefault(0)----------UDF--------->target
f3----->mapwithdefault(0)------/
you mentioned you cannot use mapwithdefault or add , could you please explain any reasons (as why you cannot use standard functions).
If you use standard functions no UDF is required.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Duplicate the Idoc structure at receiver side and implement different add functions for the Target fields in IDocs.
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you can directly concat the 3 fields and assign to third field...
Cheers,
Cnu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
there is no need of a udf for this. you cud use the standard concat function(under text functions) if u simply want to concat fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kumar,
write a UDF with var1 var2 and var3 as inputs.
use code as belwo simple
return var1+var2+var3 ---->if you want concat them
return var1+' '+var2+' '+var3 --> if you want concat them with space delimitor
Regards,
Sreeni.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kumar,
You can write UDF as follows as you are not able to use standard functions:
Pass 3 fields as parameter to UDF and create UDF of type value.
You may check for empty field in UDF as field != "".
Regards,
Beena
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.