Deleting block from internal table with AT / ENDAT

Hi.
I have the following code:
sort itab by pred_doc.
loop at itab into wa_cust.
At end of pred_doc.
sum.
write :/ wa_cust-pred_doc, wa_cust-amount.
if wa_cust-amount = 0.
Delete entire block of this pred_doc
endif.
endat.
endloop.
Within that "IF" statement, I want to delete the entire block (all entries with that pred_doc).  How do I do this?  I'm not sure of the syntax.  In other words, I just need to do subtotals of the internal table by pred_doc on amount.  If the subtotal equals zero, the records for that pred_doc need to be removed from the internal table. 
Thanks,
Clay

Hi,
I agree with Rob. Use two internal tables for this purpose.
data: itab1 like itab. New internal table which will hold the required entries
sort itab by pred_doc.
loop at itab into wa_cust.
At end of pred_doc.
sum.
write :/ wa_cust-pred_doc, wa_cust-amount.
if wa_cust-amount ne 0. " If the workarea has the subtotal entry with amount not equal to zero, then transfer it to a new internal table
append wa_cust to itab1
endif.
endat.
endloop.
Now itab1 will contain your required entries. But please note that this will be the 'summed up' entries and not the the individual entries before summing up.
Hope this helps!
Cheers,
Mahesh

Similar Messages

  • Delete Duplicates from internal table with object references

    Hi
    How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
    I have created a method, with the following code:
      LOOP AT me->business_document_lines INTO l_add_line.
        CREATE OBJECT ot_line_owner
          EXPORTING
            i_user      = l_add_line->add_line_data-line_owner
            i_busdoc = me->business_document_id.
          APPEND ot_line_owner TO e_line_owners.
      ENDLOOP.
    e_line_owners are defined as a table containing only object references.
    One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
    How can do this?
    Regards,
    Morten Nielsen

    Hello Morten
    Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
      SORT e_line_owners BY table_line->user.
      DELETE ADJACENT DUPLICATES FROM e_line_owners
        COMPARING table_line->user.
    However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
    Alternative solution:
      DATA:
         ld_idx    TYPE sy-tabix.
      LOOP AT e_line_owners INTO ls_line.
        ld_idx = syst-tabix + 1.
        LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
                       WHERE ( table_line->user = ls_line->user ).
          DELETE e_line_owners INDEX syst-tabix.
        ENDLOOP.
      ENDLOOP.
    Regards
      Uwe

  • How to choose in Delete Duplicates from internal table?

    Now I need to delete Duplicates from internal table,
    So at first I sort
    than I delete duplicate
    Sort itab1 BY Company_Code  Asset_No Capital_Date.
          DELETE ADJACENT DUPLICATES FROM itab1 COMPARING Company_Code  Asset_No  Capital_Date
    Company_Code
    Asset_No
    Capital_Date
    Remark
    BC35
    1515593
    20021225
    Helen
    BC35
    1515593
    20021225
    Common Asset
    BC35
    1515594
    20030109
    Judy
    BC35
    1515594
    20030109
    Common Asset
    But here comes my problem~If I want to delete the Common Asset in Remark Column,how I let it choose the right one to do it?

    Hi Jack
    Try the below coding..
    Report zsamp.
    types: begin of t_tab,
            comp_code(4) type c,
            ***_no(7) type n,
            cap_date type d,
            remark type string,
            end of t_tab.
    data: i_tab type TABLE OF t_tab,
           w_tab type t_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515593'.
    w_tab-cap_date = '20021225'.
    w_tab-remark = 'Helen'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515593'.
    w_tab-cap_date = '20021225'.
    w_tab-remark = 'Common Asset'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515594'.
    w_tab-cap_date = '20030109'.
    w_tab-remark = 'Judy'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515594'.
    w_tab-cap_date = '20030109'.
    w_tab-remark = 'Common Asset'.
    append w_tab to i_tab.
    sort i_tab by remark.
    delete ADJACENT DUPLICATES FROM i_tab COMPARING remark.

  • Deleting entry from internal table

    Hi Experts,
    i have the following internal table:
    data :    it_result1            TYPE   crmt_object_guid_tab
    and work area
    data : wa_result1 type crmt_object_guid.
    i have to delete a guid from internal table based on some condition.
    loop at it_resul1 into wa_result1
    if lv_priority eq priority.
    delete     this entry from internal table.
    endif.
    endloop..
    i tried using  delete table it_result with table key CRMT_OBJECT_GUID = wa_result. but this is giving syntax error.
    what should be done to delete the entry?
    Thanks and regards
    Shilpi

    Hi
    Check Syntax for DELETE operator on pressing F1
    1. DELETE itab.
    2. DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
    3. DELETE TABLE itab [FROM wa].
    4. DELETE itab INDEX idx.
    5. DELETE itab FROM idx1 TO idx2.
    6. DELETE itab WHERE logexp.
    7. DELETE ADJACENT DUPLICATES FROM itab.
    delete table it_result with table key CRMT_OBJECT_GUID = wa_result
    this is wrong
    delete  it_result where CRMT_OBJECT_GUID = wa_result
    Edited by: Lavanya K on Apr 22, 2009 10:20 AM

  • Delete records from internal table

    hi all,
    i want to delete records from intenal table which are starting with a particular starting number .
    eg internal table
    10000
    20000
    90000
    91000
    92000
    88880
    i want delete the records starting with 9 i.e. 90000 91000 92000.
    Thanks in Adv
            RAJ

    You can test this piece of code.
    DATA:
    i_tab TYPE STANDARD TABLE OF mara,
    wa_tab TYPE mara.
    wa_tab-matnr = '1000'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1002'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1003'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '2001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '3001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '4010'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM

  • Get records number from internal table with condition.

    Internal table itab got more than 1000 records,now i need to get the number of records with condition that itab-field1 = 'XXXX'.
    actully, i got an inefficient logic to count the number in a loop statement. is there better way to implement it?

    hello,
    Every time assigning data into temp table and delete may that may not be much efficient. You can check in loop logic how much time is taken. You can check the below code. here I am trying to check the numbers of plant for for one material.
    In this logic material is the first field. So if there is option to make the required field in to the 1 st position then it will be nice.
    TYPES: BEGIN OF x_count,
            matnr TYPE matnr,
            count TYPE i,
           BEGIN OF x_count.
    DATA: i_marc  TYPE STANDARD TABLE OF marc,
          i_count TYPE STANDARD TABLE OF x_count,
          wa_count TYPE x_count.
    FIELD-SYMBOLS: <wa_marc> TYPE marc.
    SELECT * UP TO 1000 ROWS
      FROM marc
      INTO TABLE i_marc.
    IF sy-subrc = 0.
      SORT i_marc BY matnr.
      LOOP AT i_marc ASSIGNING <wa_marc>.
        wa_count-count = wa_count-count + 1.
        AT END OF matnr.
          wa_count-matnr = <wa_marc>-matnr.
          APPEND wa_count TO i_count.
        ENDAT.
      ENDLOOP.
    ENDIF.
    Thanks
    Subhanakr

  • Problem in deleting entries from internal table

    i am selecting
               vrgar
                perio
                paobjnr
                belnr
                gjahr
                perde
                budat
                kndnr
                artnr
                frwae
                kursf
                rec_waers
                kaufn
                kdpos
                bukrs
                kokrs
                werks
                gsber
                vkorg
                vtweg
                spart
                rbeln
                rposn
                prctr
                pprctr
                kunnr
                land1
                regio
                kunwe
                kvgr1
                wwpmg
                zterm
                wwcst
                wwrst
                mvgr3
                wwseg
                wwcls
                wwesa
                prdha
                wwbun
                wwexd
                wwph1
                wwph2
                wwph3
                wwph4
                prat1
                prat2
                vrprs
                vv510
                vv508
                vv509
                vvqt2
                vv515
        INTO TABLE ct_ce11000 FROM ce11000
        WHERE paledger EQ gv_ledbo AND
              vrgar    EQ lc_vrgar AND
              belnr    GT uv_belnr AND
              gjahr    EQ pa_gjahr AND
              perde    EQ pa_perd AND
              bukrs    EQ pa_bukrs.
    now i awant to delete all those entries from my internal table ct_ce11000 where my plant (WEKRS) and company code (BUKRS)
    i am writting
    loop at ct_ce11000 into wa_ce11000.
    if wa_ce11000-werks ne wa_ce11000-bukrs.
    now how can i delete all the entries from nmy internal table (ct_ce11000)  when plant and company code is not same
    pls help me  with logic.
    thank you for helping me

    Hello Guys,
    It is not advisable to delete the entries from the internal table you are looping upon. See this thread: [Sy-tabix in loop : Doubt|Sy-tabix in loop : Doubt]
    And to answer the OP's question select data into some local internal table & based on the condition populate your final table. Creating a local table of the same type as the final table will not create too much performance overhead
    Cheers,
    Suhas

  • Delete duplicate from internal table

    HI Abapers,
    I have a query on how to remove the duplicates from an internal table
    My internal table data is as follows :
    Cno    Catg1  Catg2
    01       0         1000
    01      2000         0
    I want to get only one record as
    01   2000  1000
    How to  get the result.
    I tried sorted by cno and used delete duplicates but it was not helpful.
    Is there any other alternative to get this done
    Please help me.
    Regards,
    Priya

    check it out with delete adjacent duplicate records
    Deleting Adjacent Duplicate Entries
    To delete adjacent duplicate entries use the following statement:
    DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
                                      [COMPARING <f1> <f 2> ...
                                                 |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> <f 2> ... the contents of the specified fields <f 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > 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.

  • Delete records from internal table using another internal table

    HI,
    I have two internal tables itab1 and itab2 which have same records initially.Later some records of itab2 are deleted .Then i want to delete those records from itab1 also ie,those records not found in itab2 .Is there any method other than looping.
    So that itab1 again becomes equal to itab2.
    Thanks in advance.
    Sowmya.

    Soumya,
    Itab1 , Itab2 .
    Before deleting the records from itab2  move those records to one more internal table itab3.
    Now you have deleted records  of itab2  in itab3.
    SORT ITAB3,ITAB1 by your main key field.
    LOOP AT itab3.
      READ TABLE ITAB1 WITH KEY key field = itab3-
      keyfield.
    IF sy-subrc EQ 0.
    DELETE itab1 where keyfield eq itab3-keyfield.
    ENDIF.
    ENDLOOP.

  • Deleting entries from internal table

    hi
    i have an internal table. column one value can vary from A to Z. i mean some records can have A, some entries can have 'C like that. now i want to delete all the entries where column one value is not equal to A or C. can i do this in one single statement?
    i tried delete with where condition but it did not work. if i use an and condition in where clause it won't obviously work. if i use or condition it will only give entries with either A or C, but not both.
    thanks

    Moderator message - Basic question - thread locked
    Rob

  • DELETED rows from internal table

    Hi Experts,
    If I delete row/s from an internal table
    using the command DELETE ADJACENT DUPLICATES,
    is there a way to get these deleted rows.
    Thanks in advance.
    Rose

    Hi roselie,
    1. ofcourse not.
    2.hence, before that,
      u can declare another internal table,
      similar to original,
      and use like this.
    3. ITAB1[]   = ORIGINALITAB[].
    regards,
    amit m.

  • Delete entries from internal table

    Hello friends,
                        I have a screen on which im displaying a table, now i have also provided an delete button which deletes the selected record.
                      the record which i have written is
    GET CURSOR FIELD FLD LINE IND.
      READ TABLE ITAB2 INDEX IND.
      DELETE ZCTA_STONE_DET FROM ITAb2.
      IF IND IS NOT INITIAL.
        DELETE ITAB2 INDEX IND.
      ENDIF.
    but there is problem with this code,when ever the user scrolls the wrong data gets deleted.
    so wat is the proper code to delete the record from the display table

    Hi,
    This maybe possible B'coz the Line Number is taken considering the Headers so you should subtract 1 or 2 depending on the no. of lines in Header and then delete the record.
    so write the Code as
    GET CURSOR FIELD FLD LINE IND.
    READ TABLE ITAB2 INDEX IND.
    DELETE ZCTA_STONE_DET FROM ITAb2.
    SUBTRACT 1 FROM IND.
    IF IND IS NOT INITIAL.
    DELETE ITAB2 INDEX IND.
    ENDIF.
    Regards,
    Sunil

  • Delete row from internal table using field symbol.

    Hi friends,
      I created dynamic internal table using field symbol. I want to delete some data using where clause.
    for example. i want to use like,
        DELETE <FS> WHERE KUNNR = WA_KNA1-KUNNR.
    Like the above statment it won't work. How i can use delete with where clause in field symbols.
    Hope any one can help me.
    Thanks and regards
    Srikanth. S

    hi Srikanth,
    I think you have to LOOP through the whole internal table and check each line and decide to delete or not:
    LOOP at <itab> INTO <wa>.
    ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <wa> TO <field>.
    CHECK <field> IS ASSIGNED.
    IF <field> EQ WA_KNA1-KUNNR.
    DELETE ...
    ENDIF.
    UNASSIGN <field>.
    ENDLOOP.
    hope this helps
    ec

  • Deleting records from internal table.

    Hello Friends,
    I have done F1 on delete and also went through the forum . I want to do a delete effectively as it involves huge amount of data ..
    Lets cosider I have two internal tables ITAB 1 and ITAB 2 .
    ITAB 1 has 10000 records  having two key fields
    ITAB2 has 1000 records having the same two key fields in it .
    THe other fields are different .
    Now I want to perform an operation where for corresponding  1000 records in ITAB2 I must delete the records in ITAB1 and result in ITAB 1 must be 10000 - 1000 = 9000 records.
    Which could be the most effecient way to do this.?
    Comradely,
    K.Sibi

    Are you sure that the keys are all unique? That is non trivial with internal tables.
    If yes, then you should define itab1 as a hashed table or copy into a hashed table.
    LOOP AT itab2
        READ TABLE itab1 WITH TABLE KEY ...
        IF ( sy-subrc = 0 ).
          DELETE itab1 WITH TABLE KEY ...
        ENDIF
    ENDLOOP.
    You can also use sorted tables and delete with index, will be somewhat slower. Or standard table with REAB BINARY SEARCH and DELETE with index.
    If the uniqueness is unclear, then you must change the order and LOOP itab1first and comletely, because the same key can appear several times.
    A READ without BINARY SEARCH will kill you, i.e. the above recommendation is incorrect.
    Siegfried

  • Delete lines from internal table

    Hello experts!
    I have two internal tables.
    select options sa_tknr and gt_versand_plan.
    sa_tknr-low contents transportation-Nr.
    gt_versand_plan has transportation-Nr too (gt_versand_plan-tknum).
    How can I delete all transportation-Nr from
    gt_versand_plan which dont' appear in sa_tknr-tknum.
    THX
    sas

    Hi
    check this statement.
    <b>delete gt_versand_plan where not tknum in sa_tknr.</b>
    <b>Reward points for useful Answers</b>
    Regards
    Anji

Maybe you are looking for

  • PI 7.1, ECC 6.0 EP3, CE 7.1, and ES Bundles.  SR question

    Hi everyone, We have a ECC 6.0 Enhancement Pack 3, PI 7.1 (using the ESR and SR here),  and CE 7.1 sandbox enviroment.  I'm having difficulty getting the Enterprise Services available as part of Enhancement Pack 1, 2, and 3 to show up in the Service

  • AD connection and repository population

    Ok, so I am a newbie to the SAP IDM space, but am well versed in LDAP and other IDM solutions. I need some help for the scenario we are working on Password change replication from AD to SAP systems. AD has the users and will be the source for passwor

  • Create an EXT number range's delivery by fm/bapi

    Hi,    I have customized an new delivery type with EXT number range.and I want to write a program to create the delivery reference from.sales order.Is there any FM or bapi can help me create it for the delivery number can be assign by my program.Or i

  • FAQ's area.

    It has been suggested and discussed before that the community may benifit by having a series of acticles to address key aspects of using NI products that show up frequently in discussion board threads.  Knowledge Base articles and Community Nuggets o

  • Custom dimension change

    Hi guys, I have a dimension of 100 000 elements. The client asks to have a possibility to change properties of some elements. Without accessing Admin Console and waiting for hours until the end of the reprocess. So, I developed a package that updates