Regarding collect

selection screen has 2 options
detail
summary
already one internal table is getting the detailed values.
now i have write code for summary
when summary is clicked
the output shoul be sorted by matnr and all  the similar
matnr should be consolidated .ie all the qunatity
and price values should be totalled for similar matnr.
please let me knwo ur suggestions for logic of this
FORM SUMMARY_REPORT .
sort tbl_output by matnr.
loop at tbl_output.
MOVE-CORRESPONDING tbl_output TO tbl_output1.
append tbl_output1.
ENDLOOP.
sort tbl_output1 by matnr.
loop at tbl_output1.
at end of matnr.
sum.
endat.
endloop.

hi i have put teh do_sum = x
but where should i sort matnr and put subtot = x??
PERFORM write_fieldcat1 USING 'WERKS' 'TBL_OUTPUT' 'AUFK' 'X' 1 ' ' ' '.
  PERFORM write_fieldcat1 USING 'AUFNR' 'TBL_OUTPUT' 'AUFK' ' ' 2 ' ' ' '.
  PERFORM write_fieldcat1 USING 'MATNR' 'TBL_OUTPUT' 'AFPO' ' ' 3 ' ' ' '.
  if p_sum = 'X'.
    PERFORM write_fieldcat1 USING 'WKG010' 'TBL_OUTPUT' ' ' ' ' 4 'PV Alum' 'X'.
    PERFORM write_fieldcat1 USING 'WKG0102' 'TBL_OUTPUT' ' ' ' ' 5 'PV Cemt' 'X'.
    PERFORM write_fieldcat1 USING 'WKG0103' 'TBL_OUTPUT' ' ' ' ' 6 'PV Ceno' 'X'.
    PERFORM write_fieldcat1 USING 'WKG0104' 'TBL_OUTPUT' ' ' ' ' 7 'PV Pulp' 'X'.
    PERFORM write_fieldcat1 USING 'WKG0105' 'TBL_OUTPUT' ' ' ' ' 8 'PV Silica' 'X'.
    PERFORM write_fieldcat1 USING 'WKG0106' 'TBL_OUTPUT' ' ' ' ' 9 'PV MACDO' 'X'.
    PERFORM write_fieldcat1 USING 'WKG0107' 'TBL_OUTPUT' ' ' ' ' 10 'PV NonFM' 'X'.
endif.
FORM WRITE_FIELDCAT1  USING    name tab st key pos desc sum.
  st_fieldcat-fieldname = name.
  st_fieldcat-tabname = tab.
  st_fieldcat-ref_tabname = st.
  st_fieldcat-key = key.
  st_fieldcat-col_pos = pos.
  st_fieldcat-seltext_m = desc.
  st_fieldcat-do_sum = sum.
  APPEND st_fieldcat TO tbl_fieldcat.
  CLEAR st_fieldcat.
ENDFORM.                    " WRITE_FIELDCAT1

Similar Messages

  • Doubt Regarding Collection Methods

    Hello,
    I am working on Oracle version 10g Release 2
    I wanted to know that how can we find a particular name (person) exists in a Collection..
    Below is my Code
    DECLARE
    TYPE nested_tab IS TABLE OF VARCHAR2(100);
    l_tab nested_tab := nested_tab();
    BEGIN
    SELECT e.ent_id BULK COLLECT INTO l_tab
    FROM entity_master e
    WHERE e.ent_id IN ('N002208', 'Z002011', 'V002313', 'X002011'..... & so on);
    IF l_tab.EXISTS('N002208') THEN
    dbms_output.put_line('element exists');
    ELSE
    dbms_output.put_line('NO element ');
    END IF;
    END;
    ORA-06502 - Numeruc or Value Error
    what can be the work around for this...?

    Aijaz Mallick wrote:
    Ok.
    But It would be really helpfull if you Elaborate this Example a Bit...
    I mean the I/O part because Quering table also Require I/OANY data that you need to access (in any computer system and language) requires I/O. That data needs to be read from disk (PIO or physical I/O) or buffer cache (LIO or logical I/O) and processed.
    So the important part is optimising I/O. If you only need 1MB of data from a 100GB data structure, you do not want to I/O that entire data structure to find that 1MB of data that is relevant to your code.
    The answer to this is three fold.
    Firstly, you design that data structure optimally. In databases, that means a proper and sound relational database model.
    Secondly, you implement that data structure optimally. In databases, that means using the most appropriate physical data model for storing that relational data model. Using the features like indexing, partitioning, index organised tables, and so on.
    Lastly, in some cases your requirements will require scanning a large volume of that data structure. Which means that there is no option but to use a lot of I/O. In such a case, parallelising that I/O is important. I/O has inherent latency. Which means idle time for your code, waiting for data to arrive from the I/O system. Parallel processing enables one to address this and increase performance and scalability.
    So what do you need to do with your "large" table?
    - make sure it is correctly modelled at a logical data model level
    - make sure it is optimally implemented physically in Oracle, making best use of the features that the Oracle RDBMS provide
    - when your code has to deal with large volumes of data, design and code for parallel processing
    & how about Java Part. ..?Java is worse than PL/SQL in this regard as the data path for data to travel from the database layer into Java is longer and slower than the same path to PL/SQL.
    Storing/caching that data in the application layer is an attempt to address the cost of this data path. But this is problematic. If another application makes a change to data in the database, the cached data in the application tier is stale - and incorrect. Without the application layer knowing about it.
    Storing/caching that data in the application layer means a bigger and more expensive h/w footprint for the application layer. It means that scaling also requires a cluster cache in the application layer to address scalability when more application servers are added. This is complex. And now reintroduce a data path that runs over the network and across h/w boundaries. Which is identical to the data path that existed between the database layer and application layer in the first place.
    It also makes the border between the database layer and application layer quite complex as caching data in the application layer means that basic database features are now also required in the application layer. It is an architectural mess. Contains complex moving parts. Contains a lot more moving parts.
    None of this is good for robustness or performance or scalability. Definitely not for infrastructure costs, development costs,and support and maintenance costs, either.
    In other words, and bluntly put. It is the idiotic thing to do. Unfortunately it is also the typical thing done by many J2EE architects and developers as they have a dangerous and huge lack of knowledge when it comes to how to use databases.

  • Regarding collect statement - Production report

    Dear Experts,
    I've the following requirement
    A ) I'm creating a ALV report from Z table where i want the summary of the qty across different processing type like CT , ST , WS  & FG .
    B ) For each processing types i want the total qty to be displayed in different columns.
    C ) When i'm trying to execute , no data is displaying..
    Piece of coding is as below..  Request help to clear the below issue..
    REPORT  ZPP_PRD_REPORT.
    TABLES : ZPP_ACTUAL_PRD.
    TYPES : BEGIN OF TY_ACTUAL_PRD,
             KDAUF TYPE KDAUF,
             KDPOS TYPE KDPOS,
             WERKS TYPE WERKS_D,
             PROCTYP TYPE ZDE_PP_PROCTYP,
             AUFNR TYPE AUFNR,
             MEINS TYPE MEINS,
       END OF TY_ACTUAL_PRD.
       TYPES : BEGIN OF TY_FINAL,
             KDAUF TYPE KDAUF,
             KDPOS TYPE KDPOS,
             WERKS TYPE WERKS_D,
             PROCTYP TYPE ZDE_PP_PROCTYP,
             AUFNR TYPE AUFNR,
             MEINS TYPE MEINS,
         END OF TY_FINAL.
       DATA : GT_ACTUAL_PRD TYPE TABLE OF TY_ACTUAL_PRD,
              GS_ACTUAL_PRD TYPE TY_ACTUAL_PRD,
              GT_ACTUAL_PRD_COLLECT TYPE TABLE OF TY_ACTUAL_PRD.
       DATA : GT_FINAL TYPE TABLE OF TY_FINAL,
              GS_FINAL TYPE TY_FINAL.
        DATA : GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
               GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
          DATA : GT_EVENTS TYPE SLIS_T_EVENT.
           DATA : GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
           DATA : GS_REPID LIKE SY-REPID.
      SELECT-OPTIONS : S_KDAUF FOR ZPP_ACTUAL_PRD-KDAUF,
                        S_KDPOS FOR ZPP_ACTUAL_PRD-KDPOS.
      START-OF-SELECTION.
                     PERFORM GET_DATA.
                     PERFORM POPULATE_DATA1.
    *&      Form  GET_DATA
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM GET_DATA .
       SELECT
              KDAUF
              KDPOS
              WERKS
              PROCTYP
              AUFNR
              MEINS
    FROM ZPP_ACTUAL_PRD INTO TABLE GT_ACTUAL_PRD WHERE KDAUF IN S_KDAUF AND
                                                  KDPOS IN S_KDPOS.
    ENDFORM.                    " GET_DATA
    *&      Form  POPULATE_DATA1
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM POPULATE_DATA1 .
       LOOP AT GT_ACTUAL_PRD INTO GS_ACTUAL_PRD.
         GS_FINAL-KDAUF = GS_ACTUAL_PRD-KDAUF.
         GS_FINAL-KDPOS = GS_ACTUAL_PRD-KDPOS.
         GS_FINAL-WERKS = GS_ACTUAL_PRD-WERKS.
         GS_FINAL-PROCTYP = GS_ACTUAL_PRD-PROCTYP.
         GS_FINAL-AUFNR = GS_ACTUAL_PRD-AUFNR.
         GS_FINAL-MEINS = GS_ACTUAL_PRD-MEINS.
       COLLECT GS_ACTUAL_PRD INTO GT_ACTUAL_PRD_COLLECT.
    ENDLOOP.
    ENDFORM.                    " POPULATE_DATA1
    *&      Form  BUILD_FIELDCATALOG
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM BUILD_FIELDCATALOG .
       GS_FIELDCAT-FIELDNAME = 'KDAUF'.
       GS_FIELDCAT-SELTEXT_M = 'SALESORDER'.
       GS_FIELDCAT-OUTPUTLEN = 10.
       GS_FIELDCAT-DO_SUM = 'X'.
       GS_FIELDCAT-NO_ZERO = 'X'.
       APPEND GS_FIELDCAT TO GT_FIELDCAT.
       CLEAR GS_FIELDCAT.
       GS_FIELDCAT-FIELDNAME = 'KDPOS'.
       GS_FIELDCAT-SELTEXT_M = 'SALESITEM'.
       GS_FIELDCAT-OUTPUTLEN = 10.
       GS_FIELDCAT-DO_SUM = 'X'.
       GS_FIELDCAT-NO_ZERO = 'X'.
       APPEND GS_FIELDCAT TO GT_FIELDCAT.
       CLEAR GS_FIELDCAT.
       GS_FIELDCAT-FIELDNAME = 'WERKS'.
       GS_FIELDCAT-SELTEXT_M = 'PLANT'.
       GS_FIELDCAT-OUTPUTLEN = 10.
       GS_FIELDCAT-DO_SUM = 'X'.
       GS_FIELDCAT-NO_ZERO = 'X'.
       APPEND GS_FIELDCAT TO GT_FIELDCAT.
       CLEAR GS_FIELDCAT.
       GS_FIELDCAT-FIELDNAME = 'PROCTYP'.
       GS_FIELDCAT-SELTEXT_M = 'TYPE'.
       GS_FIELDCAT-OUTPUTLEN = 10.
       GS_FIELDCAT-DO_SUM = 'X'.
       GS_FIELDCAT-NO_ZERO = 'X'.
       APPEND GS_FIELDCAT TO GT_FIELDCAT.
       CLEAR GS_FIELDCAT.
    GS_FIELDCAT-FIELDNAME = 'AUFNR'.
       GS_FIELDCAT-SELTEXT_M = 'ORDER'.
       GS_FIELDCAT-OUTPUTLEN = 10.
       GS_FIELDCAT-DO_SUM = 'X'.
       GS_FIELDCAT-NO_ZERO = 'X'.
       APPEND GS_FIELDCAT TO GT_FIELDCAT.
       CLEAR GS_FIELDCAT.
       GS_FIELDCAT-FIELDNAME = 'MENGE'.
       GS_FIELDCAT-SELTEXT_M = 'QTY'.
       GS_FIELDCAT-OUTPUTLEN = 10.
       GS_FIELDCAT-DO_SUM = 'X'.
       GS_FIELDCAT-NO_ZERO = 'X'.
       APPEND GS_FIELDCAT TO GT_FIELDCAT.
       CLEAR GS_FIELDCAT.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  ALV_DISPLAY
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM ALV_DISPLAY .
       GS_REPID = SY-REPID.
       IF GS_REPID IS NOT INITIAL.
         CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
             I_CALLBACK_PROGRAM = GS_REPID
             IT_FIELDCAT        = GT_FIELDCAT[]
             IT_EVENTS          = GT_EVENTS[]
             I_SAVE             = 'A'
             I_DEFAULT          = 'X'
           TABLES
             T_OUTTAB           = GT_ACTUAL_PRD_COLLECT
           EXCEPTIONS
             PROGRAM_ERROR      = 1
             OTHERS             = 2.
         IF SY-SUBRC <> 0.
           MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
         ENDIF.
       ENDIF.
    ENDFORM.                    " ALV_DISPLAY
    Z Data base table looks as below..
    Best rgds/thnks,
    Srikanth.

    Hi  Sankara ,
        Collect statement is used to add all the numeric components to the corresponding values of all the existing rows in an internal table , with the same key . The data type can be I , P , F .
        Please ensure that there is a comman value  in all the rows .
       check this out and let me know if any issues
    Regards,
    Kavitha

  • Infor regarding Collections from customers

    Dear SAP gurus
    goodmorning
    as I need some information regarding Accounts Receivable.
    our client is distributing power to customers and receives the collections from the customers/consumers. Now the issues is that if a customer is not paid the bill amount (became defaultee) for the past two months and also for the current month.  In the current month he paid some amount towards the settlement of arrears. We are planing to charge interest for the arrears of bill amout and it should show as open item.
    Where should I configure these settings and assign them.
    Is it possible to configure at the payment terms and assign a new GL account with the arrears of interest.
    thanks in advance
    pls suggest me in this issue
    thanks and regards
    Kishore
    Hyderabad

    Hi,
    Please check with these reports.
    S_ALR_87012177 - Customer Payment History
    S_ALR_87012178 - Customer Open Item Analysis by Balance of Overdue Items
    Thanks
    Prasada

  • Regarding  Collective Documents

    Dear All,
             I have to create One Commercial Invoice with reference to more than one order, how it is possible.Also PO nos are differents.
             Also i have to create one order with reference to more than one quotations.
             one Invoice with reference to One or more Delivery.
           Plz send soluntion.
          Award pts for useful answers.
    Thx & Regards,
    Pankaj

    Hi
    You can create One order with many quotations.First create the order with reference to Quotation.In sales order screen again create with reference to quotation,the item will added in the sales order.
    For Creating one Invoice with reference to one or more delivery the below are prerequisite. All the below should be same.
    payer
    billing date
    payment terms
    Use T-code VF04 and select the invoices and execute the collective document this will combine the delivery documents into one invoice.Hope this will clear your doubts to certain extent
    Regards
    Ramesh

  • Regarding COLLECT stmt usage in an ABAP Program.

    Hi All,
    Could anyone please explain if the COLLECT statement really hampers the performance of the program, to a large extent.
    If it is so, please explain how the performance can be improved with out using the same.
    Thanks & Regards,
    Goutham.

    COLLECT allows you to create unique or summarized datasets. The system first tries to find a table entry corresponding to the table key. (See also Defining Keys for Internal Tables). The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa. The line type of itab must be flat - that is, it cannot itself contain any internal tables. All the components that do not belong to the key must be numeric types ( ABAP Numeric Types).
    Notes
    COLLECT allows you to create a unique or summarized dataset, and you should only use it when this is necessary. If neither of these characteristics are required, or where the nature of the table in the application means that it is impossible for duplicate entries to occur, you should use INSERT [wa INTO] TABLE itab instead of COLLECT. If you do need the table to be unique or summarized, COLLECT is the most efficient way to achieve it.
    If you use COLLECT with a work area, the work area must be compatible with the line type of the internal table.
    If you edit a standard table using COLLECT, you should only use the COLLECT or MODIFY ... TRANSPORTING f1 f2 ... statements (where none of f1, f2, ... may be in the key). Only then can you be sure that:
    -The internal table actually is unique or summarized
    -COLLECT runs efficiently. The check whether the dataset
    already contains an entry with the same key has a constant
    search time (hash procedure).
    If you use any other table modification statements, the check for entries in the dataset with the same key can only run using a linear search (and will accordingly take longer). You can use the function module ABL_TABLE_HASH_STATE to test whether the COLLECT has a constant or linear search time for a given standard table.
    Example
    Summarized sales figures by company:
    TYPES: BEGIN OF COMPANY,
            NAME(20) TYPE C,
            SALES    TYPE I,
          END OF COMPANY.
    DATA: COMP    TYPE COMPANY,
          COMPTAB TYPE HASHED TABLE OF COMPANY
                                    WITH UNIQUE KEY NAME.
    COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.
    COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB.
    Table COMPTAB now has the following contents:
              NAME    | SALES
              Duck    |   40
              Tiger   |   20

  • Regarding collecting the BW objects through the transport conn- in backend

    Hi All,
    I am trying to collect all the In data flow afterwards objects of a cube through the transport connection.
    But it is more time as a result I am unable to retrive the result because of system timeout.
    My question is, is there any way to perform the abovementioned function in the backend. If yes, how exactly.
    Thanks with regards,
    Vinay H.S

    Hi Murali,
    Thanks a lot for the response.
    I have checked it for the Info Object and it is in the respective package. But,the data elements and domains are still in $TMP .
    Regards,
    Manjari.

  • Regarding collecting messages until you get particular payload

    Hi All,
    I am having below requirement,
      I am getting several messages from source, i need to collect all the messages, until i get TRAILER message
    Condition is " COLLECT THE PAYLOAD UNTILL YOU GET DTS IN PAYLOAD(TRAILER)". so we need to collect header message and data messages untill you get trailer message.
    message1(Header message which contains DHS)like below  
        20090604034447338isc                 DHS64    500d3100033d705050258002f86300
    message2(data message which contains DDS) like below
               20090604034447338isc                 DDS64    50031s000337050502580d0286300
               20090604034447338isc                 DDS64    5003100033705050d25800286300
    Message3(data message) like below
               20090604034447338isc                 DDS64    500310003370505025800286300
               20090604034447338isc                 DDS64    500310003370505025800286300
               20090604034447338isc                 DDS64    5003100033d7050502580f0286300
    Message4(trailer which contains DTS) like below 
               20090604034447338isc                 DTS64    500310003370505025800286300
    So 4th message contains 3 charcters DTS, now i need to end the collecting messages in loop and need to send the collected messages to target.
    Presently i am using PI7.1 which contains some patters to use as XPath for end condition purpose. I am using Contains Patter(CP) in loop end condition. according to my understanding the collection in loop has to end when it find DTS in message. but it is not working. Please share you ideas whether Contains Patterns suitable for my requirement
    or not and is there any other better approach for this requirement?
    Thanks & Regards,
    Madhusudhan

    Hi,
    Thanks for your valuable reply,
    As you told i implemeted the logic for loop end condition like below
    Value CP 'DTS'
    Value is condition variable in xpath according to PI7.1.
    Now according to above xpath, if DTS found in payload at any place. The loop has to end, but now even there is no DTS in payload the loop is getting complete and messages are going to target.
    Thanks,
    Madhu
    Edited by: Madhusudana Reddy on Aug 5, 2009 9:13 PM
    Edited by: Madhusudana Reddy on Aug 5, 2009 9:24 PM
    Edited by: Madhusudana Reddy on Aug 5, 2009 9:25 PM

  • Doubt Regarding Collection

    Hello,
    How can we perform a search inside a collection Variable ...
    Like ... we use a IN .... If Yes then how ..?

    Below is the illustration to query a collection in a where clause.
    create or replace type test_coll as object(a number, b number);
    create or replace type test_collnest as table of test_coll;
    create table test_nestab(col1 number, col2 test_collnest) nested table col2 store as tab_nest
    SQL> ed
    Wrote file afiedt.buf
    1* insert into test_nestab values (&n,test_collnest(test_coll(&n,&n)))
    SQL> /
    Enter value for n: 1
    Enter value for n: 100
    Enter value for n: 200
    old 1: insert into test_nestab values (&n,test_collnest(test_coll(&n,&n)))
    new 1: insert into test_nestab values (1,test_collnest(test_coll(100,200)))
    1 row created.
    SQL> /
    Enter value for n: 2
    Enter value for n: 200
    Enter value for n: 300
    old 1: insert into test_nestab values (&n,test_collnest(test_coll(&n,&n)))
    new 1: insert into test_nestab values (2,test_collnest(test_coll(200,300)))
    1 row created.
    SQL> /
    Enter value for n: 3
    Enter value for n: 300
    Enter value for n: 400
    old 1: insert into test_nestab values (&n,test_collnest(test_coll(&n,&n)))
    new 1: insert into test_nestab values (3,test_collnest(test_coll(300,400)))
    1 row created.
    Query the collection using TABLE function
    1* select t1.col1,t2.* from test_nestab t1, table(t1.col2) t2
    SQL> /
    COL1 A B
    1 100 200
    2 200 300
    3 300 400
    Where Query based on collection attribute
    1 select t1.col1,t2.* from test_nestab t1, table(t1.col2) t2
    2* where t2.a = 200
    SQL> /
    COL1 A B
    2 200 300

  • Regarding Collections and maximum Items

    Hi
    HTML DB has a restriction of 100 items per page.
    Is there any other way that I can include 190 items on a page?
    Can I do this using collections?
    Thanks in advance
    Ameya.

    Assumed you have a report on page one with the primary key in the first column named
    MY_PK,
    then edit the link attributes of the element/column MY_PK:
    Link Text: maybe #MY_PK# or one of the icons ....
    Target: Page in this Application
    Page: 2
    Name (Item 1) P2_MY_PK
    Value(Item 1) #MY_PK#
    The element P2_MY_PK must exist on Page 2, it will contain your Primary Key.
    If you like to have another sql report on Page 2 based on this primary key, do something like
    select first_col, second_col, third_col
    from second_table
    where second_col = :P2_MY_PK
    If you like to have on the first page two links, one for page 2 and one for page 3
    , then you need two columns. I would suggest
    a column with LinkText: Icon 1
    Page 2
    Name (Item 1) P2_MY_PK
    Value(Item 1) #MY_PK#
    a column with LinkText: #MY_PK#
    Page 3
    Name (Item 1) P3_MY_PK
    Value(Item 1) #MY_PK#

  • Regarding collection objects

    I happened to view this program in the net.
    import java.util.*;
    public class FindDups {
    public static void main(String[] args) {
    Comparator<String> comparator = new Comparator<String>() {
    public int compare (String s1, String s2) {
    return s1.compareToIgnoreCase(s2);
    SortedSet<String> s = new TreeSet<String>(comparator);
    for (String a : args)
    if (!s.add(a))
    System.out.println("Duplicate detected: " + a);
    System.out.println(s.size() + " distinct words: " + s);
    When i compile and run ,its working properly.Am not able to get a hang of this piece of code.
    My doubt is why there is a semi colon after the braces ?
    why have they given <string> in between?

    The <String> part is explained in Generics (http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf)
    The semicolon after the closing brace is necesary beacuse it's an anonymous inner class (http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html)
    Comparator<T> is an interface. The code is creating an implementation of the interface.

  • Question regarding Collections Library Usage/Behaviour

    Hi All,
    I am trying to write a dynamic JSON formatter based on my business logic. I am trying something like this:
    Code:
    JSONArray testArray= new JSONArray();
    JSONObject obj1 = new JSONObject();
    obj1.put("TestKey","Test Value");
    testArray.add(obj1);This works perfectly with the JSONObject showing up in the JSONArray.
    However, when I try an anonymous class or simultanous JSONObject.put() inside JSONArray. The size of the array is updated but not the ENTRY i.e. I cant see any Key Value pair updated inside the array.
    Code:
    import org.json.simple.JSONObject;
    import org.json.simple.JSONValue;
    import org.json.simple.JSONArray;
    JSONArray testArray= new JSONArray();
    JSONObject obj1 = new JSONObject();
    testArray.add(obj1.put("TestKey","TestValue"));
    [OR]
    testArray.add(new JSONObject().put("TestKey","TestValue"));In follow up with them same discussion, when I try the following snippet:
    public static void main(String[] args)
           Set<HashMap<String,String>> testObj = new HashSet<HashMap<String,String>>();
            test.add((HashMap)(new HashMap().put("test","value")));       
        }I still can't see any HshMap object created in testObj. I want to know why is it failing this way?
    Thank you all in advance.
    Note: Please excuse me if this post is not allowed here. I am posting it here as the API for JSON formatting i.e.JSONArray and JSONObject classes are straightforward extensions to ArrayList and HashMap.
    Harsh
    Edited by: codeNombre on Aug 26, 2010 6:23 PM

    test.add((HashMap)(new HashMap().put("test","value")));        You're making an incorrect assumption about what HashMap.put() returns. Check it.

  • Question regarding Collections.binarySearch()

    I was looking at the source of the binarySearch implementation, and while most of it is perfectly clear, I just don't get why the method
    returns -(low 1)+ instead of -low when the desired item has not been found.
    The doc says it should return in this case -(insertionpoint) - 1 but this makes no sense for me.
    Thanks in advance :-).

    Well done figuring it out. It gives a good sense of satisfaction to lead someone to the answer instead of just spoon-feeding like most posters seem to expect!
    BTW: It does also explain that in the Javadoc ;-)
    (And don't forget the dukes...)

  • Proble regarding collections

    // studentExeTreeSet.java
    This program compiles with no error or warning but at runtime it throws ClassCastExeption , plz help me ..........!
    import java.util.*;
    class Student implements Comparator
         private int age;
         private String name;
         private int phoneNo;
         public Student(String n,int a,int p)
         this.name=n;
         this.age=a;
         this.phoneNo=p;
         public int getAge()
         return age;
         public int getPhone()
         return phoneNo;
         public String getName()
         return name;
         public int compare(Object ob1,Object ob2)
         Student p=(Student)ob1;
         Student p1=(Student)ob2;
              if (p.getAge()>p1.getAge())
              return 1;
              else if (p.getAge()<p1.getAge())
              return -1;
              else
              return 0;
         public class studentExeTreeSet
              public static void main(String ar[])
              Student s1=new Student("manoj",25,2766300);
              Student s2=new Student("shankar",28,2766300);
              Student s3=new Student("akhil",26,87444546);
              TreeSet obj=new TreeSet();
              obj.add(s1);
              obj.add(s2);
              obj.add(s3);
              Iterator i=obj.iterator();
                   while(i.hasNext())
                   Student t=(Student) i.next();
                   System.out.println(t.getName()+ " " + t.getAge() + " " + t.getPhone());
         }

    You should implement Comparable, not Comparator. So, you will need compareTo instead of compare.And, from the error message you are getting (and what line it occurs on) before you make the change I suggested above, you should be able to figure out why the above change is required. (Instead of just taking my word for it, investigate it, and learn why my suggestion is correct.)

  • Issue while using Collect statement in program

    Hi friend's,
    i have some issue regarding Collect statement..
    Issue is somthing like this,i have created a structure and internal table and work area with same type,
    u can look in below code..i wann to collect 'enmng' f'ield value whose matnr,charg,mvt type ,aufnr,rsnum are same but rspos and lgort are differnt for this i need to collect 'ENMNG' field value can any one tel me what to do...it not collectng value instead of this it append entire row...
    types: begin of ty_resb,
            rsnum   type resb-rsnum,                "Resrvation Number
            rspos   type resb-rspos,                "item position
            xloek   type resb-xloek,                "Item Deleted  if = 'X'
            matnr   type resb-matnr,                "Material Number
            lgort   type resb-lgort,                "Storage location  'REJT'
            charg   type resb-charg,                "Batch No
            enmng   type resb-enmng,                "Quantity withdrawn should be greater then '0'
            enwrt   type resb-enwrt,                "Value Withdrawn
            aufnr   type resb-aufnr,                "Order
            bwart   type resb-bwart,                "Movement type
       end of ty_resb.
    data:tt_resb  type table of  ty_resb ,
          tt_resb1 type table of ty_resb ,
          tt_resb2 type standard table of ty_resb ,
    **workarea.
          ts_resb type ty_resb,
          ts_resb2 type ty_resb,
          ts_resb1 type ty_resb.
    **move data to another internal table
    tt_resb1[] = tt_resb[].
    sort tt_resb  by rsnum rspos matnr charg bwart lgort aufnr .
    sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
    DELETE adjacent duplicates from tt_resb  comparing rsnum rspos matnr charg bwart lgort aufnr .
    DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
    loop at tt_resb into ts_resb .
    clear:ts_resb1,ts_resb2.
    read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
                                                charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
    if ts_resb1-bwart = '261' .
        move ts_resb1-aufnr to ts_resb2-aufnr.
        move ts_resb1-matnr to ts_resb2-matnr.
        move ts_resb1-charg to ts_resb2-charg.
        move ts_resb1-bwart to ts_resb2-bwart.
        move ts_resb1-enwrt to ts_resb2-enwrt.
        move ts_resb1-lgort to ts_resb2-lgort.
        move ts_resb1-enmng to ts_resb2-enmng.
        collect ts_resb2 into tt_resb2.
    endif.
    clear ts_resb.
    endloop.
    Regard's,
    shaikh khalid.

    Hi Shaikh,
    I have added new declarations as highlighted below and new lines within your loop:
    Execute your program in debug mode and see what happens to the internal tt_collect I added. The collect will sum the fields enmng for all entries that  have same value on the fields matnr,charg,mvt type ,aufnr,rsnum.
    Question from me: what do you want to do with the collected/Summed up entries?
    types: begin of ty_resb,
            rsnum   type resb-rsnum,                "Resrvation Number
            rspos   type resb-rspos,                "item position
            xloek   type resb-xloek,                "Item Deleted  if = 'X'
            matnr   type resb-matnr,                "Material Number
            lgort   type resb-lgort,                "Storage location  'REJT'
            charg   type resb-charg,                "Batch No
            enmng   type resb-enmng,                "Quantity withdrawn should be greater then '0'
            enwrt   type resb-enwrt,                "Value Withdrawn
            aufnr   type resb-aufnr,                "Order
            bwart   type resb-bwart,                "Movement type
       end of ty_resb.
    data:tt_resb  type table of  ty_resb ,
          tt_resb1 type table of ty_resb ,
          tt_resb2 type standard table of ty_resb ,
    types: begin of ty_collect,
      rsnum   type resb-rsnum,
      matnr   type resb-matnr,
      charg   type resb-charg,
      bwart   type resb-bwart,
      aufnr   type resb-aufnr, 
      enmng   type resb-enmng,
           end of ty_collect.
    data: tt_collect type table of ty_collect,
          ts_collect type ty_collect.
    **workarea.
          ts_resb type ty_resb,
          ts_resb2 type ty_resb,
          ts_resb1 type ty_resb.
    **move data to another internal table
    tt_resb1[] = tt_resb[].
    sort tt_resb  by rsnum rspos matnr charg bwart lgort aufnr .
    sort tt_resb1 by rsnum rspos matnr charg bwart lgort aufnr.
    DELETE adjacent duplicates from tt_resb  comparing rsnum rspos matnr charg bwart lgort aufnr .
    DELETE adjacent duplicates from tt_resb1 comparing rsnum rspos matnr charg bwart lgort aufnr.
    loop at tt_resb into ts_resb .
    clear:ts_resb1,ts_resb2.
    read table tt_resb1 into ts_resb1 with key rsnum = ts_resb-rsnum rspos = ts_resb-rspos matnr = ts_resb-matnr
                                                charg = ts_resb-charg aufnr = ts_resb-aufnr binary search.
    if ts_resb1-bwart = '261' .
        move ts_resb1-aufnr to ts_resb2-aufnr.
        move ts_resb1-matnr to ts_resb2-matnr.
        move ts_resb1-charg to ts_resb2-charg.
        move ts_resb1-bwart to ts_resb2-bwart.
        move ts_resb1-enwrt to ts_resb2-enwrt.
        move ts_resb1-lgort to ts_resb2-lgort.
        move ts_resb1-enmng to ts_resb2-enmng.
        collect ts_resb2 into tt_resb2.
         move-corresponding ts_resb1 to ts_collect.
         collect ts_collect into tt_collect
    endif.
    clear ts_resb.
    clear ts_collect.
    endloop.

Maybe you are looking for

  • Po message output issue

    HI experts, I got an issue regarding po's output message related one here is issue : In my production system some messages(NEU) type are deleted manually (in me22n). next day to the same PO's NEU type message is sent to vendor with out physical trigg

  • PO confirmation from Customer Backend System

    Dear experts, I'm implementing SMI scenario with SAP SNC 5.1. I was traying to send a PO confirmation from Custoemr Backend system (ECC) to SNC. The process is this: 1) Supplier creates and publish a Replenishment Order in SNC 2) SNC sends to Custoem

  • How to export iPhoto Album in iMAC and have similar folder structure(with Timestamps) which can be viewed in finder

    How to export iPhoto Album in iMAC and have similar folder structure(with Timestamps) which can be viewed in finder In simple terms, I wanted to view the photos in Windows system, similar strcture of iPhotos

  • Change back and icloud account iphone 5

    Hello, my boyfriend connected his iphone to his cousin mac computed and it synked with his cousin icloud so he lost all his information. Even his background pictured changed and his emails accounts!! We need to know how to change back his icloud acco

  • Clone stamp tool - one layer to another

    If I have two layer and I want to use "Clone stamp tool" to clone from layer one to layer two ?