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

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...

  • 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

  • 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.

  • I want to create a mail merge for address labels into a table, but when I fill a table with merge fields, it ends up creating multiple entries for the same address, rather than one table full of each address.

    ...but when I fill a table with merge fields, it ends up creating multiple entries for the same address, rather than one table full of each address. Please help.
    Thanks!

    That is a quirk of Pagesthat  it applies only one record per page.
    There is a way around this:
    http://www.freeforum101.com/iworktipsntrick/viewtopic.php?t=245&highlight=labels &mforum=iworktipsntrick
    Peter

  • Multiple entries in the table cabn

    Hello,
    Can Anyone tell me how is it possible to have multiple entries of the same "atnam" field in the table CABN.
    It has something to do with changing number.
    Because I used a wrong select-instruction e.g.
    select atnam in charact where .... IN ....
    So, I shoud used
    select DISTINCT atnam in charact where .... IN ....
    So, I'm gone need to try to put multiple entries in the table to check, if it's working well.
    Thanks a lot.
    Best Regards,
    Kais

    If I understand your Q - you mean there are two ATINN for the same ATNAM in your CABN table?
    I dont think that's possible. If you check CT04 and try to create a new characteristic with same name as an existing one - it will give you a warning and prevent creation.
    Since you say it's a standard characteristic - please mention the characteristic name (ATNAM)?

  • Extract Cube data for all entries of an internal table

    Hi
    I want to fetch the data from the cube for all entries of another internal table.
    Scenario : Fetching the COMPANY_CODE and DATE into an internal table and for those company codes and Dates, I have to fetch the records of the Cube.,
    I am using the Function Module : RSDRI_INFOPROV_READ
    But not sure how to accommodate the multiple selections condition for this.
    Selection Required:
                                    *For all entries of it_cc
                                      where comp_code = it_cc-comp_code and
                                                  date = it_cc-date.*
    Please help me how to such multiple conditions and "for all entries" functionality for fetching the data from the cube.
    Thanks.
    Veera Karthik G

    HI
    You can try like this
    LOOP AT lt_donotcall_old .
    <ls_donotcall>-examination_date = sy-date.
    <ls_donotcall>-examination_time = sy-time.
    ENDLOOP.
    append it_donotcall_old.
    Reward all helpfull answers
    Regards
    Pavan

  • How to use Different Main Windows in Multiple pages to print internal table

    Hi experts,
    I have a problem regarding how to have multiple different main windows in  smartforms..the problem is that i want to print an internal table in the third page of the smartform and that table can have dynamic values ..sometime it may have more than 400 values also which can not be printed in one or two pages ...
    so to accomplish the same what i did was..
    i tried creating a new main window in the third page but it is throwing an error saying two main windows not allowed and i also tried by copying the first page's main window but it is just repeating the same content what was there in second page..
      i also tried by creating a secondary window in the third page and in that  window i tried giving my internal table and tried by giving the next page to itself but  that also is not allowed and it throws an error saying a page without a main window cannot point to itself as a next page....
    i also tried using a secondary window and in that window i was trying to display the internal table but it is only showing third page content and fourth page itself  was not created....although in my next page field value of the third page , i have given  the third page itself as a next page ....but this also is not working ,.....
    please suggest how to have different main windows(not copy of first main window) in smartforms in order to display the dynamic contents of an internal table

    HI ,
    Just check with your smart styles with assigned  paragraph  allignment   .
    Try to create character style  with your required  font ,size and  Allignment  .
    Hope u this will solve your issue  .
    Let me know if any concerns......
    Regards,
    Lokesh

  • Merging of multiple rows in an internal table as a single record

    Hi All,
    I have an internal table which has the following columns:
    text, date, time, user.
    it stores notes in the internal table.
    The problem is...when I save a note with multiple lines and spaces it saves each line of the note as a row in the internal table.
    Thus i get more no. of rows in the internal table compare to the no. of rows!
    I need to store each notes as single row in the internal table.
    Please advise how to approach this?
    Helpful answers will be rewarded.
    Thanks & Regards,
    Anshumita.

    You can create a deep internal table. You can declare one Column as an internal table and store the NOTES in that Internal table for each row.
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb366d358411d1829f0000e829fbfe/content.htm
    you can check the example in the link
    regards,
    abhishek

  • 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.

  • INSERT works for only last record of the Internal table ...??

    I am trying to insert data from an internal table JTAB to a Databse Table
    in CRM. The name of the databse table in CRM is CRMD_PARTNER
    For this i first declared an internal table JTAB with same structure as that of
    the databse table CRMD_PARTNER
    DATA: BEGIN OF JTAB OCCURS 0,
         INCLUDE STRUCTURE CRMD_PARTNER,
          END OF JTAB.
    Then I filled my JTAB with the required entries. For filling the JTAB i am
    getting data from couple of other tables and filling the internal table JTAB
         loop at ktab.
    here i am filling values in JTAB and then i say APPEND JTAB.
            endloop.
         Till here every thing works well and my internal table JTAB has all values that
    I need to insert to the CRMD_PARTNER table. Also my JTAB has vales for all primary key fields.
    Now I write a condition like below.
    if not jtab[] inital.
    MODIFY CRMD_PARTNER from TABLE JTAB.
    COMMIT WORK.
    endif.
    Here comes the problem...once this code is executed and once program totally executes...
    i always see that only last record in JTAB is being inserted to the databse table CRMD_PARTNER.
    When i check in the debugger ..i see that the loop is being executed only once
    and the SY-TABIX of JTAB is being always set to the length of JTAB and
    that is why only last  record is being inseretd to the table CRMD_PARTNER.
    Now what should i do ..to insert all records of JTAB to CRMD_PARTNER table?
    is there a way i can restet the SY-TABIX and make the modify statement work for all records of JTAB?
    Finally i hardcoded the values in JTAB then i dont have any problem and all records of JTAB are being
    inserted into the database table.
    only if i am dynamically fetching the values into JTAB(by Putting in loop..endloop statements and
    pushing values to JTAB and APPENDING JTAB ) i have a problem .
    in this case also my JTAB is being correctly filled with values ..but when i try to
    insert theses values to CRMD_PARTNER with MODIFY stmt ..only always last record is being inserted.
    i tried with INSERT instead of MODIFY and i am getting runtime error.
    kindly pease help.
    Regards,
    Jessica Sam

    yes a@s i am really struggling from last 3 days.
    I actually want to create a sales order in CRM and want to
    assign ship to party for each line item in a sales order in CRM
    for that i used the standard bapi BAPI_BUSPROCESSND_CREATEMULTI and i am able
    to create an order successfully, but i see that the ship toparty
    that i give at header is being copied to each line item.
    but this is not what is expected.
    So finally i tracked in which table the ship to party gets stored in each line item
    and then tried to insert the records directly into databse. and it worked
    but only if i am hardcoding..but not when i am dynamically fecthing the values into JTAB for insertion,
    Can yoy help ..if you have any idea why insert/modify is processing only last record?
    any help will be highly appreciated.
    Regards,
    Jessica Sam

  • Max no. of entries in an internal table?

    Max no. of entries in an internal table?

    Hi,
    You can specify the initial amount of main memory assigned to an internal table object when you define the data type using the following addition:
    INITIAL SIZE <n>
    This size does not belong to the data type of the internal table, and does not affect the type check. You can use the above addition to reserve memory space for <n> table lines when you declare the table object.
    When this initial area is full, the system makes twice as much extra space available up to a limit of 8KB. Further memory areas of 12KB each are then allocated.
    You can usually leave it to the system to work out the initial memory requirement. The first time you fill the table, little memory is used. The space occupied, depending on the line width, is 16 <= <n> <= 100.
    It only makes sense to specify a concrete value of <n> if you can specify a precise number of table entries when you create the table and need to allocate exactly that amount of memory
    (exception: Appending table lines to ranked lists). This can be particularly important for deep-structured internal tables where the inner table only has a few entries (less than 5, for example).
    To avoid excessive requests for memory, large values of <n> are treated as follows: The largest possible value of <n> is 8KB divided by the length of the line. If you specify a larger value of <n>, the system calculates a new value so that n times the line width is around 12KB.
    Regards,
    Bhaskar

Maybe you are looking for

  • Short dump in standard program

    Hi Friends, below description is short dump for standard program. Please see the below and help me how to correct the program. The current application triggered a termination with a short dump.             What happened? The current application progr

  • Is there a way to present two or three radio buttons that will open up new fields based on the radio button pressed?

    What we want to do is ask our new clients their preferred method of billing: Credit Card, Invoiced, ACH. If they choose Credit Card, credit card info fields will show up. If invoiced, Billing Address field shows up. If ACH, bank account and routing n

  • US localization. Select 2 Sales orders in one down payment invoice

    US Localization. I need to create a Sales Down payemnt invoice selecting 2 sales order but is not possibile to select more than one SO. In Other localization I see that it is possible. There is some set up or on the US localization it is not possible

  • Need help removing Snow Leopard and Installing Leopard

    Snow Leopard was a waste of time and money. Time I could have used for much more productive work. How can I remove snow leopard and reinstall leopard. I have the installation disc for Leopard. Can I simply install it over the top of snow leopard? Tha

  • 22 inch LaCie Blue II to new iMac - possible?

    I have a new 21" iMac and an old 22 inch LaCie Blue II computer Monitor that I'd like to add as a second monitor because I like the tonal quality for print - is it possible? Will I be able to span or is the old LaCie to slow? Thanks Chris