cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting

Former Member
0 Kudos

Hi Group,

In one of my Message Mapping (File to File scenario) I want to sort the reference number field,In which reference number fields have value 'REF' I want to keep them

in the Last,can any body suggest(in this Reference Number some of them contains REF and all others are numbers),Please suggest.

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Did you see my last post.It's working fine.

Cheers!

Samarjit

Former Member
0 Kudos

Hi swabap,

ArrayList arr = new ArrayList();

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

arr.add(a<i>);

}

List listA = arr.subList(0,arr.size());

Iterator itr = listA.iterator();

Collections.sort(listA);

while(itr.hasNext()){

result.addValue(itr.next()+"");

}

this code work in xi.

Before that you should import java.util.*;

Cheers!

Samarjit

Former Member
0 Kudos

Hi,

ArrayList arr = new ArrayList();

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

arr.add(a<i>);

}

Iterator itr = arr.iterator();

List listA = arr.subList(0,arr.size());

Collections.sort(listA);

Iterator itr = listA.iterator();

while(itr.hasNext()){

return.addValue(itr.next()+"");

}

Please check this code i hope it will work.

Assume "a" is the String array coming from method as a parameter.

Cheers!

Samarjit

Former Member
0 Kudos

Hi Samrajith,

Problem is that It is not identifying Iterator,List ,Collections even after adding the imports

Former Member
0 Kudos

Hi,

If code is still giving error..try with this.

Iterator itr = a.iterator();

List listA = a.subList(0,a.length);

Collections.sort(listA);

Iterator itr = listA.iterator();

while(itr.hasNext()){

return.addValue(itr.next()+"");

}

Assume "a" is the array coming from method as a parameter.

Cheers!

Samarjit

bhavesh_kantilal
Active Contributor
0 Kudos

Hi

Did you check the Sort function under the node functions?

http://help.sap.com/saphelp_nw2004s/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

<i>Sorts all values of the multiply-occurring inbound field I within the existing or set context. The sorting process is stable (the order of elements that are the same is not switched) and it sorts the values in O(n*log(n)) steps. Using the function properties, you can specify whether values are to be sorted numerically or lexicographically (case-sensitive or non case-sensitive) and in ascending or descending order.</i>

Regards

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

Yes,I tried with SORT Node Function ,but its not working as expected.

prabhu_s2
Active Contributor
0 Kudos

what is ur input and what output u got? can u post ur structure aswell?

Former Member
0 Kudos

Input

-


1909138700012

1947991300010

REF

1947991300045

1947991300067

REF

REF

Output(expecting)

-


1909138700012

1947991300010

1947991300045

1947991300067

REF

REF

REF

prabhu_s2
Active Contributor
0 Kudos

refer: /people/stefan.grube/blog/2005/12/29/new-functions-in-the-graphical-mapping-tool-xi-30-sp13

or u can use a udf....check with code (wrt to other thread):

Vector vID = new Vector();

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

if (!vID.contains(a)) vID.add(a);

}

Collections.sort(vID);

for (int i=0; i><vID.size(); i++) {

result.addValue((String)vID.get(i));

}

Former Member
0 Kudos

Hi Prabhu,

Do I need to import any method to use this code in UDF

prabhu_s2
Active Contributor
0 Kudos

i'm not sure enought but must check if any packages needs to be inserted. u can have this udf and execute the mapping and see if any errors triggers

Former Member
0 Kudos

Hi Prabhu,

I am getting the following Error:

<b>

RuntimeException in Message-Mapping transformation: Exception:[java.lang.ClassCastException] in class com.sap.xi.tf._FIle_to_File_ method contrasort$[com.sap.aii.mappingtool.tf3.rt.BufPointer@5a6601b0]

</b>

Former Member
0 Kudos

Hi,

/****UDF****/

ArrayList arr = new ArrayList();

arr.add("1909138700012");

arr.add("1947991300010");

arr.add("REF");

arr.add("1947991300045");

arr.add("1947991300067");

arr.add("REF");

arr.add("REF");

Iterator itr = arr.iterator();

List listA = arr.subList(0,arr.size());

Collections.sort(listA);

System.out.println("New Sorted List : " + listA);

/********/

return listA in form of String.

Output:

New Sorted List : [1909138700012, 1947991300010, 1947991300045, 1947991300067, REF, REF, REF]

Cheers!

Samarjit

Message was edited by:

Samarjit Dey

Former Member
0 Kudos

Hi Samrajit,

I have given the Input Values only for example,My Input Files have Huge records

Former Member
0 Kudos

Hi,

I am no talking to give the input.For example i put into the code.

That array will come from UDF itself.

Code is working......i tested it.

Cheers!

Samarjit

Former Member
0 Kudos

Hi Samrajith,

I am bit confused abt the code ,Can you please send the UDF code so that I can test it

Former Member
0 Kudos

Hi swabap,

Create UDF of queue mapping there String a[] will come automatically.

then put my code like

ArrayList arr = new ArrayList();

arr = a;

Iterator itr = arr.iterator();

List listA = arr.subList(0,arr.size());

Collections.sort(listA);

Iterator itr = listA.iterator();

while(itr.hasNext()){

return.addValue(itr.next().toString());

}

Cheers!

Samarjit

Message was edited by:

Samarjit Dey

Former Member
0 Kudos

Hi Samrajith,

do I need to add any imports because I am getting the following Erros.

<b>

ile_.java:3250: incompatible types found : java.lang.String[] required: java.util.ArrayList arr = a; ^ /usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Map48517d4002d211dcc92a0003bae4e42a/source/com/sap/xi/tf/_FIle_to_File_.java:3254: itr is already defined in refsort$(java.lang.String[],com.sap.aii.mappingtool.tf3.rt.ResultList,com.sap.aii.mappingtool.tf3.rt.Container) Iterator itr = listA.iterator(); ^ /usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Map48517d4002d211dcc92a0003bae4e42a/source/com/sap/xi/tf/_FIle_to_File_.java:3256: cannot return a value from method whose result type is void return(itr.next().toString()); ^ 3 errors().toString()); ^ 3 errors

</b>

Former Member
0 Kudos

Hi,

You need to import

import java.util.ArrayList;

import java.util.Collections;

import java.util.Iterator;

import java.util.List;

Instead of assigning arr = a;

remove that line and replace arr by a.

Cheers!

Samarjit

Former Member
0 Kudos

Hi Samrajith,

I included the below objects in imports fiels in UDF (at the top)

<b>

java.util.Collections;java.util.List;java.util.Iterator;java.util.ArrayList;

</b>

still I am getting the Error

<b>

usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Map8848509002e111dcc9c60003bae4e42a/source/com/sap/xi/tf/_FIle_to_File_.java:3261: cannot resolve symbol symbol : method iterator () location: class java.lang.String[] Iterator itr = a.iterator(); ^ /usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Map8848509002e111dcc9c60003bae4e42a/source/com/sap/xi/tf/_FIle_to_File_.java:3262: cannot resolve symbol symbol : method size () location: class java.lang.String[] List listA = a.subList(0,a.size()); ^ /usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Map8848509002e111dcc9c60003bae4e42a/source/com/sap/xi/tf/_FIle_to_File_.java:3264: itr is already defined in contrasort$(java.lang.String[],com.sap.aii.mappingtool.tf3.rt.ResultList,com.sap.aii.mappingtool.tf3.rt.Container) Iterator itr = listA.iterator(); ^ /usr/sap/XD1/DVEBMGS03/j2ee/cluster/server0/./temp/classpath_resolver/Map8848509002e111dcc9c60003bae4e42a/source/com/sap/xi/tf/_FIle_to_File_.java:3266: cannot return a value from method whose result type is void return addValue(itr.next().toString()); ^ 4 errors

</b>

Former Member
0 Kudos

Hi,

Iterator itr = a.iterator();

List listA = a.subList(0,a.size());

Collections.sort(listA);

Iterator itr = listA.iterator();

while(itr.hasNext()){

return.addValue(itr.next()+"");

}

Please try this code.

Assume "a" is the array coming from method as a parameter.

Cheers!

Samarjit

Former Member
0 Kudos

Hi Samrajith,

The same code I used including the Imports,but I am getting syntax error saying that "Cannot resolve symbol symbol : method iterator ()"

"cannot resolve symbol symbol : method size ()"