cancel
Showing results for 
Search instead for 
Did you mean: 

sort drop down value based on subtype

Former Member
0 Kudos

Hi all,

I have a dropdown in which value is populating from an RFC. I have used hash map in th code.Now I need to sort the value displaying in the dropdown in order of subtype, for example subtype 1 should be in the top followed by subtype 2,3 etc.

Please help me as early as possible.

Thanks & Regards,

Aniruddha

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member214651
Active Contributor
0 Kudos

Hi,

The best way is to get the output from the RFC in the sorted order. This will help u in avoiding unnecessary coding in ur WDJ program.

You can inform your ABAP er to send the output in a sorted order.

Regards,

Poojith MV

Former Member
0 Kudos

Do it in java coding : (If it is possible in web dynpro)

Sort based on the keys

Map yourMap= new HashMap();
// put some tuples in yourMap ...
Map sortedMap = new TreeMap(yourMap);

To sort only the keys :

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

...

    Map<String,java.io.File> theSimpsons = new HashMap<String,java.io.File>();
    theSimpsons.put("Bart", new java.io.File("Bart.jpg"));
    theSimpsons.put("Lisa", new java.io.File("Lisa.jpg"));
    theSimpsons.put("Marge", new java.io.File("Marge.jpg"));
    theSimpsons.put("Barney", new java.io.File("Barney.jpg"));
    theSimpsons.put("Homer", new java.io.File("Homer.jpg"));
    theSimpsons.put("Maggie", new java.io.File("Maggie.jpg"));

    SortedSet<String> sortedset= new TreeSet<String>(theSimpsons.keySet());

    Iterator<String> it = sortedset.iterator();

    while (it.hasNext()) {
      System.out.println (it.next());
    }
  
...

Sort based on the values

HashMap yourMap = new HashMap();
// put some tuples in yourMap ...

// to hold the result
HashMap map = new LinkedHashMap();


List yourMapKeys = new ArrayList(yourMap.keySet());
List yourMapValues = new ArrayList(yourMap.values());
TreeSet sortedSet = new TreeSet(yourMapValues);
Object[] sortedArray = sortedSet.toArray();
int size = sortedArray.length;

for (int i=0; i<size; i++) {
   map.put
      (yourMapKeys.get(yourMapValues.indexOf(sortedArray<i>)),
       sortedArray<i>);
}

To iterate your new Sorted Map

Set ref = map.keySet();
Iterator it = ref.iterator();

while (it.hasNext()) {
  String file = (String)it.next();
}

laurent_touillaud
Contributor
0 Kudos

Hi Saurabh,

Tried your code but seems casting like this is not supported in our NWDS version (7.02.02). "Object<String>"

Can you tell us how to cast this in earlier java releases?

Thanks,

Laurent

former_member182372
Active Contributor
0 Kudos

IWDNode has method sort