Application Development and Automation 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: 
Read only

Deleting Rows in Internal table

Former Member
0 Likes
8,089

Hi Experts,

I have an internal table of 100 records

And dymanically i would be getting some row numbers,

For Eg i get 10,20,30 etc

So i would like to delete all the rows apart from 10,20,30

These are dynamic and can be any

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,332

Hi..

I think it is useful for u.

 PARAMETERS p_carrid TYPE sflight-carrid. 

TYPES: BEGIN OF sflight_key, 
         mandt  TYPE sflight-mandt, 
         carrid TYPE sflight-carrid, 
         connid TYPE sflight-connid, 
         fldate TYPE sflight-fldate, 
      END OF sflight_key. 

DATA sflight_key_tab TYPE TABLE OF sflight_key. 

SELECT carrid connid fldate 
       FROM sflight 
       INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab 
       WHERE carrid = p_carrid AND 
             fldate = sy-datum AND 
             seatsocc = 0. 

DELETE sflight FROM TABLE sflight_key_tab. 

13 REPLIES 13
Read only

Former Member
0 Likes
3,332

Hi,

Method 1 Declare one more internal Table of same type.

Read this rows and append to the new internal table.

Method 2 Loop through Table and capture the sy-tabix value in variable.

use case or If stmt with in the loop such that u delete other Document but not 10,20.30 rows.

for Example

DATA : g_index like sy-index. " Which Stores Row value

data it_tab type table of mara,

it_tab type table of mara,

  • for Index 10

Read table it_tab index g_index into it_tab.

append it_tab to it_tab2

  • for Index 20

Read table it_tab index g_index into it_tab.

append it_tab to it_tab2

  • for Index 30

Read table it_tab index g_index into it_tab.

append it_tab to it_tab2

or

data: g_tabix like sy-tabix.

loop AT it_itab.

g_tabix = SY-TABIX.

if g_tabix 10 or g_tabix EQ 20 or g_tabix eq 30.

delete it_itab INDEX g_tabix .

endif.

endloop.

Thanks & regards,

ShreeMohan

Read only

Former Member
0 Likes
3,332

HI,

Using Index you can delete any rows.

DATA : P_IDX LIKE SY-TABIX.

LOOP AT ITAB.

P_IDX = SY-TABIX.

IF P_IDX <> 10 or P_IDX <> 20 P_IDX <> 30.

DELETE ITAB INDEX P_IDX.

ENDIF.

ENDLOOP.

Regds,

Anil

Read only

former_member585060
Active Contributor
0 Likes
3,332

Hi,

If the row field will be blank for other rows, then you can use DELETE statement

DELETE TABLE <itab> WITH TABLE KEY row = ' '.

Regards

Bala Krishna

Read only

Former Member
0 Likes
3,332

Hi

If you are getting the row numbers dynamically into an internal table.

describe table dy_tab lines v_llines.

loop at dy_tab.

delete itab index dy_tab-row_num----> dynamic row number

endloop.

regards

Ramchander Rao.K

Read only

former_member206439
Contributor
0 Likes
3,332

Hi

Pass that dynamic values to 3 variables and write delete statement for internal table where index in NE to that variable values

so that it will delete other than that index values

Read only

Former Member
0 Likes
3,332

hi,

there are so many ways u can solve ur problem...

1- you can loop at first table and then append second inernal table only for those record which you want to appned.

2- second way is you assign first internal table to second

itab2[] = itab1[].

and then delete itab2 comparing the values.

Thanks

Ashu

Read only

Former Member
0 Likes
3,332

Hi,

Following code may help you.

Describe another table of same type say Tab1.

then,

read ur_tab into wa_ur_tab index dyn_index.

append wa_ur_tab to Tab1.

free ur_tab.

append lines of Tab1 to ur_tab.

Read only

Former Member
0 Likes
3,332

Hi,

here is the link for u ...

just go through this i hope this will give u some help...

http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb37d9358411d1829f0000e829fbfe/content.htm

Thanks

Ashu

Read only

Former Member
0 Likes
3,332

HI,



itab1 contains 100 records ,
itab2 contains the row numbers (For Eg i get 10,20,30 etc ) , means 3 entries. 
itab_new , after calculations it contains the entries of row number 10,20,30 etc

types : begin of ty_p,
             row_num type i ,
           end of ty_p.
data : wa2 type ty_p,
          itab2 type standard table of ty_p.

loop at itab2 into wa2.

READ TABLE itab1 INDEX wa2-row_num  INTO wa1.
if sy-subrc is initial.
append wa1 to itab_new.
endif.
clear : wa1,wa2.
endloop.

Regards,

Aby

Read only

Former Member
0 Likes
3,332

hi,

its better if u declare a 2nd internal table same as 1st once n pass all the records to it and then delete those records from the 2nd internal table which u dnt want,in this way ur original records won't get deleted and u can use them whnevr it is required by u

rgds

shivraj

Read only

Former Member
0 Likes
3,332

Hi,

Try this.....

Data: v_indx like sy-tabix.

parameters: p_indx like sy-tabix.

declare itab1.

itab2.

loop at itab1.

v_indx = sy-tabix.

if v_indx eq p_indx.

append itab1 to itab2.

endif.

clear: v_indx

endloop.

loop at itab2.

write:/ itab2-field.

endloop.

Thanks

Read only

Former Member
0 Likes
3,332

Hello,

Try this way:

1. Define select option that will hold all the number you want to keep enable NO DISPLAY addition for it.

2. Load select option with all the required numbers

3. Use DELETE <ITAB> WHERE <FIELD> NOT IN <select option>.

You can also use RANGE instead of select options.

Check if this can help

Thanks,

Augustin.

Read only

Former Member
0 Likes
3,333

Hi..

I think it is useful for u.

 PARAMETERS p_carrid TYPE sflight-carrid. 

TYPES: BEGIN OF sflight_key, 
         mandt  TYPE sflight-mandt, 
         carrid TYPE sflight-carrid, 
         connid TYPE sflight-connid, 
         fldate TYPE sflight-fldate, 
      END OF sflight_key. 

DATA sflight_key_tab TYPE TABLE OF sflight_key. 

SELECT carrid connid fldate 
       FROM sflight 
       INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab 
       WHERE carrid = p_carrid AND 
             fldate = sy-datum AND 
             seatsocc = 0. 

DELETE sflight FROM TABLE sflight_key_tab.