Summarizing entries of the Internal table--Urgent..plz help

Hi All!!
I have an internal table containing fields f1, f2 ,f3 ..f8.
I want to summarize the entries based on three fields of table f1,f2 and f3.These fields are numeric fields.The other fields have numeric and non numeric fields.One of the field f4 is quantity field which needs to summed.
For example the contents:
1 2 3 4 A 5 6 7
1 2 3 4 A 5 6 7
1 2 3 4 B 5 6 7
3 4 5 5 D 5 6 7
3 4 5 6 D 5 6 7
will be summarized as
1 2 3 8 A 5 6 7
1 2 3 4 B 5 6 7
3 4 5 11 D 5 6 7
4th field is quantity field.It is assumed that if the first 3 fields are same all others numeric field will be same.Non numeric may be different.
Please help in this regard..
Thanks in advance..
Prabhas.

Hi Prabhas,
Decalre your internal table of type HASHED. < See F1 to declare such a table>. with key fields as all the character fields.
Then when you are making the entry in your table Use Collect statement.
like Collect itab.
This should give you the required results.
Use table declaration as Hashed Table only.
Use F1 to get details, In case you need code I can give the same as well.
Hope this helps.
Happly Learning!
Regards,
Lalit

Similar Messages

  • Summarizing entries of the Internal table

    Hi All Experts!!
    I have problem regarding summarizing of the entries of the internal table.I want the amount field of the entries be summed based on 3  fields of table rkst skst rkstar.It means that summation be carried out if the set of these 3  fields are same.If there is different set new entry will be created.
    Here I want to summarize itab gt_yrepost2.
      LOOP AT gt_yrepost2 INTO gwa_yrepost2.
        sum_amount = sum_amount + gwa_yrepost2-amount
    be summed for repeating sets of 3 fields*****
          lwa_sum_yrepost2-amount = sum_amount.
          lwa_sum_yrepost2-kokrs = gwa_yrepost2-kokrs.
          lwa_sum_yrepost2-belnr = gwa_yrepost2-belnr.
          lwa_sum_yrepost2-buzei = gwa_yrepost2-buzei.
          lwa_sum_yrepost2-kstar = gwa_yrepost2-kstar.
          lwa_sum_yrepost2-bukrs = gwa_yrepost2-bukrs.
          lwa_sum_yrepost2-pbukrs = gwa_yrepost2-pbukrs.
          lwa_sum_yrepost2-tcurr = gwa_yrepost2-tcurr.
          lwa_sum_yrepost2-skst = gwa_yrepost2-skst."field1
          lwa_sum_yrepost2-rkst = gwa_yrepost2-rkst."field2
          lwa_sum_yrepost2-rkstar = gwa_yrepost2-rkstar."field3
          lwa_sum_yrepost2-txt = gwa_yrepost2-txt.
          APPEND lwa_sum_yrepost2 TO gt_sum_yrepost2.
    It means that if there is change in set of key fields new entry will be created. Else the entries will be summed to a single entry.In this example gt_sum_yrepost2 contained the summed(summarized) entries.
    The positive thing here is that if for one set of these fields the other values will be same.Hence other fields will take value of any of the repeating entries(with repeated set).
    Please help in this regards..
    Thanks in Advance....
    Prabhas.
    Edited by: PRABHAS jha on Jan 25, 2008 4:34 PM

    Hi Prabhas ,
    You could use Collect statement instead of Append.
    Thanks
    Rekha

  • Number of entries in the internal table for perticular field value

    hi All,
    Is this possible to get the count of records from the internal table for a perticular field value.
    currently my requirement is to get the entries from the internal table which does not have two records for perticular field value (say a = 123) whose status is active (say b = 'X').
    also suggets should use LOOP or DELETE or DESCRIBE for a internal table to ful fill this requirement.
    Thanks in advance.
    Pradeep

    Try like this..
    Create another table itab2 with same structure as itab1 & move the contents of itab1 to itab2
    ITAB2[] = ITAB1[].
    Then delete entries from itab2
    Delete itab2 whete a = '123' and b = 'X'
    Then use Describe statement to get the no of entries
    Describe table itab2 lines v_lines.
    Hope this helps...

  • HANDLING MULTIPLE ENTRIES IN THE INTERNAL TABLE

    Hi guys,
              I got some problem with handling multiple entries from database table. I am retriving four fields and an amount field from the database table and creatinf a file to upload in the application server.But the file has to be taken like below.
          If the four fields which i am retrieving are repeated then we have to take the net amount and make all the entries as one record. else if any of the four fields vary then i have to take it as a seperate record in the internal table. So how can we do this !! I have tried AT NEW and some other logics too but could get the exact one.
      Pls help me out ASAP....

    I think I may have misunderstood your problem.  If you have an exactly match(all four fields), only then you need to collect,  right?
    Try this example.
    report zrich_0002.
    data: begin of itab occurs 0,
          field1(10) type c,
          field2(10) type c,
          field3(10) type c,
          field4 type p decimals 2,
          end of itab.
    data: begin of icheck occurs 0,
          field1(10) type c,
          field2(10) type c,
          field3(10) type c,
          field4 type p decimals 2,
          end of icheck.
    data: begin of itab2 occurs 0,
          field1(10) type c,
          field2(10) type c,
          field3(10) type c,
          field4 type p decimals 2,
          end of itab2.
    start-of-selection.
      itab-field1 = 'A'.
      itab-field2 = 'B'.
      itab-field3 = 'C'.
      itab-field4 = '123.45'.
      append itab.
      itab-field1 = 'A'.
      itab-field2 = 'B'.
      itab-field3 = 'C'.
      itab-field4 = '123.45'.
      append itab.
      itab-field1 = 'A'.
      itab-field2 = 'B'.
      itab-field3 = 'C'.
      itab-field4 = '123.45'.
      append itab.
      itab-field1 = 'A'.
      itab-field2 = 'B'.
      itab-field3 = 'C'.
      itab-field4 = '678.90'.
      append itab.
      loop at itab.
        read table icheck with key field1 = itab-field1
                                   field2 = itab-field2
                                   field3 = itab-field3
                                   field4 = itab-field4.
        if sy-subrc = 0.
          move-corresponding itab to itab2.
          collect itab2.
        else.
          move-corresponding itab to icheck.
          append icheck.
          move-corresponding itab to itab2.
          append itab2.
        endif.
      endloop.
      check sy-subrc  = 0.
    Regards,
    Rich Heilman

  • Counting the Multiple Occurence of a record in the internal Table-Urgent

    Hi,
    I have an internal table with the following values
    a
    a
    a
    b
    b
    b
    c
    c
    I need to print a-2
                         b-3
                         c-2
    How do i accomplish this? i.e.,I need to count the multiple occurence of a field.Any input on this will be of great help.
    Thanks and Regards,
    Pavithra

    Hi,
    Find the piece of code below it can help you:
    data: begin of itab occurs 0,
               field1 type c,
               field2 type i,
            end of itab.
    data: itab2 like table of itab occurs 0 with header line.
    data: count type i.
    start-of-seleciton.
    itab-field1 = a.
    append itab.
    itab-field1 = a.
    append itab.
    itab-field1 = a.
    append itab.
    itab-field1 = b.
    append itab.
    sort itab by field1.
    loop at itab.
      count = count + 1.
    at end of field1.
      clear itab2.
      itab2-field1 = itab-field1.
      itab2-field2 = count.
      append itab2.
    endat.
    endloop.
    Dispaly output table.
    loop at itab2.
      write:/ itab2-field1, itab2-field2.
    endloop.
    Reward the points if it is helpful.

  • Delete duplicate entriess from the internal table its urgent pls help.

    Hi friends,
    Hope everybody is doing good,Here is m query on delete duplicate data from the intenal table.
    I have an internal table which contain data in the following format.
    Doc No Comp Cod Vendor Assignment
    1500000009 JM11 00000000
    1500000008 JM11 20070212(Repeating)
    1500000007 JM11 20070212
    1500000006 JM11 00000000
    1500000005 JM11 00000000
    1500000004 JM11 00000000(Repeating)
    1500000003 JM11 00000000 (Repeating)
    1500000002 JM11 00000000
    1500000001 JM11 20050302
    1500000000 JM11 00000000
    1500000003 JM11 10000088
    1500000001 JM11 10000088
    1500000030 JM11 10006260
    1500000010 JM11 10006269
    1500000008 JM11 10006269
    1500000006 JM11 10006269
    1500000004 JM11 10006269
    if you see the document numbers,there are some document number which are repeating here,there are some document numer which contain vendor number but not the assignments,some of the document numbers contain the assignments but not the vendors.
    If my internal table contain this kind of data with repeted document numbers than i want the document number which contains only the vendor number.
    Pls help me with the appropriate logic,its urgent.
    Thanks a lot
    mrutyun^

    Hi,
    <u><b>Deleting Adjacent Duplicate Entries</b></u>
    To delete adjacent duplicate entries use the following statement:
    DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
    [COMPARING <f1> <f2> ...
    |ALL FIELDS].
    The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are
    duplicate if they fulfill one of the following compare criteria:
      Without the COMPARING addition, the contents of the key fields of the table must be
    identical in both lines.
      If you use the addition COMPARING <f1> <f2> ... the contents of the specified fields <f1>
    <f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as
    the contents of a field <ni> in the form (<ni>). If <ni> is empty when the statement is
    executed, it is ignored. You can restrict the search to partial fields by
    specifying offset and length.
      If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines
    must be identical.
    You can use this statement to delete all duplicate entries from an internal table if the table is
    sorted by the specified compare criterion.
    If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
    Examples
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
    DO 4 TIMES.
    LINE-COL1 = SY-INDEX.
    LINE-COL2 = SY-INDEX ** 2.
    INSERT LINE INTO TABLE ITAB.
    ENDDO.
    LINE-COL1 = 1.
    DELETE TABLE ITAB: FROM LINE,
    WITH TABLE KEY COL1 = 3.
    LOOP AT ITAB INTO LINE.
    WRITE: / LINE-COL1, LINE-COL2.
    ENDLOOP.
    The output is:
    2    4
    4   16
    The program fills a hashed table with a list of square numbers. The DELETE
    statement delete the lines from the table where the key field COL1 has the contents 1 or 3.
    Regards,
    Bhaskar

  • Using for all entries of two internal tables in where clause of the select

    Hi experts,
    My requirement is, need to select Marc-minbe and wrpl-sobst, for all the entries of the two internal tables it_mara , and it_t001w.
    here is the select queries i have used,
    select matnr normt from  mara into it_mara for all entries in it_data where normt = it_data-normt.
    select konnr werks from t001w into it_t001w for all entries in it_data where konnr = it_data-konnr.
    now i need to select minbe of marc table and sobse of wrpl table for all the entries of above internal tables, it_mara and it_t001w, using both matnr of it_mara and werks of it_t001w in where condition.
    Pls advise how i can do it.
    Thanks.
    Moderator message: very basic, please work on this yourself first, these forums are not a substitute for ABAP training.
    Edited by: Thomas Zloch on Dec 6, 2010 9:38 AM

    Hi
    call SE16 with table TFTIT in order to get a full list (it will be long...)
    A list of FMs with parameters can be found in table FUNCT.
    Finally go to sm37rsdf4
    that will give you all the function modules with description
    Here is the list:
    http://www.erpgenie.com/abap/functions.htm
    hope this helps...
    Regards
    CSM Reddy

  • Need clarification to sum the entries in a internal table

    Hi Gurus ,
            Below i have written the logic for have the count of number of records in the internal table along with it i need to find the Total dollar amount of all the records .
    iam not sure how to have that total .
    please provide me the solution .
    you can see at the bottom the where i tryed to sum .
    LOOP AT IT_BKPF.
    *AP ENTRIES
        IF ( ( IT_bkpf-yke_awsys <> ' ' ) AND
                ( It_bkpf-ldgrp = '0L' OR It_bkpf-ldgrp = ' ' ) AND
                 ( IT_BKPF-BLART EQ 'N1' OR IT_BKPF-BLART EQ 'N2' OR IT_BKPF-BLART EQ 'LP' OR
                   IT_BKPF-BLART EQ 'TK' OR IT_BKPF-BLART EQ 'L5' OR IT_BKPF-BLART EQ 'L6' OR
                   IT_BKPF-BLART EQ '1A' OR IT_BKPF-BLART EQ '1B' OR IT_BKPF-BLART EQ '1C' OR
                   IT_BKPF-BLART EQ '1D' OR IT_BKPF-BLART EQ '1E' OR IT_BKPF-BLART EQ '1F' OR
                   IT_BKPF-BLART EQ '1G' OR IT_BKPF-BLART EQ '1H' OR IT_BKPF-BLART EQ '1I' OR
                   IT_BKPF-BLART EQ '1J' OR IT_BKPF-BLART EQ '1K' OR IT_BKPF-BLART EQ '1L' OR
                   IT_BKPF-BLART EQ '1M' OR IT_BKPF-BLART EQ '1N' ) ).
       CLEAR : COUNT_AP_0L ,V_COUNT_AP_0L.
          READ TABLE It_bseg WITH KEY BUKRS = IT_BKPF-BUKRS
                                      BELNR = IT_BKPF-BELNR
                                      GJAHR = IT_BKPF-GJAHR
                                      BINARY SEARCH.
          LOOP AT IT_BSEG FROM SY-TABIX.
            IF IT_BSEG-BUKRS <> IT_BKPF-BUKRS.
           OR IT_BSEG-BELNR <> IT_BKPF-BELNR
           OR IT_BSEG-GJAHR <> IT_BKPF-GJAHR.
              EXIT.
            ENDIF.
            IF SY-SUBRC IS INITIAL .
          COUNT_AP_0L = COUNT_AP_0L + 1.
          MOVE COUNT_AP_0L TO V_COUNT_AP_0L .
          AT END OF DMBTR.
          SUM.
          ENDAT.      ENDIF.
          ENDLOOP.
    Thanks ,
    vinay

    Hi,
    Use the sum statment after AT LAST.  statment.
    regards,
    Santosh Thorat.

  • Fetch the values from internal table inside an internal table (urgent!!)

    data : BEGIN OF PITB2_ZLINFO occurs 0,
             BEGDA LIKE SY-DATUM,
             ENDDA LIKE SY-DATUM,
             PABRJ(4) TYPE N,                       "Payroll Year
             PABRP(2) TYPE N,                       "Pay. Period
             ZL LIKE PC2BF OCCURS 0,
           END OF PITB2_ZLINFO.
    I have a internal table like this,
    How to Fetch the values from internal table inside an internal table.
    Kindly Help me on this..
    Regards,
    Ram.

    Hi,
    Try this....
    Loop at PITB2_ZLINF0.
    Loop at PITB2_ZLINF0-ZL.
    endloop.
    Endloop.
    Thanks...
    Preetham S

  • *How can we use the internal table in module pool programming? Clarify plz*

    If we creating a screen using the table having four fields(for e.g.). The screen has the functions of display, modify, delete, save, exit etc for the fields. The front-end of the screen having I/O fields of the table using internal table. How can we declare the internal table in the screen?

    HI,
    Create one WA for your Internal table and then map it to your fields.
    For Example,
    Data : begin of wa,
              name(10),
              age type i,
               end of wa.
    data : it like table of wa with header line.
    Then in screen create input fields with the name, age and ***.
    Then the user entered values are stored in name age and ***.
    then you can manipulate with that values using wa.
    Thanks.

  • Summarizing records in a internal table

    hi
    what is meant by summarizing records in an internal table
    vamsi

    HI
    please go through this:
    u will get some idea.
    Appending Summarized Lines
    The following statement allows you to summate entries in an internal table:
    COLLECT <wa> INTO <itab>.
    <itab> must have a flat line type, and all of the fields that are not part of the table key must have
    a numeric type (F, I, or P). You specify the line that you want to add in a work area that is
    compatible with the line type.
    When the line is inserted, the system checks whether there is already a table entry that matches
    the key. If there is no corresponding entry already in the table, the COLLECT statement has the
    same effect as inserting the new line [Page 282]. If an entry with the same key already exists, the
    COLLECT statement does not append a new line, but adds the contents of the numeric fields in
    the work area to the contents of the numeric fields in the existing entry.
    You should only use the COLLECT statement if you want to create summarized tables. If you
    use other statements to insert table entries, you may end up with duplicate entries.
    Lines are added to internal tables as follows:
      Standard tables
    If the COLLECT statement is the first statement to fill the standard table, the system
    creates a temporary hash administration that identifies existing entries in the table. The
    hash administration is retained until another statement changes the contents of key fields
    or changes the sequence of the lines in the internal table. After this, the system finds
    existing entries using a linear search. The runtime for this operation increases in linear
    relation to the number of existing table entries. The system field SY-TABIX contains the
    index of the line inserted or modified in the COLLECT statement.
      Sorted tables
    The system uses a binary search to locate existing lines. The runtime for the operation
    increases logarithmically with the number of existing lines. The system field SY-TABIX
    contains the index of the line inserted or modified in the COLLECT statement.
      Hashed tables
    The system finds existing lines using the hash algorithm of the internal table. After the
    COLLECT statement, the system field SY-TABIX has the value 0, since hashed tables
    have no linear index.
    Example
    DATA: BEGIN OF LINE,
    COL1(3) TYPE C,
    COL2(2) TYPE N,
    COL3 TYPE I,
    END OF LINE.
    DATA ITAB LIKE SORTED TABLE OF LINE
    WITH NON-UNIQUE KEY COL1 COL2.
    BC - ABAP Programming SAP AG
    Appending Summarized Lines
    286 April 2001
    LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
    COLLECT LINE INTO ITAB.
    WRITE / SY-TABIX.
    LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
    COLLECT LINE INTO ITAB.
    WRITE / SY-TABIX.
    LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
    COLLECT LINE INTO ITAB.
    WRITE / SY-TABIX.
    LOOP AT ITAB INTO LINE.
    WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
    ENDLOOP.
    Thanks
    Shiva

  • Problem with downloading the internal table onto the presentation server.

    Hey folks,
    I have a problem where in i am downloading one year of sales done by the company. I wrote a program to download the file onto the presentation server . The error occurs in the FM GUI_DOWNLOAD where if the file exceeds 105843504 bytes its giving me a dump saying that
    When the program was running , it was established that more memory was needed than the operating system is able to safely to provide.
    The current program has to be terminted because of the program already requested 105843504 bytes from the operating system with malloc when the operating system reported after further memory request that there was no more memory space available.
    Could somebody provide an alternative soltuion for this.
    Its really urgent as i can download the file with 70,000,000 bytes
    Regards
    Rock

    Hi Rock,
    Please download the files on to Application Server, else as suggested by Ashish download into 2 or 3 files and merge them manually.
    Declare same internal tables may be 5 times.
    When you fill the internal table check for a counter and when you hit a certain number stop appending to it and start appending to the next.
    After you are done so download all the internal tables.
    I guess this would be a good way. I am not sure if there are any ther alternative good methods.
    Hope this helps.
    Shreekant

  • Inserting a record in an internal table - Urgent

    Hi Friends,
    I have a requirement where in I have 2 internal tables say itab1 and itab2.Itab1 has 10 records and itab2 has one record initially.
    Now I have to move the records of itab1 into itab2.
    My question is if some conditions satisfy,then I need to append the records of itab1 after the single record in itab2.In some other cases I need to insert the records of itab1 before
    the single record in itab2.
    What is the syntax to attach the records before the record as append statement always attaches the record after the existing record.
    Your help is highly appreciated.
    Regards,
    Vishnu.

    You can use insert itab index idx .
    Alternative 2
    ... itab INDEX idx
    Effect
    This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.
    If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.
    An exception that cannot be handled is raised when:
    idx contains a value less than or equal to 0
    A line to be inserted would cause a duplicate entry in tables with a unique table key
    A line to be inserted would disrupt the sort order of sorted tables
    Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.
    read help on this .
    reward if helpful

  • Limit on the memory/size of the internal table

    Hi,
    Is there any limit on the size of internal table....?
    we are having some select statements that are fetching huge no. of records into the internal tables...
    can some of the records be missed  or is there any limit on the no. of records or size of the internal table...
    The code that we are using is logically correct and it is working fine for small inputs but for the large selections, some of the records are getting missed as we are displaying the data from these internal tables only...
    We can not debug the code coz for the large inputs, code is taking around 2 to 3 hours of processing
    We are using this code in BI in the end routines
    We are doing the operation like
    itab1 = itab2
    where itab2 contains around 25000 records and itab1 is initial(no entries)
    If there is a limit , then how can we increase the size
    Please suggest..
    Thanks
    Tarun Brijwani
    Edited by: Tarun Brijwani on Apr 23, 2009 6:06 PM
    Edited by: Tarun Brijwani on Apr 23, 2009 6:06 PM

    Hello Tarun
    You can limit the number of records selected by your SELECT statement by adding the addition "UP TO n ROWS" to your SELECT statement.
    Example:
    SELECT * FROM TABLEXYZ UP TO 5000 ROWS WHERE .........
    Hope this helps you.
    Thanks and best regards
    Anand.

  • Size of the internal table

    Hi Experts,
    I would like to ask about the size limit of internal table?
    How many records can I fetch into an internal table?
    iam not getting the correct answer,plz any one can tell me pin point answer.
    Thanks,

    hi ,
    there is no limit for records to the internal table ,its depends on your server memory available.
    internal table is a temporary memory ,so its totally dependent on the memory.
    thanks
    siddharth

Maybe you are looking for

  • Adobe will not open attachment in email.

    I was prompted to update Adobe, now I cannot open the file as an attachment in my outlook. Im running Windows 7 64 bit os. I tried to unistall/reinstall, same issue. Worked fine before the update.

  • How to activate time machine

    How do i create a back-up on my new macbook air? When I rurn on time machine it goes to air port utility and then is unable to connect. Am I doing something wrong ?

  • Information needed

    Hi, I am getting duplicate records while i run a report..Can anyone tell how to resolve it.

  • Trying to Upgrade... Trying to Change my Credit Card Information

    Help... I'm trying to upgrade my storage. I no longer have the bank account that's on file. It's not allowing me to change the credit card info. Any ideas? Thanks!

  • Opening a Final Cut Express File with Final Cut Pro

    I recently got a copy of Final Cut Pro to use at home. I have access to a lab that uses Final Cut express. I had to use the lab computers to capture the project. (I'm still missing some equipment...) I saved everything onto a USB flash drive to bring