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

dynamic internal table.

Former Member
0 Likes
1,045

i m having a dynamic internal table.

i want to delete a record where product = 'car'.

there are 10 records with value car.

how to delete as a whole.

in static table i will specify it[].

How to do tht in dynamic table.

Thanks in advance.

5 REPLIES 5
Read only

Former Member
0 Likes
635

hi.

Try this.

Loop at internal_table where product = 'car'.

delete internal_table.

endloop.

Warren

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
635

I don't think you can do this in one line with a dynamic internal table. But you can do it like this.



loop at <dyn_table> into <dyn_wa>.
    assign component  'PRODUCT'  of structure <dyn_wa> to <dyn_field>.
    if <dyn_field> = 'car'.
      delete table <dyn_table> from <dyn_wa>.
    endif.
 endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
635

Hi Maya,

Use,

Delete itab where product eq car.

Reward points if useful.

Read only

Pawan_Kesari
Active Contributor
0 Likes
635

suposse <FS_1> is you internal table...

step 1 create work area as line of you internal table


DATA: NEW_LINE type ref to data.
create data NEW_LINE like line of <FS_1>.
assign NEW_LINE->*  to <FS_2>.

then loop on your internal table


loop at <FS_1> assigning <FS_2>.
* Get the component in which value is stored..
   assign component 1 of structure <FS_2> to <FS_3>.
   IF <FS_3> = 'CAR' .
     DELETE <FS_1> INDEX sy-tabix
   ENDIF.
endloop.


Message was edited by:

Pawan Kesari

Read only

Former Member
0 Likes
635

Please see the code below :

It may help u..


DATA:  BEGIN OF itab OCCURS 0,
         fld1(10) TYPE c,
         fld2(10) TYPE c,
         fld3(10) TYPE c,
       END OF itab.

DATA:  l_index LIKE sy-tabix.

FIELD-SYMBOLS:  <fs> TYPE ANY,
                <fs_tab> TYPE table,
                <l_fs> TYPE ANY.

itab-fld1 = '1'.
itab-fld2 = '2'.
itab-fld3 = '3'.
APPEND itab.

itab-fld1 = '11'.
itab-fld2 = '22'.
itab-fld3 = '33'.
APPEND itab.

itab-fld1 = '111'.
itab-fld2 = '222'.
itab-fld3 = '333'.
APPEND itab.

LOOP AT itab.

  WRITE:/ itab-fld1, itab-fld2, itab-fld3.
ENDLOOP.

assign itab[] to <fs_tab>.

LOOP AT <fs_tab> ASSIGNING <fs>.
  l_index = sy-tabix.

  ASSIGN COMPONENT 1 OF STRUCTURE <fs> TO <l_fs>.      " Component 1 = FLD1
*** OR use   ASSIGN COMPONENT 'FLD1' OF STRUCTURE <fs> TO <l_fs>.     

  IF <l_fs> EQ '1'.
    DELETE <fs_tab> INDEX l_index.
  ENDIF.

ENDLOOP.

LOOP AT itab.

  WRITE:/ itab-fld1, itab-fld2, itab-fld3.
ENDLOOP.

Reward if useful..

Regards

Prax