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 records from dynamic internal table.

Former Member
0 Kudos
4,606

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
393

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

5 REPLIES 5

Former Member
0 Kudos
393

I am using SAP ecc 5.

ferry_lianto
Active Contributor
0 Kudos
393

Hi Gaurav,

Perhaps you can try like this.


loop at t_kunnr.
  lw_tabix = sy-tabix.

  ...

  delete table <tbl> with table key (lc_fieldname) =  t_kunnr-kunnr.  

  ...
Endloop.

Regards,

Ferry Lianto

0 Kudos
393

hi ferry,

Thanks for helping me.

The code that you suggest is giving dump saying some of the key field are missing.

My requirement is to delete records from <tbl> where

kunnr <> t_kunnr-kunnr.

So wat we can do is ,

loop at t_kunnr.

lw_tabix = sy-tabix.

loop at <tbl> assigning <wa_tbl>

Assign component 7 of structure <wa_tbl> to <field>.

If <field1> <> t_kunnr-kunnr.

Here we have to write the delete statement,

If you can help me in writing the delete code

then it will be great help for me.

Endif.

Endloop.

endloop.

Thanks again,

Gaurav.

Former Member
0 Kudos
394

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

0 Kudos
393

Thanks Max ,It solved the issue .I think the issue was with table creation.

Thanks again Genius.