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

Please guide me how this Delete Statement is working

Former Member
0 Likes
853

DELETE ITAB WHERE segnam = 'ZCREEXT' OR

                                   segnam = 'E1LFA1M' OR

                                   segnam = 'E1LFB1M' OR

                                   segnam = 'E1LFA1M' OR

                                   segnam = 'E1LFA1B' OR

                              segnam = 'E1LFA1A' OR

                              segnam = 'E1LFA1H' OR

                              segnam = 'E1LFA1L' OR

                              segnam = 'E1LFB1M' OR

                              segnam = 'E1LFBWM' OR

                              segnam = 'E1LFB5M' OR

                              segnam = 'E1LFB1H' OR

                              segnam = 'E1LFB1L'.

Now my question is Would this Statement would delete the segments available in Table ITAB as provided in the Condition.

Now in my code it is deleting the segments present in table ITAB as mentioned in the where clause. But i think it should only delete whichever the condition holds true..

Pls guide me whether this statement is correct or will it falter somewhere.

DELETE ITAB WHERE segnam = 'ZCREEXT' OR

                                   segnam = 'E1LFA1M' OR

                                   segnam = 'E1LFB1M' OR

                                   segnam = 'E1LFA1M' OR

                                   segnam = 'E1LFA1B' OR

                              segnam = 'E1LFA1A' OR

                              segnam = 'E1LFA1H' OR

                              segnam = 'E1LFA1L' OR

                              segnam = 'E1LFB1M' OR

                              segnam = 'E1LFBWM' OR

                              segnam = 'E1LFB5M' OR

                              segnam = 'E1LFB1H' OR

                              segnam = 'E1LFB1L'.

Now my question is Would this Statement would delete the segments available in Table ITAB as provided in the Condition.

Now in my code it is deleting the segments present in table ITAB as mentioned in the where clause. But i think it should only delete whichever the condition holds true..

Pls guide me whether this statement is correct or will it falter somewhere.

6 REPLIES 6
Read only

matt
Active Contributor
0 Likes
815

If segnam is 'ZCREEXT', the record will be deleted.

If segnam is 'E1LFA1M' the record will be deleted

If segnam is 'E1LFB1M' the record will be deleted.

...

etc.

...

What's the problem? The DELETE statement removes exactly those records where the condition holds true. Perhaps your understanding of the condition is incorrect? What are you expecting?

Read only

Former Member
0 Likes
815

Thanks for the reply..

I was of understanding that OR means that any of the conditions would work not both.

so nevertheless ur reply sorted out my confusion. thanks alot

Read only

Former Member
0 Likes
815

This message was moderated.

Read only

Former Member
0 Likes
815

Hi Rajat,

The records from the itab will be deleted for any of the condition you have specified since you are using 'OR'. There may be chances of multiple deletion of records. If segnam matches any of 'ZCREEXT' or

'E1LFA1M' or 'E1LFB1M' or 'E1LFA1M', the record will be deleted.

Read only

Former Member
0 Likes
815

DATA: BEGIN OF ITAB OCCURS 0,

      sno type i,

      segnam type c LENGTH 7,       "Plant+ material

   END OF  ITAB.

itab-SNO = 1.

ITAB-segnam = 'ZCREEXT'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 2.

ITAB-segnam = 'E1LFA1M'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 3.

ITAB-segnam = 'E1LFB1M'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 4.

ITAB-segnam =   'E1LFA1B'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 5.

ITAB-segnam = 'E1LFA1M'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 6.

ITAB-segnam = 'E1LFA1A'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 7.

ITAB-segnam = 'E1LFA1H'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 8.

ITAB-segnam = 'E1LFA1L'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 9.

ITAB-segnam = 'E1LFB1M'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 10.

ITAB-segnam = 'E1LFBWM'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 11.

ITAB-segnam = 'E1LFB5M'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 12.

ITAB-segnam = 'E1LFB1H'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 13.

ITAB-segnam = 'E1LFB1L'.

APPEND ITAB.

CLEAR ITAB.

itab-SNO = 14.

ITAB-segnam = 'ABCDE'.

APPEND ITAB.

CLEAR ITAB.

DELETE ITAB WHERE segnam = 'ZCREEXT' OR

                                    segnam = 'E1LFA1M' OR

                                    segnam = 'E1LFB1M' OR

                                    segnam = 'E1LFA1M' OR "no need to repeat

                                    segnam = 'E1LFA1B' OR

                               segnam = 'E1LFA1A' OR

                               segnam = 'E1LFA1H' OR

                               segnam = 'E1LFA1L' OR

                               segnam = 'E1LFB1M' OR

                               segnam = 'E1LFBWM' OR

                               segnam = 'E1LFB5M' OR

                               segnam = 'E1LFB1H' OR

                               segnam = 'E1LFB1L'.

LOOP AT ITAB.

WRITE😕 ITAB-SEGNAM.

ENDLOOP.

YOUR REUSLT WILL BE ABCDE.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
815

What do you exactly expect, you only post a statement for deletion, and then you ask us if it does what it is intended to do ?

If the statement doesn't work as you expected you wrongly code it, but as long as you don't write your exact requirement; guessing it is difficult/hazardous, try to write your requirement in plain logical English...

Regards,

Raymond