on 08-07-2015 11:36 AM
Hi Folks,
Currently my project is using SAP PI 7.0 Version.
for one of the requirement : i need to remove the duplicates in the filed:
i wrote UDF as below:
ArrayList aList = new ArrayList();
aList.add(a[0]);
result.addValue(a[0]);
for(int i=1; i<a.length; i++){
if(aList.contains(a[i]))
continue;
else{
aList.add(a[i]);
result.addValue(a[i]);
}
}
but i am getting the below error:
RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping
/ns0:Messages/ns0:Message1/Offer/LocationGroups/LocationGroup[8]/LocationGroupID. The message is:
Exception:[java.lang.StringIndexOutOfBoundsException] in class com.sap.aii.mappingtool.flib3.
TextFunctions method substring[, com.sap.aii.mappingtool.tf3.rt.Context@14d914d9]
Kindly check and provide me the Exact UDF code or any alternate method to resolve the issue.
Thanks in advance.
best regards,
Hari.
Hi Hari,
The queue in your example, all the values is unique, not duplicated, so probably not UDF problem.
The error is complaint about string index out-of-bound at LocationGroup[8], which is 9th start from index 0. At 9th string of your queue is empty string, so hit error when map to substring(1..4) but with string with zero length.
Are you sure is UDF lead to this error or providing the correct error? post a display queue of the removeDuplicate might help.
I have an UDF similar with your UDF too is working fine.http://scn.sap.com/docs/DOC-63651
List uniqueList = new ArrayList();
for (int i = 0; i < contextValues.length; i++){
String value = contextValues[i];
if (!uniqueList.contains(value)) {
uniqueList.add(value);
result.addValue(value);
}
}
Regards,
Yee Loon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Yee Loon Khoo,
thanks for your quick reply.
thanks for the above UDF.
i have solved the issue by using existing fuctions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hari,
Please use belowe UDF at context :
String[] v_current = new String [var1.length];
v_current[0] = "";
for(int i = 0; i<var1.length ; i++)
{
if( var1.length == 1 )
{
result.addValue( var1[i]);
}
else if( var1[i].compareTo(v_current[0]) != 0)
{
result.addValue( var1[i]);
v_current[0] = var1[i];
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.