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

Delete statement

Former Member
0 Likes
711

Hello friends,

I have to delete a record from an Internal table based on comparing two fields from the same line in the Internal table.

I am using this code.

LOOP AT itab.

IF itab-01_kschl = 'ZBX1'.

IF itab-02_kschl <> 'ZAXS' OR

itab-02_kschl <> 'ZRON' OR

itab-02_kschl <> 'ZTIS' .

DELETE itab index sy-tabix.

ENDIF

ENDIF.

ENDLOOP.

I am kind of worried to delete using the sy-tablx as the index. Is there a bettew way to handel this issue.

Thanks.

Shejal.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
666

You don't need the INDEX in the DELETE statement, and your IF statement should have AND, not OR.

LOOP AT itab.
IF itab-01_kschl = 'ZBX1'.
   IF itab-02_kschl <> 'ZAXS' and
       itab-02_kschl <> 'ZRON' and
       itab-02_kschl <> 'ZTIS' .
     DELETE itab.
   ENDIF
ENDIF.
ENDLOOP.

Regards,

Rich Heilman

6 REPLIES 6
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
667

You don't need the INDEX in the DELETE statement, and your IF statement should have AND, not OR.

LOOP AT itab.
IF itab-01_kschl = 'ZBX1'.
   IF itab-02_kschl <> 'ZAXS' and
       itab-02_kschl <> 'ZRON' and
       itab-02_kschl <> 'ZTIS' .
     DELETE itab.
   ENDIF
ENDIF.
ENDLOOP.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
666

Hi,

Try this..

DELETE ITAB WHERE 01_KSCHL = 'ZBX1' AND

( 02_KSCHL <> 'ZAXS' AND

02_KSCHL <> ZRON' AND

02_KSCHL <> 'ZTIS' ).

Thanks,

Naren

Read only

former_member194669
Active Contributor
0 Likes
666

Hi,

Move the condition values to a range and use syntax

delete itab where kschl in r_range.

aRs

Read only

0 Likes
666

Thanks Rich, Naren and Mony.

Thanks again for your advice and help.

Shejal.

Read only

Former Member
0 Likes
666

I'm not sure your logic is correct. Do you want to:

delete itab 
  where 01_kschl =  'ZBX1'
    and 02_kschl <> 'ZAXS'
    and 02_kschl <> 'ZRON'
    and 02_kschl <> 'ZTIS'.

Rob

Read only

uwe_schieferstein
Active Contributor
0 Likes
666

Hello Shejal

You could simplify your DELETE statement like this:

DELETE itab WHERE   ( 01_kschl = 'ZBX1'  )
                    AND NOT ( 02_kschl = 'ZAXS'  OR
                                     02_kschl = 'ZRON'  OR
                                     02_kschl = 'ZTIS' ).

Regards

Uwe