Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete a record in the internal table?

Former Member
0 Kudos

Hi,

I have a <fs> which is an internal table that contains quite a numerous record. I need to delete some record where a column 'Year' that consist year 2007. How do i achieve that?

Regards,

Rayden

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Rayden,

try this

loop at <fs> assigning <wa>.
v_tabix = sy-tabix.
  DO.
    assign component 'YEAR' of structure <wa> to <year>.
    if <year> eq '2007'.
       DELETE <FS> index v_tabix.
       exit.
    endif.
   ENDDO.
endloop.
   

11 REPLIES 11

former_member386202
Active Contributor
0 Kudos

Hi,

loop on that internal table check if year is 2007 then delete internal table.

Ex. Loop at itab.

if year = 2007.

delete itab.

endif.

endloop.

Regards,

Prahsnat

Former Member
0 Kudos

loop at <fs> into wa.

if <fs>-year co '2007'.

delete itab from wa.

endif.

endloop.

Former Member
0 Kudos

hi rayden

delete itab where logical expression.

regards

kk

Former Member
0 Kudos

hi

LOOP AT THAT INTERNAL TABLE AND

DELETE THE RECORD WHERE THAT CONDITION

ENDLOOP.

USE CODE LIKE THIS TO DELATE RECORDS FROM ITAB

Former Member
0 Kudos

hI

LOOP AT THAT INTERNAL TABLE

DELETE TABLE ITAB WHERE THAT CONDITION

ENDLOOP.

USE THIS CODE

Former Member
0 Kudos

Hi,

DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.

DELETE itab INDEX idx.

DELETE itab WHERE logexp.

Use the above syntax.

Bye,

KC

Former Member
0 Kudos

Hi Rayden,

try this

loop at <fs> assigning <wa>.
v_tabix = sy-tabix.
  DO.
    assign component 'YEAR' of structure <wa> to <year>.
    if <year> eq '2007'.
       DELETE <FS> index v_tabix.
       exit.
    endif.
   ENDDO.
endloop.
   

Former Member
0 Kudos

ways to delete record from internal table......select required one....

U can use the statement as given below:

delete it_tab where fld = tab-fld

or

delete it_tab1 at i_index_p.

In case u want to delete all records from your table then use:

clear: itab, itab[]. Refresh itab.

DELETE - itab_lines

Syntax

... itab [FROM idx1] [TO idx2] [WHERE log_exp]... .

Extras:

1. ... FROM idx1

2. ... TO idx2

3. ... WHERE log_exp

Effect

To delete several lines at once, you have to specify at least one of the additions FROM, TO, or WHERE. You can only use the additions FROM and TO with standard tables and sorted tables.

If you specify several of the additions, the rows are deleted that result from the intersection of the individual additions.

Addition 1

... FROM idx1

Effect

If you specify FROM, all the table rows from the table index idx1 onwards are included. idx1 must be a data object with type i. If the value of idx1 is less than or equal to 0, a runtime error occurs. If the value is greater than the number of table rows, no rows are deleted.

Addition 2

... TO idx2

Effect

If you specify TO, only the table rows up to table index idx2 are included. idx2 must be a data object with type i. If the values of idx2 is less than or equal to 0, a runtime error occurs. If the value is greater than the number of table rows, it is set to the number of rows. If idx2 is less than idx1, no rows are deleted.

Addition 3

... WHERE log_exp

Effect

You can specify any logical expression log_exp after WHERE, for which the first operand of each individual comparison is a component of the internal table. This enables all logical expression with the exception of IS ASSIGNED, ISREQUESTED, and IS SUPPLIED. The dynamic specification of components using character-type data objects in parentheses is not supported here. All rows for which the logical expression is true are deleted.

Note

Whereas every row of the internal table is checked for the logical expression of the WHERE addition in standard tables and hashed tables, you can use linked AND queries to optimize the access to sorted tables by checking at least the starting component of the table key for equality with the logical expression.

Example

Deletes all rows of an internal table from row 4. The result is the same as in the example for APPEND ... SORTED BY.

PARAMETERS: p_carrid TYPE sflight-carrid,

p_connid TYPE sflight-connid.

DATA: BEGIN OF seats,

fldate TYPE sflight-fldate,

seatsocc TYPE sflight-seatsocc,

seatsmax TYPE sflight-seatsmax,

seatsfree TYPE sflight-seatsocc,

END OF seats.

DATA seats_tab LIKE STANDARD TABLE OF seats.

SELECT fldate seatsocc seatsmax

FROM sflight

INTO TABLE seats_tab

WHERE carrid = p_carrid AND

connid = p_connid.

LOOP AT seats_tab INTO seats.

seats-seatsfree = seats-seatsmax - seats-seatsocc.

MODIFY seats_tab INDEX sy-tabix FROM seats.

ENDLOOP.

ENDLOOP.

SORT seats_tab BY seatsfree DESCENDING.

DELETE seats_tab FROM 4.

Regards

vasu

Former Member
0 Kudos

As per my understanding you want to delete record from internal table where year is 2007. Check this code out.

If (some condition is true)

Delete itab where year EQ '2007'.

Endif.

Thanx & Rgds

hymavathi_oruganti
Active Contributor
0 Kudos

loop at itab assigning <fs>.

if (condition).

delete <Fs>.

endif.

endloop.

Former Member
0 Kudos

hi,

if you want to delet some of the entries in the table.

if <condition>

loop at itab .

delet itab where field = XXXX.

endloop.

regards,