Delete records in an internal table

I uploaded the data incorrectly into a ztable .how can i delete all entries in a that table now. I am afraid the table gets deleted.

Hi,
  you can delete the entries in the table by using DELETE command.
1. DELETE FROM dbtab WHERE cond.
DELETE FROM (dbtabname) WHERE cond.
2. DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ...
3. DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
4. DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Effect
Deletes lines from a database table(see Relational Databases ). You can specify thename of the database table either in the program itself with DELETEFROM dbtab ... or at runtime as the contents of the fielddbtabname with DELETE FROM (dbtabname) .... In bothcases, the database table must be known to the ABAP Dictionary.Only data from the current client is usually deleted. You can deletedata using a view only if the view refers to a singletable and was created in the ABAP Dictionary with themaintenance status "No restriction".
DELETE belongs to the Open SQLcommand set.
Notes
The DELETE statement does not performauthorization checks. You must programthese yourself.
The final (irrevocable) deletion of lines with the DELETEstatement is not performed until after a database commit (seeLogical Unit of Work (LUW)). Prior to this,you can reverse any database update with a database rollback (seeProgramming Transactions).
You cannot rely exclusively on the locking mechanism of the database system to synchronize several users trying toaccess the same dataset at the same time. You should therefore use theSAP locking mechanism.
<b>Variant 1</b>
DELETE FROM dbtab WHERE cond.
DELETE FROM (dbtabname) WHERE cond.
Addition:
... CLIENT SPECIFIED
Effect
Deletes lines in a database table that satisfy the WHERE clause cond. With thisvariant, specification of a WHERE condition is obligatory .
When the statement has been executed, the system field SY-DBCNTcontains the number of deleted lines.
The return code is set as follows:
SY-SUBRC = 0:
At least one line was deleted.
SY-SUBRC = 4:
No lines were deleted, since no line was selected.
Example
Delete all bookings for the Lufthansa flight 0400 on02.28.1995 (in the current client):
TABLES SBOOK.
DELETE FROM SBOOK WHERE CARRID = 'LH'       AND
                        CONNID = '0400'     AND
                        FLDATE = '19950228'.
Note
To delete all the lines in a table, you must specify aWHERE condition that is true for all lines. You can achieve thiswith
... WHERE f IN itab
If the internal table itab is empty, such a condition wouldselect all lines.
Addition
... CLIENT SPECIFIED
Effect
Switches off automatic client handling. This allows youto delete data across all clients in the case of client-specifictables. The client field is then treated like a normal table field, forwhich you can formulate suitable conditions in the WHERE clause.
You must specify the addition CLIENT SPECIFIED immediately afterthe name of the database table.
<b>Variant 2</b>
DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ...
Additions:
1. ... FROM wa
2. ... CLIENT SPECIFIED
See Short forms not allowed and* work areas not allowed.
Effect
These are SAP-specific short forms used to deleteone line of a database table. If the name of the database tableis specified in the program, the primary key ofthe line to be deleted is taken from the specified work area -dbtab or *dbtab. If the name of the database table is notdetermined until runtime ( DELETE (dbtabname) ...), the addition... FROM wa is obligatory .
When the statement has been executed, the system field SY-DBCNTcontains the number of deleted lines (0 or 1).
The return code is set as follows:
SY-SUBRC = 0:
The line was deleted.
SY-SUBRC = 4:
No lines could be deleted, since no line exists withthe primary key specified.
Example
Delete the booking with the booking number 3 for theLufthansa flight 0400 on 28.02.1995 (in the current client):
TABLES SBOOK.
SBOOK-CARRID = 'LH'.
SBOOK-CONNID = '0400'.
SBOOK-FLDATE = '19950228'.
SBOOK-BOOKID = '00000003'.
DELETE  SBOOK.
Addition 1
... FROM wa
Effect
Takes the primary key for the line to be deleted notfrom the table work area dbtab, but from the explicitlyspecified work area wa. Here, the key values from left to rightare taken from wa according to the structure of the primarykey in the table work area dbtab (see TABLES). The structure of wa is not taken intoaccount. Therefore, the work area wa must be at least as wide(see DATA) as the primary key in thetable work area dbtab and the alignment ofthe work area wa must correspond to the alignment of the primarykey in the table work area. Otherwise, you get a runtime error.
Note
If a work area is not explicitly specified, the values forthe line to be deleted are taken from the table work area dbtab,even if the statement appears in a subroutine (see FORM) or function module (see FUNCTION) where the table work area is stored in a formalparameter or a local variable of the same name.
Addition 2
... CLIENT SPECIFIED
Effect
As with variant 1.
<b>Variant 3</b>
DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
Addition:
... CLIENT SPECIFIED
Effect
Mass deletion: Deletes all database table lines forwhich the internal table itab contains values for theprimary key fields. The lines of the internaltable itab must satisfy the same condition as the work areawa in addition 1 to variant 2.
The system field SY-DBCNT contains the number of deleted lines,i.e. the number of lines of the internal table itab for whosekey values there were lines in the database table dbtab.
The return code is set as follows:
SY-SUBRC = 0:
All lines from itab could be used to deletelines from dbtab.
SY-SUBRC = 4:
For at least one line of the internal table in thedatabase table, there was no line with the same primary key. All foundlines are deleted.
Note
If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.
Addition
... CLIENT SPECIFIED
<b>
Effect</b>
As with variant 1.
<b>Variant 4</b>
DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
This variant is not allowed in an ABAP Objectscontext. See VERSION addition not allowed.
<b>Note</b>
This variant is now obsolete, since variants 1 - 3 allowyou to specify the database table name dynamically.
<b>Effect</b>
Deletes a line in a database table, the name of which istaken from the field vers at runtime. The database table must beknown to the ABAP Dictionary and its name must conform to thefollowing naming convention: It must begin with 'T' and canconsist of four additional characters. The field vers mustcontain the table name without a leading 'T'. Only lines in thecurrent client are deleted. The line to be deleted is taken from thestatically specified table work area dbtab or *dbtab.
The return code is set as follows: SY-SUBRC = 0:
The line was deleted.
SY-SUBRC = 4:
No lines could be deleted because no line existedwith the specified primary key.
Regards,
Vara

Similar Messages

  • How to delete records from dynamic internal table.

    Hi Experts,
    Need urgent help!!!
    Issue is with Dynamic internal tables.
    Below is code written by me :
    FORM select_query USING Lw_tabnam
                      TYPE  t682i-kotabnr.
      DATA :  lw_line  TYPE REF TO data,
              lw_line1 TYPE REF TO data.
        CREATE DATA Lw_line    TYPE (lw_TABNAM).
        ASSIGN      Lw_line->* TO   <WA_tbl>.
        CREATE DATA LW_LINE    TYPE STANDARD TABLE OF (Lw_tabnam)
                               WITH NON-UNIQUE DEFAULT KEY.
        ASSIGN      Lw_line->* TO <TBL>.
        SELECT * FROM  (Lw_tabnam)
                 INTO CORRESPONDING FIELDS OF TABLE <TBL>
                 WHERE (t_keys).
    Endform.
    code is working fine.
    here even the table name and where condition are dynamic,everything is fine upto this point.
    Now i have to delete some record from <TBL> based on some conditons.
         for ex : ( here lc_fieldname is KUNNR)
          loop at t_kunnr.
              lw_tabix = sy-tabix.
            Read table <tbl>
                    with key (lc_fieldname) = t_kunnr-kunnr ASSIGNING <wa_tbl>.
            If sy-subrc = 0.
            *Delete
            delete <tbl> from <wa_tbl>
    delete <tbl> index  lw_tabix.
            Endif.
         Endloop.
    The above delete statement doesn't work ,even we can't use index as it gives a syntax error " something related to "index is not allowed in standard table or hash table.
    Can you help me ab't how to delete records in Dynamic internal table?
    Other option that i am thinking of is to create a static table of type dynamic table.
    means, data itab type standard table of <tbl> .I know the syntax is wrong ,however is there any way to do this?
    Thanks in advance ,
    If you have any suggestion ab't this then do let me know.
    bye,
    Gaurav.

    Hi
    I wrote this code and it works fine:
    DATA LW_TABNAM(10) VALUE 'LFA1'.
    DATA : LW_LINES TYPE REF TO DATA,
           LW_LINE  TYPE REF TO DATA.
    FIELD-SYMBOLS: <TABLE> TYPE TABLE,
                   <WA>    TYPE ANY.
    CREATE DATA LW_LINES TYPE TABLE OF (LW_TABNAM)
    WITH NON-UNIQUE DEFAULT KEY.
    ASSIGN LW_LINES->* TO <TABLE>.
    CREATE DATA LW_LINE TYPE (LW_TABNAM).
    ASSIGN LW_LINE->* TO <WA>.
    DO 10 TIMES.
      APPEND INITIAL LINE TO <TABLE>.
    ENDDO.
    SY-TABIX = 4.
    DELETE <TABLE> INDEX SY-TABIX.
    WRITE SY-SUBRC.
    I hope it help you
    Max

  • Delete records in a internal table

    I Have an ALV in which I have selected several lines to delete (icon "-").
    The method get_selected_rows returns the index of the selected lines.
    In a loop I try to delete the lines of the internal table by the index. But I have a problem because when I delete a line, the index number is updated, therefore the second record that I try to delete doesn´t work because the index has changed.
    does there exist the possibility that the index is not updated?
    Thanks

    hi
    try to delete like this
    loop at itab
    delete itab                    
    endloop
    it deletes all the records in the internal table
    outside of the loop
    delete itab index 2   -
    > it deletes the record of index 2
    put it into the while or do while
    i =1.
    while i < 5
    i = i+ 1.
    delete itab index i.
    endwhile.
    it deletes 5 records in the internal table

  • Deleting records in an internal table

    Hey everyone, I hope this is a fairly easy question,
    I have an internal table, included is two fields from date and to date.
    I have been given a date range to delete records based on this range.
    For this example I will explain it like this.
    FROM                    TO
        1                          2
        2                          3
        3                          4
        4                          5
        5                          6
        6                          7
        7                          8
    If for example I have been given a range of delete records between 2 and 5.
    I want to only delete these records.
        2                          3
        3                          4
        4                          5
    but i don't want to delete the record:   5       6
    How hard is the to resolve????
    Thanks for your help,
    Stephen

    hi,
    1) Declare a select-options with no display.
    2) Append the values to be deleted to this select-options.
    3) Loop the table i.e
    loop at itab.
    if itab-from is in s_limit and itab-to is in s_limit.
    delete itab   " Deletes that record.
    endif.
    endloop.
    Thanks
    Sharath

  • Deleting a record in an internal table

    hi,
      loop at itab,
       ..... if a particular record alone matches a condition then that particular record alone has to be deleted.
    endloop.
    only the particular record which matches the  condition inside the loop should be deleted. remaining records should be there in that internal table itself.
    can anyone explain me how to do this.
    Regards,
    Phyrose.

    hi,
    u can specify the condition in th loop statement itself..
    loop at itab where condition.
    delete itab.  " itab - internal table with header line
    endloop.
    else if u want to specify it inside the loop..
    loop at itab.
    if condition.
    delete itab.
    endif.
    endloop.
    hope it answers ur requirement...
    Regards,
    Viji

  • Count the Records in  an internal table without a loop.

    How do i count the number of records in an internal table without using the loop  statement.
    The Describe statement give the total no. of records in the internal table.But i want the count of the key fields in the internal table
    For eg
    Row Field
    1       A
    2       A
    3       A
    4       B
    5       B
    6       C
    Count of A = 3
    Count of B = 2
    Count of C = 1

    Dilip,
      I think isn't posible. Only 3 ideas:
    1ª, make other table "table2", similar to your actual table.
         table2[] = yourtable[].
         delete table2 where key <> 'A'.
         describe table table2 lines contA.
        But depending the amount of data, you may have problems in performance or memory consumption...
    2ª, make other table, only with the keys fields and a count field,
        data begin table2
           key_field1,
           cont type i.
        end data.
       when you append lines to yourdata, make a collect to this table:
        table2-keys = yourtable-keys.
        table2-cont = 1.
       collect table2.
       But only works if you can modify the program where data is appended, and you may be carefull when data is deleted :-(...
    3ª if your data if filled in a select, you may fill the table2 of point 2ª, making a similar select but:
       select keyfields count( * ) into table table2
      from ...
      where (the same you have to fill your original table...)
       group by keys.
    But you have the same problem is data is deleted later...
    I hope that any of the three is useful for you...
    Edited by: Diego Alvarez on Jan 5, 2010 5:09 PM

  • How to delete entries in an internal table except for one entry

    Hi all,
    I have 4 records in my internal table and I need to delete all the  records in the internal table except the last one.How do i do this?Any sample code?
    Thanks.
    Moderator message - Please do not ask or answer basic questions - thread locked
    Edited by: Rob Burbank on Dec 16, 2009 3:23 PM

    Hi,
      use following logic:
    DATA: lt_itab type standard table.
    DATA: l_lines type i.
    DESCRIBE TABLE lt_itab lines l_lines.
    l_lines = l_lines - 1.
    delete lt_itab from 1 to l_lines.
    Regards,
      Karol

  • @Inserting Records in an Internal Table

    Hi,
    How can I Insert records in an internal table..such that i can insert the records somewhere in the middle based on the entry in a field?

    INSERT wa INTO TABLE 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.

  • To count number of records in an internal table for a condition

    Hello All,
            I want to count number of records in an internal table for a condition.
    For e.g. -- I have one internal table IT which having fields F1, F2, F3, F4, F5.
                     Now, I want number of records in itnternal table IT where F1 = 'ABC'.
    Is it possible to do..?? If yes, then how.??
    Thanks in advance...!!
    Regards,
    Poonam.

    Hi,
    If you mean an internal table, there are a few ways to do this.
    1 One would be to loop over the table with a WHERE clause and increment a counter.
    data: lv_counter type i.
    clear lv_counter.
    loop at itab where fld1 = 'ABC'.
    lv_counter = lv_counter + 1.
    endloop.
    lv_counter now has the number of rows per the condiction.
    2  Well, you may want to try this as well, and compare to the LOOP way. Not sure what kind of overhead you may get doing this way. Here ITAB is our main internal table, and ITAB_TMP is a copy of it. Again I think there may be some overhead in doing the copy. Next, delete out all records which are the reverse of your condition. Then whatever is left is the rows that you want to count. Then simply do a LINES operator on the internal table, passing the number of lines to LV_COUNT.
    data: itab type table of ttab.
    data: itab_tmp type table of ttab.
    itab_tmp[] = itab[].
    delete table itab_tmp where fld1  'ABC'.
    lv_count = lines( itab_tmp ).
    Thanks & Regards,
    ShreeMohan

  • Records in an internal table

    Hi,
    How to check if all the records in an internal table are identical.
    could you help soon

    Hi,
    use the code,
    data : begin of itab occurs 0,
              matnr like mara-matnr,
              maktx like makt-maktx.
              end of itab.
    parameters : p_matnr like mara-matnr.
    start-of-selection.
    select * from makt into corresponding fields of table itab
                                where  matnr = p_matnr.
    delete adjacent duplicates from itab comparing matnr.
    if sy-subrc eq 0.
    write : /1 'Entries are identical.' .
    endif.
    Regards,
    Sankar.

  • Filtering records from one internal table based on ranges in another itab

    Hi guys,
    I have 1 internal table with set of GL accounts. I have 2nd internal table where lower interval  and upper interval of GL accounts
    How to filter out records from 1 internal table by comparing with the GL account ranges present in 2nd internal table.
    Please reply.

    Hi
    Create a RANGE for GL Accounts.
    LOOP the second Internal Table.
    And assign HIGH & LOW to ranges from second ITAB.
    And Delete the accounts which are not there in the range.
    Use the below code as reference.
    DATA: itab TYPE TABLE OF mara WITH HEADER LINE.
    DATA: r_matnr TYPE RANGE OF matnr WITH HEADER LINE.
      SELECT * FROM mara INTO TABLE itab UP TO 10 ROWS.
      r_matnr-sign = 'I'.
      r_matnr-option = 'BT'.
      r_matnr-low  = '000000000016900036'.
      r_matnr-high = '000000000016900040'.
      APPEND r_matnr.
      DELETE itab WHERE matnr NOT IN r_matnr.

  • How to Delete a Column in Internal Table

    Hi All,
    Does any one know ,How to Delete a Column in Internal Table?

    Hi,
       For deleting the column in the internal table, you have to eliminate the field which you want to delete.
    loop at itab into wa.
      move corresponding wa to wa1.
    append wa1 to itab1.
    clear wa1.
    clear wa.
    endloop.
    wa1 is the workarea without the field which you want to delete.
    itab1 is the internal table which consists of the deleted column.

  • Maximum record length in internal table?

    Is there a maximum record length in an internal table?  Please note:  My question is NOT related to table space.  I'm referring only to the length of an individual record (A.K.A. row length).
    I am using a work area to insert data into an internal table.  Both the work area and internal table are defined by the same structure.
    The structure has a total length of 672 bytes.  For the sake of this discussion I'll point out that at the end of the structure, bytes 669, 670, 671, and 672 are four separate fields of 1 character each.
    When viewing the work area record in the debugger I'm seeing all the fields and all the values.  When viewing the internal table in the debugger after a record is inserted, the internal table ends with the field defined at Byte 670.  The internal table does not include the two fields defined at Bytes 671 and 672.
    Am I to assume from the above explanation that the length of a record ( A.K.A. row) in an internal table cannot exceed 670 bytes?
    Thank you.

    Manish,
    False alarm!  While, technically, you didn't answer my question, your request for code ended up helping me answer my own question.
    To provide you with some code I wrote a simple test program using the record layout referred to above, with a DO loop to put some records into the internal table, followed by a LOOP AT, with accompanying WRITE statements to display the contents of the internal table and demonstrate that the last two fields weren't being stored.
    However, when I ran the test program, the last two fields were being displayed.
    It was at that point, when stepping through the debugger that I noticed the scroll arrows above the last column of my internal table that allowed me to scroll to the right and see my final two fields.
    Apparently, because of the large number of fields in my internal table I had reached the default display length of the debugger.  While I was obviously aware of the scroll bar found at the bottom of the display, I had never worked with an internal table of that width in the past and hadn't even noticed the scroll arrows above the last column before.
    Thanks for taking the time to respond helping me get to the solution.

  • Spilt the number of records in a internal table

    Hi all,
            I have a requirement where i must spilt the number of records in my internal table itab .Say if i have 2000 records , i must spilt it taking the first 990 records and doing some posting using Bapi and again take the next 990 records and do the posting .Can some one help me out.
    Good answers will be rewarded with points.

    Hi,
    You can use these instructions using two internal tables, but please be aware to not forget any line.
    REFRESH my_table2.
    APPEND LINES OF my_table FROM 1 TO 990 TO my_table2.
    CALL FUNCTION 'BAPI'....
                 (with my_table2)
    REFRESH my_table2.
    APPEND LINES OF my_table FROM 991 TO my_table2.
    CALL FUNCTION 'BAPI'....
                 (with my_table2)
    Regards,
    Mathieu

  • Count number of records in a internal table

    hi
    i want to count number of records in internal table
    pls let me know how to count the number of records in a internal table.
    regards
    Arora

    hi
    one way is
    data field type i.
    Decribe table itab lines field.
    write: / field.
    displays the no of records in tha internal table
    or if u want to write logic.
    data:
      w_count type i.
    loop at itab.
    w_count = w_count + 1.
    endloop.
    write: / w_count.
    displays the no of records.
    reward points if useful.

Maybe you are looking for

  • How do you know what Mac Mini version you are getting?

    I heard that as of September 2005, Apple had completly updated there Mac Mini's.. I heard that they put in a 64mb 9200 Graphic Card, and all had Bluetooth and Airport.. But, how would I know that what I am getting is the updated version? Compusa's Ma

  • Problem with printing logo in smartform.

    Hi guys, We have a logo in a window, its working fine in print preview, however while printing the page data ,other than logo is comming fine on printout , but logo is not comming fine. Logo is comming like one black vertical strip on left side of pa

  • Huge data upload to custom table

    I created a custom table and the requirement is to load huge data to this table around 20million records. I have input file with 1million records. After loading few files, I got error max extents 300 is reached. We talked to basis and they increased

  • HT1947 Apple remote app under ios7 won't rotate

    After the ios7 update my remote app doesn't work in landscape on my ipad 2. Anyone else experienced this?

  • Sync calendar from my macbook pro to my google calendar

    I am trying to sync my apple calendar on my macbook pro to my google calendar. It syncs from google calendar to my apple calendar but not the other way around. So if I add an event on my Macbook or my iPhone using the apple calendar it is not syncing