Sorting an ArrayList based on the value of a field in one of the objects.

Hi,
I have the following problem:
A server app returns an array list of simple objects with a bunch of fields.
One of these fields is an int.
How do I go about sorting the list based on the size of the int?
Thanks in advance!

Thanks a lot.
The Comparator solution is actually ridiculously simple.....
public class MyComparator implements Comparator {
public int compare(Object o1, Object o2) {
     if (Integer.parseInt(((ZMData)o1).getAantalposts())>Integer.parseInt(((ZMData)o2).getAantalposts())) {
          return 1;     
     if (Integer.parseInt(((ZMData)o1).getAantalposts())<Integer.parseInt(((ZMData)o2).getAantalposts())) {
          return -1;     
     return 0;
}Thanks again.

Similar Messages

  • Need to fetch the routings based on the Object text maintained in Long text

    Hi Gurus,
    i have a requirement to fetch all the routing operations based on the Object text that had been maintained in the long text of the routing.
    I found out the tables STXH and MAPL for the values, but unable to link the same.
    Please do help me to find a solution.
    Thank you.
    Naveen.A

    HI Ratan,
    My requirement is to fetch routings that contain Object text.
    The long text of a routings may contain many object texts , but i need to identify the specific object text alone and dispaly all the operations in which this object text exists.
    Thanks for your understanding.
    NAveen.A

  • Get value of two fields into one field

    Hellou,
    i need little help with javascript again
    Currently i'm using code below to get value from one field to other:
    getField("Text35").value = getField("Text1").valueAsString;
    Now i'm wondering how to change this code, so i could get values from two fields into one. For example i have field "firstname" and field "lastname", now i want to show this in field "name".
    Example, if field firstname have value John and field lastname value is Doe, i want to show it in field name like "John Doe".
    I hope that u understood what i want
    Thanks for helping me!

    getField("Text35").value = getField("Text1").valueAsString + " " +
    getField("Text2").valueAsString;

  • Sorting an array based on the value of another array

    Hi
    Ive got 2 arrys... An Integer[]{11,12,23,24,25};
    and another one double[]{60,79,83,54,67};
    i wanna sort the first array based on the values of the second array..
    ie my result should be double[]{83,79,67,60,54} and
    Integer[]={23,12,25,11,24}...........
    is thr any easy method to do tis..

    You should make a class with the int and the double as fields; and have your class implement Comparable to compare on the double the way you want; and just have an array of objects of this class, and sort it.
    Because the corresponding elements in your arrays are essentially linked, so they should be together.
    Edited by: spoon_ on Apr 12, 2008 2:17 AM

  • Field Read Only based on a value of another field

    Hello,
    In our project we´d like to have Field A made Read Only based on a value of Field B. Otherwise it should be R/W.
    Would this be possible in OnDemand ?
    Txs. a lot for any help.
    Antonio

    If your field is the key field that helps in dynamic layout then this is possible. If not try doing a validation on the field.

  • Fields required based on a value in another field

    Hi,
    I am looking to have fields required (Annual Revenues and # of Employees) based on the value of another field (Ownership). Basically, if the value is Public the user is required to enter the Annual Revenue and Employees fields. I thought about using dynamic layouts but the only key field for Accounts is Account Type.
    Thanks,
    Caryn

    Hi Caryn!
    I think it is not possible for making #Employees and Revenues required depending on Ownership(as it is a look up field).. it should be possible if you want to do it on any other criteria other than ownership by just renaming the Account Type, Disable all the values of Account Tyope add new values to Pick List and make it driving picklist upon your requirements..
    If you require Account Type, create a custom picklist "Account-Type" and add the values.

  • How can I do a multi-row insert based on a value in a field on my form?

    My Form contains these fields (for the purpose of inserting rows into my 'Ports' table)
    ..Number_of_Ports
    ..Device_Name
    ..Router_Name
    ..Router_Slot_Number
    ..Router_Port_Number
    ..Vlan_Number
    Based on the value entered for 'Number_of_Ports'
    I would like to insert 'X' number of rows into my 'Ports' Table
    with the values which are contained in:
    ..Device_Name
    ..Router_Name
    ..Router_Slot_Number
    ..Router_Port_Number
    ..Vlan_Number
    Can someone help me with this,
    Or should I post this on another forum?
    Thanks in advance- Gary

    Gary,
    You can accomplish this with a PL/SQL process using a FOR LOOP. For the following example, I am going to use fields that would have been generated for Page 1 of an application:
    Begin
    FOR i IN 1..:P1_NUMBER_OF_PORTS LOOP
    INSERT INTO tablename(port_number, device_name, router_name, router_slot_number_vlan_number)
    VALUES(i, :P1_DEVICE_NAME, :P1_ROUTER_NAME, :P1_ROUTER_SLOT_NUMBER, :P1_ROUTER_PORT_NUMBER, :P1_VLAN_NUMBER);
    End Loop;
    End;
    Hope this helps.
    Mike

  • Read Internal Table based on Multiple Values for Key Field

    Hi Gurus,
    i have one query can you tell me how read an internal table it_kna1 for multiple values of land1 DE US IND etc.
    i had tried as below but i could not can you try and let me knwo at the earliest.
    here i want read the values with DE or US and want further prosess them.
    REPORT  YC001.
    tables kna1.
    select-options: cust for kna1-kunnr.
    data: begin of it_kna1 occurs 0,
            kunnr like kna1-kunnr,
            name1 like kna1-name1,
            land1 like kna1-land1,
            end of it_kna1.
    select kunnr name1 land1 into table it_kna1 from kna1 where kunnr in cust.
    read table it_kna1 with key land1 = ( 'DE' OR 'US' ) .
    can anybody suggest me some solution.
    Thanks,
    Jeevi.

    This should be what you need:
    REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 80 MESSAGE-ID 00.
    TABLES kna1.
    SELECT-OPTIONS: cust FOR kna1-kunnr.
    DATA: BEGIN OF it_kna1 OCCURS 0,
            kunnr LIKE kna1-kunnr,
            name1 LIKE kna1-name1,
            land1 LIKE kna1-land1,
          END OF it_kna1.
    DATA: itab_index LIKE sy-tabix.
    SELECT kunnr name1 land1
      INTO TABLE it_kna1
      FROM kna1
      WHERE kunnr IN cust.
    SORT it_kna1 BY land1.
    READ TABLE it_kna1 WITH KEY
      land1 = 'DE'
      BINARY SEARCH.
    itab_index = sy-tabix.
    WHILE sy-subrc = 0.
      itab_index = itab_index + 1.
      WRITE: /001 it_kna1-kunnr, it_kna1-land1, it_kna1-name1.
      READ TABLE it_kna1 INDEX itab_index.
      IF it_kna1-land1 <> 'DE'.
        sy-subrc = 99.
      ENDIF.
    ENDWHILE.
    SKIP 1.
    READ TABLE it_kna1 WITH KEY
      land1 = 'US'
      BINARY SEARCH.
    itab_index = sy-tabix.
    WHILE sy-subrc = 0.
      itab_index = itab_index + 1.
      WRITE: /001 it_kna1-kunnr, it_kna1-land1, it_kna1-name1.
      READ TABLE it_kna1 INDEX itab_index.
      IF it_kna1-land1 <> 'US'.
        sy-subrc = 99.
      ENDIF.
    ENDWHILE.
    Rob

  • Copying the value of customized fields from one order to other in CRM

    Hi ALL,
    We have added new customized fields in web ui for Sales Order.
    Now when we are using the standard COPY functionality to copy one particular sales order, then all the fields are getting copied into new order except the customized fields which we have added.
    We have created new data elements for our fields and added it by EEWB transaction.
    Please let me know if there is any badi or any other way which we can implement so that our customized fields are also copied.
    Thanks,

    Hi!
    BADI "CRM_COPY_BADI" is the one you are looking for.
    Create badi implementation and assign copy routine to the copy management parameter.
    The parameter can be configured via IMG->CRM->Transactions->Basic settings->Copying Control for Business Transactions->Define Copying Control for Transaction Types.
    I hope it helps you.
    Regards,
    Fukuhara Yohei

  • Identify What are the days present in weekdays value of recurrenceinfo field

    Hi,
          I want the particular days based on weekdays values in recurrenceinfo field for appointment.The values of days as sunday 1,monday 2,tuesday 4,wednesday 8,thursday 16,friday 32 and saturday 64.Now the weekdays = 65 which means in this
    saturday 64 and sunday 1 is contained.So i want the query for identifying days in weekdays values.

    Just do a boolean and operator with 65 (64 | 1 ie both saturday and sunday) to check the presence
    For example say recurrenceinfo field is set for Mon,Wed and Fri
    then value would be 2 | 8 | 32 = 42
    Now & with 65 and you will get 0 as there are no overlaps
    SELECT 2 | 8 | 32
    SELECT 42 & 65
    So your filter should be like this
    WHERE recurrenceinfo & 65 = 0
    for no overlap
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • What are the objects that support variables?

    What are the objects that support variables?

    Using Variables: The Variable Wizard and the Variable Editor
    Definition
    Variables are parameters of a query that you defined in the Query Designer and that are filled with values when you execute the query or Web application. They serve as a store for characteristic values, hierarchies, hierarchy nodes, texts and formula elements, and can be processed in different ways.
    The processing type determines how a variable is filled with a value for the runtime of the query or Web application.
    There are different types of variables depending on the object for which you want to define variables. These types specify where you can use the variables.
    Variables are reusable objects. This means that when you define a variable for a query in the Query Designer, this variable can be used in all other queries. Variables are not dependent on the InfoProvider, only on the InfoObject. A variable that you define for an InfoObject is available in all InfoProviders that use this InfoObject.
    Use
    Variables enable you to customize queries flexibly (parameterize the query) possible. If you use variables in the Query Designer, do not select any fixed characteristic values, hierarchies, hierarchy nodes, texts, or formula elements. Instead, set up variables as place holders. These are then filled with values when the query is running (when you insert the query into a workbook, when you refresh the workbook or when you execute the query on the Web. You can use one query definition as the foundation for many different queries if you use variables.
    You want to create one query for all the people responsible for customer groups, who each only evaluate the data for one customer group. In the Query Designer, you insert a variable for the characteristic u2018customer groupu2019. Just before the query is executed, decide for which customer group(s) you want the query to apply to.
    There are two tools in the Query Designer for designing and changing variables.
    The variable wizard takes you step-by-step through the process of defining a variable. Each individual step is context-sensitive and is adjusted according to the combination of variable and processing types used. This means that the variable wizard only offers the selection options that are permitted for that combination of variable and processing types. For more information, see Defining Variables with the Variable Wizard.
    The variable editor dialog box offers all of the selection options for changing an existing variable. The individual fields in the dialog box show the settings affected in the variable. You can change these settings here. If you want to make the changes using a step-by-step process with explanatory texts, you can jump to the variable wizard using . For more information, see Changing Variables in the Variable Editor.
    Integration
    The variable wizard and the variable editor are functions in the Query Designer and are context-sensitive.
    In principle, the two dialog boxes appear wherever you can enter constants (that is, values) in input fields. One of these input fields is the Entry of Variables checkbox.  If you select this option, the following options for using a variable appear, instead of a fixed value:
    ·        The variables that are available appear in the dropdown box for the input field. You can select a variable from the dropdown box.
    ·        The symbol  Change Variable appears next to the Entry of Variables checkbox. You can change the variable using  . The Variable Editor dialog box appears.
    ·        The symbol  New Variable appears next to the Entry of Variables checkbox. Choose  if you want to create a new variable. The Variable Wizard dialog box appears.
    By way of an example, when defining conditions for the value limit of the condition, you can not only enter fixed values but also formula variables. Mark the Entry of Variables checkbox and you can then use the options described above. The settings are context-sensitive so that the formula variables that only those formula variables that are available appear in the dropdown box.  The variable wizard is set up automatically in the same way for entering formula variables.
    You can also get to the variable wizard and the variable editor from the context menu of those objects for whose values you can define variable placeholders. From the context menu, choose New Variable. The SAP BW Variables Wizard appears. In the context menu for variables that have already been defined, you can choose Edit. The SAP BW Variables Editor appears.
    In the InfoProvider objects dialog box, you select a characteristic (for example, Order) and from the context menu, choose New Variable. You reach the variable wizard, which is already set up for you to enter a characteristic value variable.
    In the InfoProvider objects dialog box, you select a characteristic value variable and from the context menu, choose Edit. You reach the variable editor where you see all of the settings for the variable. You can make changes to the variables here.
    Variable Types
    Definition
    The type of variable being used. This determines the object that the variable represents as a placeholder for a concrete value.
    Structure
    There are different types of variables depending on the object for which you want to define variables. These types specify where you can use the variables.
    ·        Characteristic Value Variables
    Characteristic value variables represent characteristic values and can be used wherever characteristic values are used.
    If you restrict characteristics to specific characteristic values, you can also use characteristic value variables. See, Restricting Characteristics.
    ·        Hierarchy Variables
    Hierarchy variables represent hierarchies and can be used wherever hierarchies can be selected.
    If you restrict characteristics to specific hierarchies or select presentation hierarchies, you can also use hierarchy variables. See Selecting Hierarchies
    ·        Hierarchy Node Variables
    Hierarchy node variables represent a node in a hierarchy and can be used wherever hierarchy nodes are used.
    If you restrict characteristics to specific hierarchy nodes, you can also use hierarchy node variables. See Restricting Characteristics: Hierarchies
    ·        Text Variables
    Text variables represent a text and can be used in descriptions of queries, calculated key figures and structural components.
    You can use text variables in the description of calculated key figures, restricted key figures, selections and formulas when you create them. See Defining Calculated Key Figures, Defining Restricted Key Figures, Defining Selections, and Defining Formulas.
    You can change the descriptions in the properties dialog box. See Query Properties Calculated Key Figure Properties Restricted Key Figure Properties, and Selection/Formula Properties.
    ·        Formula Variables
    Formula variables represent numerical values and can be used in formulas. See Defining Formulas.
    In addition, numerical values are used for selecting exceptions and conditions and you can also use formula variables here. See Defining Exceptions and Defining Conditions
    You can use a formula variable for the interest rate in order to process the current interest rate, after you have executed the query or Web application.
    http://help.sap.com/saphelpnw04/helpdata/en/e3/e60138fede083de10000009b38f8cf/frameset.htm_

  • Subtotal in alv report based on the particular field value

    Hi,
    As per my requirement, i need to do subtotal of quntity field based on the material number field value in alv report.
    Ex:  if material number falls 1 to 10 then i need to be calculate and display subtotal qty amount with text " total of the mat1" and if material number falls 11 to 20 then again i need to be claculate and display subtotal qty amount with text "total of the mat2". similarily i need to display the details.
    <removed_by_moderator>
    Regards
    Nagendra

    Hi,
    Ex: if material number falls 1 to 10 then i need to be calculate and display subtotal qty amount with text " total of the mat1" and if material number falls 11 to 20 then again i need to be claculate and display subtotal qty amount with text "total of the mat2". similarily i need to display the details.
    What you can do is in your output table, you will have to create an auxilary field, lets call it as material group (groupid). Now you can do a subtotal on the material group. However the logic to determine what materials belong to which group should be coded. I guess you might be having some logic for that.
    So lets say that material 1 to 10 as G1 ( group 1 ) and material 11 to 20 as G2 ( group 2 )
    The output of the internal table would be
    Groupid  matnr ...
    1  1
    1  2
    1  3.....and so on
    2  11
    2  12
    2  13....upto 20.
    Now in the fieldcatalog assign an 'X' to the 'dosum' parameter to the field Groupid
    In the sort info do the following :
    gs_sort-fieldname = 'GROUPID'.
    gs_sort-spos = 1.
    gs_sort-up = 'X'.
    gs_sort-subtot = 'X'. ***CRUCIAL STATEMENT****
    append gs_sort to gt_sort.
    Now pass all this data to the alv grid function. And you are done.
    regards,
    Advait

  • Is there an easy way to filter a 2-d array based on the values of two of the fields?

    Is there an easy way to filter a 2-d array based on the values of one of the fields. In my attached VI the output array has the following format:
    TimeStamp        Ident                Frame Type          Bytes    Data
    10:57:07.621   3AD00016   CAN Data Frame   8          0000000000000000
    10:57:07.622   3AD00017   CAN Data Frame   8          000005E000000000
    10:57:07.624   3AD00018   CAN Data Frame   8          0000000003300000
    10:57:07.625   2DC00000   CAN Data Frame   8          0000000000000000
    10:57:07.626   3AD00019   CAN Data Frame    4         0000030000000000
    I would like to delete any rows that do not have an "Ident" between the values of 3AD00000 and 3AD0001E. So for the above data the fourth row would be deleted. The only way I can see to do it is to form a 1-d array. Is there a better approach?
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    CMM_SN_MULTI.vi ‏20 KB

    Hi chuck72352,
    after you have sorted your data, you can use the InRange Function. Combined with a "search 1D Array" you'll get the range you really want.
    Mike
    Attachments:
    ArraySubset.PNG ‏25 KB

  • Trying to get the input parameter of a web service fxn based on table value

    Hello--
    I am new to ADF and Jdev 11g (I am a forms developer). I had created a web service from a pl/sql stored db package. I can successfully execute a function with an input parameter from ADF Faces.
    Instead of the input parameter being enterable by the user, I would like it to be based on a selected ADF table column value. How would I correlate the selected row column value as the function input parameter?
    I played with an ADF output text based on the ADF table column with the PartialTriggers value set to the ADF table...which updates the output text based on the column selected. Do I use some sort of partial trigger on the input parameter?
    From a forms point of view, I am looking for the "Copy Value from Item" property :)

    Hi,
    Not sure if this would help you.
    But if your table is bound to a ViewObject, it will be easier to get the current selection.
    Supose your table is bound to iterator1.
    In your backBean code:
    DCBindingContainer dcBindings = (DCBindingContainer)getBindings();
    DCIteratorBinding iterator =dcBindings.findIteratorBinding("iterator1");
    Row row = iterator.getCurrentRow();
    Object selectedValue = row.getAttarbute(<value of the column you are looking for>);
    public BindingContainer getBindings() throws Exception {
    try {
    if (this.bindings == null) {
    FacesContext fc = FacesContext.getCurrentInstance();
    this.bindings =
    (BindingContainer)fc.getApplication().evaluateExpressionGet(fc,
    "#{bindings}",
    BindingContainer.class);
    return this.bindings;
    } catch (Exception ex) {
    displayMessage("Error occurred. Please contact your IT Adminstrator.");
    return this.bindings;
    Let me know if this helps.
    -Makrand

  • Map default values in Header based on multiple values in the line item

    Hi
    I have a scenario in which the Header field of an IDOC should be populated with some default values based on some mixed mvt types in the line items.
    eg:
    Header -
    > Delivery type -
    > needs to be mapped to A (for X of line item 1)or B (for Y of line item 2) or C (for Z of line item 3 )
    based on line items field
    line item1---> mvt type---> X
    line item 2-->mvt type----->Y
    line item 3 -
    > mvt type -
    > Z
    mvt types doesnt necessarily have to come in that order and even the same mvt type can repeat in multiple line items.
    Can we achieve this logic in XI ?

    I think if you include removeContext, Sort, SplitByValue (on Value Change), CollapseContext to mvt type in all line items and then use ifelse condition to achieve your result.
    I will give an example of line Item1
    mvt type --->RemoveContext ->Sort>SplitByValue(on value change) --> CollapseContext
    Use the above mapping to IF function and check if it is having X, Y or Z then map the appropriate value to target field.
    Do the same for rest of the line items.

Maybe you are looking for