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
2,800

Hi,

I have a variable w_prodh where all the values of product hierarchy are stored.

Now I want to delete the entries from an internal table where prodh like w_prodh.

If I use the below statement for deleting the entries it is giving syntax error.

delete tab1 where prodh LIKE w_prodh.

Is there any relevant statement for deleting the entries?

18 REPLIES 18
Read only

Former Member
0 Likes
1,828
Read only

Former Member
0 Likes
1,828

Hi,

If w_prodh is a single field of a work area , you can directly assign it in the where conditon


delete tab1 where prodh = w_prodh.

Regards,

Vikranth

Read only

0 Likes
1,828

The variable w_prodh has wild card characters like 007001001%,ZZ1%, ZZ1001%, ZZ1001001002001%.

So we need to delete the entries from internal table where the prodh is like these values.

Is there any relevant statement?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,828

Hello,

How about trying with CP:



DATA: W_BUKRS TYPE BUKRS.

DATA:
IT TYPE STANDARD TABLE OF T001.

W_BUKRS = '110%'.

REPLACE ALL OCCURRENCES OF '%' IN W_BUKRS WITH '*'.

SELECT * FROM T001 INTO TABLE IT WHERE BUKRS LIKE '11%'.

DELETE IT WHERE BUKRS CP W_BUKRS.

IF SY-SUBRC = 0.
ENDIF.

BR,

Suhas

Read only

0 Likes
1,828

try defining w_prodh as a string only.

Read only

0 Likes
1,828

Hi,

In that case use CP operator with '*' for wild card searches in delete statement. Check this example


data: begin of itab occurs 0,
      f1 type string,
      end of itab.

      itab-f1 = '100017'.
      append itab.

      itab-f1 = '100023'.
      append itab.

      itab-f1 = '100013'.
      append itab.


clear itab.
delete itab where f1 CP '10001*'.

loop at itab.
write: itab-f1.
endloop.

Regards,

Vikranth

Read only

0 Likes
1,828

HI,

YOU CAN USE FOLLOWING CONDITION IN WHERE CLAUSE:

WHERE W_PRODH+(3) = 'ZZ1'.

But Be sure that all those entries starting with ZZ1 gets deleted from internal table.

Like this you can create other conditions.

Regds,

Anil

Read only

0 Likes
1,828

you can straight away compare your work area with internal table record and delete it.

but before tat make sure tat u must sort your internal table.

sort itab.

delete itab

Read only

0 Likes
1,828

Hi,

I have used the below code in my program.

DELETE tab2 WHERE prodh CP 'lv_prodh'.

But while debugging this statement is failing.

Please find below the code snippet from my program.

Loop at tab1 INTO wa_pr_auth.

CONCATENATE tab1-prodh '%' INTO lv_prodh.

DELETE tab2 WHERE prodh CP 'lv_prodh'.

Select * from t179 INTO tab_t179 where prodh like lv_prodh.

LOOP AT tab_t179 INTO wa_t179.

wa_pr_auth1-prodh = wa_t179-prodh.

APPEND wa_pr_auth1 TO tab2.

ENDLOOP.

ENDLOOP.

tab1 table has prodh values like 007001001,zz1,zz1001,zz1001001002001,zz3001001,zz4,zz4001,zz4001003.

In the first loop of tab1 table tab2 is not filled so the delete statement fails.

tab2 gets populated in the loop of tab_t179.In the next loop pass of tab1 table,tab2 has some values and the delete statement should be executed.But it is failing.

Could you please tell me how to resolve this issue

Read only

0 Likes
1,828

Hi,

Instead of '%' use '*' for CP operator.


Loop at tab1 INTO wa_pr_auth.

CONCATENATE '*' tab1-prodh '*' INTO lv_prodh.

DELETE tab2 WHERE prodh CP lv_prodh.

Select * from t179 INTO tab_t179 where prodh like lv_prodh.
LOOP AT tab_t179 INTO wa_t179.
wa_pr_auth1-prodh = wa_t179-prodh.
APPEND wa_pr_auth1 TO tab2.
ENDLOOP.
ENDLOOP.

Make sure wa_pr_auth is type string. Only then it will work.

Regards,

Vikranth

Read only

0 Likes
1,828

Just apply this logic in your code

Create a range , append the values to be deleted frim internal table to it.

and then use delete statement


data:ra_matnr type RANGE OF mara-matnr.
data:wa like line of ra_matnr.

wa-option = 'CP'.
wa-sign = 'I'.
wa-low = 'ABC*'.
append wa to ra_matnr.
wa-option = 'CP'.
wa-sign = 'I'.
wa-sign = 'I'.
wa-low = 'BAS*'.
append wa to ra_matnr.

data:it_mara type table of mara.
data:wa1 type mara.

wa1-matnr = 'A'.
append wa1 to it_mara.
wa1-matnr = 'ABCQQ'.
append wa1 to it_mara.
wa1-matnr = 'A'.
append wa1 to it_mara.
wa1-matnr = 'BASTT'.
append wa1 to it_mara.
wa1-matnr = 'C'.
append wa1 to it_mara.

delete it_mara where matnr in ra_matnr.

Edited by: Keshu Thekkillam on Sep 9, 2009 4:11 PM

Edited by: Keshu Thekkillam on Sep 9, 2009 4:15 PM

Read only

Former Member
0 Likes
1,828

Hi,

use this delete tab1 where prodh = w_prodh.

instead of

delete tab1 where prodh LIKE w_prodh.

Regards,

Vijay

Read only

Former Member
0 Likes
1,828

Hi, never used the LIKE clause. But the WHERE field = variable. Or WHERE field IN range works file.

It the table is limited in size you can also LOOP over the table and use the DELETE tab INDEX sy-index option.

Succes.

Read only

Former Member
0 Likes
1,828

hi vikranth,

as u said that is a variable so mostly that variable wil be storing one value at one time and will in a loop to pick all product hierarchies.

so in that case this delete stmt wil also b in loop and u can use "=" instead of like.

what is the necessary of using like.

Can u b more specific and clear the reason ur using like.

Thanks,

Amar

Edited by: amar srinivas on Sep 8, 2009 11:22 AM

Read only

rashmi_purohit2
Explorer
0 Likes
1,828

Hi,

You can use :

delete tab1 where prodh = w_prodh.

Thanks,

Rashmi.

Read only

Former Member
0 Likes
1,828

Use as follows

data : itab type mara occurs 0 with header line.

itab-matnr = '42658'.

append itab .

itab-matnr = '9842258'.

append itab .

itab-matnr = '458'.

append itab .

clear itab .

delete itab where matnr CP '42'.

break-point .

This will solve your problem .

Thanks

Read only

Former Member
0 Likes
1,828

hi,

chk this sample code which helps u.

TYPES : BEGIN OF T_TAB,

SNO TYPE CHAR10,

END OF T_TAB.

DATA : ITAB TYPE TABLE OF T_TAB,

WA_ITAB LIKE LINE OF ITAB.

WA_ITAB-SNO = 'AMAR123'.

APPEND WA_ITAB TO ITAB.

CLEAR WA_ITAB.

WA_ITAB-SNO = 'AMAR1'.

APPEND WA_ITAB TO ITAB.

CLEAR WA_ITAB.

WA_ITAB-SNO = 'AMAR12'.

APPEND WA_ITAB TO ITAB.

CLEAR WA_ITAB.

WA_ITAB-SNO = 'AMAR1234'.

APPEND WA_ITAB TO ITAB.

CLEAR WA_ITAB.

WA_ITAB-SNO = 'KUMAR123777'.

APPEND WA_ITAB TO ITAB.

CLEAR WA_ITAB.

WA_ITAB-SNO = 'KUMAR1237'.

APPEND WA_ITAB TO ITAB.

CLEAR WA_ITAB.

LOOP AT ITAB INTO WA_ITAB.

IF WA_ITAB-SNO+0(4) = 'AMAR'.

DELETE ITAB WHERE SNO = WA_ITAB-SNO.

ENDIF.

ENDLOOP.

Read only

rudy_schmitz
Active Participant
0 Likes
1,828

Hi,

I would suggest to simply build a RANGE with the valid values you have in your string variable, and use, in your delete, the clause WHERE field IN range.

Hope this can help.

Regards,

Rudy

Edited by: Rudy Schmitz on Sep 8, 2009 12:51 PM