Ordering items in collection

Using this code I am able to order each item in collection:
import java.util.Iterator;
import java.util.TreeSet;
public class Item implements Comparable<Item>{
     public Integer param1 = 0;
     public Integer param2 = 0;
     public int compareTo(Item i) {
          return param1.compareTo(i.param1);
     public static void main(String[] args) {
          // collection
          TreeSet<Item> mySet = new TreeSet<Item>();
          // create items
          Item i1 = new Item();
          i1.param1 = 4;
          i1.param2 = 4;
          Item i2 = new Item();
          i2.param1 = 3;
          i2.param2 = 7;
          Item i3 = new Item();
          i3.param1 = 5;
          i3.param2 = 7;
          // add items
          mySet.add(i1);
          mySet.add(i2);
          mySet.add(i3);
          // output
          for (Iterator<Item> iter = mySet.iterator(); iter.hasNext();) {
               Item element = iter.next();
               System.out.println("ITEM: param1="+element.param1+"  param2="+element.param2);
}Please, could anyone give me some hint - I need to have for example this classes:
class TreeSetOrderByParam1 { ... }and
class TreeSetOrderByParam2 { ... }and I need inserted items will be ordered differently (according to name of its class).
Thanks in advance for any help.
Message was edited by:
radone

Hello,
there appears to be some confusion here. You can't order the items in a set. There are basically three collection types in java.util: lists, sets and maps.
Lists are an ordered collection of objects. You have ArrayList, which is fast for access but slow for inserting and deleting objects. You have LinkedList, which is a bit slower for access, but much faster for inserting and deleting objects.
Sets are an unordered collection of objects. You have HashSet, which is fastest for access. You have TreeSet, which is a bit slower for access, but stores the objects in their natural order. However, you can't change the order!
Maps are for storing (key, value) pairs. You have HashMap, which is fastest for access and TreeMap, which stores the pairs according to the natural order of the keys.
If you want to order and reorder objects you have to use lists!
There are two ways for ordering objects. The first is that the objects implement the Comparable interface. The method
public int compareTo(Object o)determines the natural order of the objects. The method returns a negative integer if this object is less than the object in the argument. The method returns 0 if this object is equal to the method in the argument. The method returns a positive integer if this object is greater than the object in the argument.
You can order the objects in a list according to their natural order with the method Collections.sort(List<T> list) in the package java.util.
If you want to define a custom order on your objects, you have to create an object that implements the Comparator<T> interface in the package java.util. This interface has two methods:
public int compare(T o1, T o2)
public boolean equals(Object obj)The compare method returns a negative integer if o1 < o2, returns 0 if o1 == o2 and returns a positive integer if o1 > o2. The equals method returns true if and only if this comparator object is equal to the object in the argument. (The latter method makes only sense if you also include the comparator object in your list.)
You can order the objects in a list according to a custom order defined by a comparator with the method Collections.sort(List<T> list, Comparator<? super T> c) in the package java.util.

Similar Messages

  • Collect cost against sales order / sales order item

    Dear All
    Is it possible to collect costs against sales order or sales order item. 
    The cost is no.of hours the employee booked time against sales order / sales order item.
    Regards
    Deepu Pillai

    Hi,
    Yes. The Sales Order Item can be made cost object to collect the cost. But your requirement is to charge the customer for the no of hours employee worked on that sales order. Through condition type, you can book the expenditure and invoice the customer accordingly. It is purely SD area.
    Trust this helps much!
    Cheers!

  • Collect funding at sales order item level

    Hi all,
    Is there a FM or BAPI that will allow me to feed in a WBS element to retrieve a list of all sales orders and associated line items. I have a need to sum the funding at the sales order item level.
    Thanks,
    Mat

    Hi,
    Perhaps you can read directly from table VBBE to get all sales order and item based on WBS element (PSPEL).
    Regards,
    Ferry Lianto

  • Settle PP Orders to SD Order items using KO8G in a MTO Scenario

    Hi
    I've set a Make_to_Order scenario for a company.
    I need to settle the cost collected onto PP Order to the relative Sales Order Item.
    When I use the KO88 transaction, i can settle a single PP order without problems, but when I try to use the KO8G transaction for a mass settlement, the system issue the message KD233 No settlement for this Sender, in both Foreground and Background processing mode.
    Somebody has an idea how to solve this issue ??
    Why is possible settle a single Order with KO88, but teh system reject the same operation with KO8G transaction ??
    Thanks id advance for your help
    Kind regards
    Claudio

    HI
    Solved by myself.
    The right transaction to use is CO88 and not KO8G used for CO and PM Orders.
    Claudio

  • Free goods determined in Delivery over Order Quantity in Sales Order Item

    Hi Gurus,
    I've a problem about using free goods determination.
    First I created free goods master record with following information
    ZG1010012060075 From 100 PC -> Free good ZG1040012060075 2 PC
    Free goods Category = '2' (Exclusive)
    Free goods delivery control = 'E' (Delivery proportional to quantity in main item)
    Then I've created Sales Order with
    Item 10 ZG1010012060075 4,000 PC.
    Item 11 ZG1040012060075(Free good) has been automatically determined for 80 PC
    Then I've splitted Item 10 into 4 deliveries. The result of free goods determine in each delivery are as follow:
    Delivery#1)
    Item10 ZG1010012060075 = 1,176 PC
    Item20 ZG1040012060075 = 24 PC
    Delivery#2)
    Item10 ZG1010012060075 = 1,176 PC
    Item20 ZG1040012060075 = 24 PC
    Delivery#3)
    Item10 ZG1010012060075 = 1,176 PC
    Item20 ZG1040012060075 = 24 PC
    Delivery#4)
    Item10 ZG1010012060075 = 472 PC
    item20 ZG1040012060075 = 9 PC
    *Remark : Total quantity of 'ZG1040012060075'(free goods) = 92424+24 = 81 PC
    (Greater than 80 PC)*
    I think the system determined free goods in Delivery#4 correctly due to rounding up. But It might not be over the order quantity in Sales Order Item 11. Even though I've set the item category in delivery with Check overdelivery = 'B' (Situation rejected with an error message), the free goods are determined over order qty. BUT if I change delivery qty in delivery#4 Item20 from 9 PC -> 8 PC -> 9 PC, the error message occurred.
    My point is to fix the system not determine free goods in delivery items over order quantity in sales order item.
    Has anyone met this situation before? Do you have any idea about this issue?
    Best Regards,
    Prachya Lalitnorasate

    Dear Sai,
    Thank you for your advice, but it didn't solve my problem.
    I would like the system to determine free goods with proportional to main item AND In the last delivery main item delivered completely free goods must be determined equal to remaining open delivery item.
    Do you have any idea about configuration/customization?

  • System message at CKM3 - Control if the ordered item absorbed the cost

    I have created an exclusive free goods agreement and I would like the ordered item to absorb the cost of the free goods.  In order to transfer the correct information to CO-PA from SD billing, I have made the required customizations ( 1- Deactivated pricing in the item category of the free item    2- Set the cumulate indicator in copying control for the billing item). Now I want to control the result with the TCode CKM3 but it gives ot the following error message. Can anybody explain me what I should do step by step?
    Thanks in advance.
    Diagnosis
         In valuation area 9999 data can only be converted for the material ledger if the material ledger is active.
    System response
         No data was converted in valuation area 9999 for the material ledger.
    Action for the system administrator
         If the material ledger should be active in valuation area 9999 and you wish to convert data, use the Product Cost Controlling section of Customizing to activate the material ledger for this valuation area.

    Hi Yasar
    From the above post i understand that you are getting an error about valuation. Hence i think that the valuation area assignment is improper.
    Check that, that should solve your issue
    Regards
    Ranjeet
    Edited by: Ranjeet Rajendra Jain on Feb 11, 2008 2:41 PM

  • Ordered item to absorb the cost of the free goods

    We have created an exclusive free goods agreement and we would like the ordered item to absorb the cost of the free goods.  In order to transfer the correct information to CO-PA from SD billing, what should we do? Can anybody explain briefly?

    Hi Yasar,
    we do the setting for this in copy controls from delivery to billing.
    pl go to t.code VTFL, select the item which is required to abasorb the cost.
    there you will find a check box " cummulate cost ". Tick it here, this will make the cost of the free item to be transferred to the main item. This can also be used even incase of BOM's.
    regards
    sadhu kishore

  • To populate Segment data to Order item level in additional tab B

    Hi Experts,
    I am working on Inbound interface using IDoc (ORDERS05); during Idoc process IDOC_ORDERS_INPUT; i have to take segment value and need to populate at order items level; in custom field  (in additional tab B).
    For that i am using FM (Customer exits) :
      Step 1-  EXIT_SAPLVEDA_001 (Getting segment value and passing to XVBAP-Zfield).
      Step 2- EXIT_SAPLVEDA_002 (Passing Value to respective screen using BDCDATA table).
    Due to unable to find where i have to set flag and how ?;                                                                                To avoid multiple record to append ; BDCDATA Table with same screen.
    As mention in this link for Header level additional tab B : http://www.sapfans.com/forums/viewtopic.php?f=21&t=62945#p1025880.
    They are using my_flag to avoid ,issue as i mention in above step.
    Step 3 - At last they are deleting my_flag in FM : EXIT_SAPLVEDA_003. (find in above link)
    Thanks in Advance
    Regards
    Vinay

    you need to use a flag of type vbap-posnr .
    and your check statement will become
    check my_flag NE XVBAP-POSNR. (or the ZZXVBAP-POSNR).
    and setting the flag
    my_flag = XVBAP-POSNR.
    so for same posnr it wont repeat the append.. hope this can help

  • Items are not getting displayed in Sales Order Lines 'Ordered Item' field

    Hi All,
    Ordered Item field in Sales Order lines is not getting values When trying to create a Manual Sales Order.
    When clicked on Ordered Item LOV, no values are getting displayed.
    Thanks,
    Chandra.

    879035 wrote:
    Hi,
    I was unable to select any item (nothing is getting displayed in Ordered Item field when the LOV is clicked) in Sales Order Lines.
    The Sales Order header information i was able to enter & generate the Order Number.
    R12.1.3 is the version i am using.
    Thanks,
    Chandra.Have you done all the required setup in OM??
    Like system parameters...Imp one would be Item Validation Organization
    Make sure item is also available in the price list which you are using in order
    Mahendra

  • Purchase Order Items open vs ME2M discrepancy

    First posting so if this is not the right section please move this topic.  Was the closest I could come to correct forum placement.
    Hello all,  I am in the process of setting up BPM to monitor u201CN* of Purchase Order Items openu201D from various plant locations and I am noticing the number BPM gives is different than what the system you give if I used ME2M.
    For example:  I am setting up BPM to monitor Number of Purchase Order Items Open for plant location 2102.  The set up is scarce and I only have a few fields filled out in the set-up:
    -Document Type u2013 Single Value u2013 NB, UB, FO, ZPC, ZGR
    -Plant (Item) u2013 2102
    -Doc. Category u2013 F (Purchase Order)
    -All of fields are left blank
    When this runs I will get an example of 1487 (it changes on an hourly basis so I canu2019t give a static value).
    When I try to verify this number using ME2M I get a value of 1237.  A difference of 250.
    The configuration I am using for ME2M is as follows:
    -Plant u2013 2102
    -Scope of List u2013 ALLES
    -Selection Parameters u2013 WE101
    -Document Type - NB, UB, FO, ZPC, ZGR
    -All other fields at left blank
    Any reason for this discrepancy?  The closest I can guess is SAP is pulling in some additional information OR my configuration is incorrect.  Anybody run into this issue that has some tips?
    Thank you
    -nic

    I know that ME2M has nothing to due to with BPM.
    I am confused as to why when I set up BPM, in Solution Manager, to monitor Purchase Orders that are open I am getting a different number than when I use the transaction ME2M in SAP ECC.
    For example:
    When the process runs in Solution Manager I get back 1425 open POs
    When I go into SAP ECC and use the transaction ME2M it will only pull up 1175 open POs
    Somewhere along the lines I am missing or adding 250 POs.  The current setup (listed above; not sure if BPM is configured the same for everyone) is listed above.
    I have tried various set-up options in both BPM Solution Manager and SAP ECC (ME2M) but can't seem to find where these additional numbers are coming from.
    Thank you
    -nic

  • Standard  report(for open PO order items) with estimated Delivery dates

    hi friends
    i would like to know if there is any standard  report(for open PO order items) with estimated Delivery dates on it.
    thanks
    alahari

    ME2M (by material)
    ME2L (by vendor)
    ME2N (by number)
    Use selection parameter WE101 for open GR
    and scope of list EINT (scheduling lines)

  • Table Name to take report of Open Sales Order items&its relevant GL Number.

    Hi,
    I wanted to take a report with Output as Open Sales Order Items and its relevant GL account numbers. is there any T Code in the Standard or atleast the table name.
    I have already fetched the Open Sales Order Items from T code VA05, but i need the relevant GL account numbers also.
    Any pointers on this will be appreciable.
    Rgds,

    Hi
    There are no standard reports where in you can fetch the data of the open sales order items and its G/L accounts with the output. But  by creating your own report using LIS then it is possible
    Regards
    Srinath

  • Sales order item report based on results analysis key and status

    Hi,
    I am trying to find a a report to generate list of sales order items with following selection
            -invoicing status -invoiced/not invoices (other status)
            -result analysis key assigned to this item (VBAP-ABGRS)
            -system status /released/teco
    Basically i am CO consultant and not so familiar with the SD statuses. I tried VA05 and V.26 but all required selections are not available in these reports.
    If no standard report is available in ERP, i would like to have it in BI. Can some help me with table fields for statuses.
    Thanks in advance.
    Regards
    Raghu

    Hi Raghu
    Go to SE16 and give VBUK table and execute it there you can select the following feilds and then check wheather they are meeting your requirements or not.If they are meeting your requirements then create a new Z report by copying standard VA05 key feilds. and include the other feilds which you need.So you take your ABAP team help
    Billing status     FKSTK
    Posting Status  BUCHK
    Overall status  GBSTK
    Document category VBTYP
    Regards
    Srinath

  • Reg Open sales order item and the quantity

    Hi experts:
    I am getting open sales order item based on inner join of tables(vbak, vbap, vbep). Not using vbbe table in inner join as it doesnt carry all pending open records.
    can any one say how open sales order items  and their quantity can be retrieved?
    I searched forum and saw usage of vbuk and vbup tables, but it does not accomplish our scenario.
    Thanks in advance,
    Sashti.

    Hi,
    1) fetch the header information from VBAK table.
    2) Based on VBAK table fetch all the line items from VBAP table.
    3) Now fetch from VBFA table.
    *-Fetch from VBFA to get the delivered qty
      SELECT vbelv               " Preceding sales and distribution document
             posnv               " Preceding item of an SD document
             rfmng               " Referenced quantity in base UOM
        FROM vbfa
        INTO TABLE lt_vbfa
         WHERE vbelv   = gv_vbeln
           and vbtyp_n = 'J'.
    4) By comparing VBFA-POSNR just filter the records from the VBAP internal table. Remained lines are open lines of the sales order.
    Regards,
    ~Satya

  • FBL5N: Sales Order & Item columns

    Hi,
    The FBL5N report contains Sales Order and Item fields from the hidden columns.  However, there is no data when they are selected to be displayed.
    How are these fields populated? How can the SO and items be displayed in these columns?
    Thanks!

    Hi,
    I am able to see the Sales Order & Item in FBL5N when it was entered in the downpayment.
    How are these fields populated in FBL5N?
    Thanks!

Maybe you are looking for