2009 Sep 08 9:59 AM
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?
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
2009 Sep 08 10:02 AM
press F1 on delete key word and show the help for itab
try this - http://help.sap.com/erp2005_ehp_04/helpdata/en/fc/eb3aef358411d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/EN/06/aafd54fc4011d195280000e8353423/content.htm
Edited by: mayank jain on Sep 8, 2009 11:14 AM
2009 Sep 08 10:04 AM
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
2009 Sep 08 10:09 AM
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?
2009 Sep 08 10:13 AM
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
2009 Sep 08 10:13 AM
2009 Sep 08 10:24 AM
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
2009 Sep 08 11:43 AM
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
2009 Sep 08 12:02 PM
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
2009 Sep 09 11:34 AM
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
2009 Sep 09 11:39 AM
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
2009 Sep 09 11:40 AM
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
2009 Sep 08 10:09 AM
Hi,
use this delete tab1 where prodh = w_prodh.
instead of
delete tab1 where prodh LIKE w_prodh.
Regards,
Vijay
2009 Sep 08 10:09 AM
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.
2009 Sep 08 10:14 AM
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
2009 Sep 08 10:25 AM
Hi,
You can use :
delete tab1 where prodh = w_prodh.
Thanks,
Rashmi.
2009 Sep 08 10:45 AM
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
2009 Sep 08 11:19 AM
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.
2009 Sep 08 11:50 AM
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
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |