cancel
Showing results for 
Search instead for 
Did you mean: 

How to sort data?

Former Member
0 Kudos

Hi Experts,

I have created WD program which fetches data from R/3 using RFC. I am getting data in following way:

Pernr   Name
1          Adam
2          Smith
3          Bob

I want to sort the data in following way:

Pernr   Name
1          Adam
3          Bob
2          Smith

Please note that I am using the Name field to populate drop down UI element.I want the name to be sorted before it is used in drop down UI element.

How I can do so?

Regards,

Gary

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

You need to sort the node in which the data is stored is the following way :

wdContext.nodeOutput_dropdown().nodeIt_Apr_Id_Tab().sortElements

(

new Comparator()

{

public int compare(Object x, Object y)

{

String ax = ((IWDNodeElement) x).getAttributeValue("<element name in the node>").toString().toUpperCase();

String ay = ((IWDNodeElement) y).getAttributeValue("<element name in the node>").toString().toUpperCase();

if (ax == null)

{

return ay == null ? 0 : 1;

}

return ax.compareTo(ay);

}

}

);

Hope this solution will help you.

Thanks

Ritushree

Ritushree

Answers (5)

Answers (5)

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Gary,

Take all the name values into List object and apply

Collection.sort(List) method to sort the object.Now get the values from List by itearting it.

( Or ) DO webdynpro table Sortinga and get the vlaues.

Regards,

srikanth

Former Member
0 Kudos

Hi Srikanth,

How I can do so? Please provide me some sample code.

Regards,

Gary

Former Member
0 Kudos

Hi Gary,

Get the name values from the table in to List object.

List l=new List();

for(int i=0;i<wdContext.node<name>.size();i++)

{

l.add(wdContext.node<name>.get<name>ElementAt(i);getName());

}

pass this List object to sort method to sort the List.

Collections.sort(l);

NOw the List object will be sorted out.

Iterate the List to get the values.

Iterator i= l.iterator();

while(i.hasNext())

{

String str= (String)i.next();

}

here u can use the str value.

Regards,

srikanth

Edited by: Srikanth Thatipally on Jul 27, 2009 10:41 AM

Edited by: Srikanth Thatipally on Jul 27, 2009 10:44 AM

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Murali,

Due to some reasons, I want to sort records of Collections. How I can do so?

Regards,

Gary

Former Member
0 Kudos

hi,

you can take it in a map and apply sort

Former Member
0 Kudos

Hi Aishwarya,

How to do so? I am using collection:

The code is as below.

Regards,

Zname1_Md_name_Getlist_Input input = new Zname1_Md_name_Getlist_Input();
    wdContext.nodeZname1_Md_name_Getlist_Input().bind(input);
    input.setPi_Langu("EN");
    try {
		wdContext.currentZname1_Md_name_Getlist_InputElement().modelObject().execute();
	} catch (WDDynamicRFCExecuteException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return false;
	}
	Collection NameFrom = new ArrayList();
	Collection NameTo = new ArrayList();
	for(int x=0; x<wdContext.nodePot_name().size(); x++){
		IPublicCreate_travel_request_comp.IFromnamesElement from = wdContext.createFromnamesElement();
		IPublicCreate_travel_request_comp.ITonamesElement to = wdContext.createTonamesElement();
		from.setFromnames(wdContext.nodePot_name().getElementAt(x).getAttributeAsText("Landx"));
		to.setTonames(wdContext.nodePot_name().getElementAt(x).getAttributeAsText("Landx"));
		NameFrom.add(from);
		NameTo.add(to);
	}
	wdContext.nodeFromnames().bind(NameFrom);
	wdContext.nodeTonames().bind(NameTo);
	int index = 0;
	for(int x=0; x<wdContext.nodeFromnames().size(); x++){
		if(wdContext.nodeFromnames().getFromnamesElementAt(x).getFromnames().equalsIgnoreCase("saudi arabia")){
			index = x;
		}
	}
	wdContext.nodeFromnames().setLeadSelection(index);
	wdContext.nodeTonames().setLeadSelection(index);
    return true;

Former Member
0 Kudos

change the following code segment:


	//Collection NameFrom = new ArrayList();
	//Collection NameTo = new ArrayList();
                      ArrayList namesList = new ArrayList();

	for(int x=0; x<wdContext.nodePot_name().size(); x++){
		IPublicCreate_travel_request_comp.IFromnamesElement from = wdContext.createFromnamesElement();
		IPublicCreate_travel_request_comp.ITonamesElement to = wdContext.createTonamesElement();

		from.setFromnames(wdContext.nodePot_name().getPot_nameElementAt(x).getLandx());
                                           to.setFromnames(wdContext.nodePot_name().getPot_nameElementAt(x).getLandx());

                                          //from.setFromnames(wdContext.nodePot_name().getElementAt(x).getAttributeAsText("Landx"));
		//to.setTonames(wdContext.nodePot_name().getElementAt(x).getAttributeAsText("Landx"));

		NameFrom.add(from);
		NameTo.add(to);
	}

                      *Collections.sort(from);*
                      *Collections.sort(to);*

Edited by: Aviad Levy on Jul 27, 2009 10:55 AM