‎2006 Oct 20 7:48 AM
Dear All,
I am working with the following code in order to delete all those records from my ztable (zvdelivery1) that do not have the MATNR (mat.no.) of 18 characters. In other words I wish to delete the corrupt data from this table but there is something wrong with this code as it's not deleting the said data.
Kindly have a look and advise the corrections.
Regards,
Alok.
start-of-selection.
select amatnr abox_no adat aexcise_from aexcise_to abox_size1
into corresponding fields of table itab
from zvdelivery1 as a where
plant eq '1010'.
loop at itab.
count = strlen( itab-matnr ).
if count lt 18.
main_table-matnr = itab-matnr.
main_table-box_no = itab-box_no.
main_table-dat = itab-dat.
main_table-excise_from = itab-excise_from.
main_table-excise_to = itab-excise_to.
main_table-box_size1 = itab-box_size1.
append main_table.
endif.
endloop.
loop at main_table.
DELETE from zvdelivery1
WHERE MATNR = MAIN_TABLE-MATNR AND
BOX_NO = main_table-box_no.
ENDLOOP.
end-of-selection.
‎2006 Oct 20 10:38 AM
Did you check with having a work area instead of internal table with header line? Sometimes header line is a big headache.
Loop at main_table into wa_maintable.
DELETE from zvdelivery1
WHERE MATNR = wa_MAINTABLE-MATNR AND
BOX_NO = wa_maintable-box_no.
endloop.
Try testing using this work area solution. Might help you solve the prob.
‎2006 Oct 20 7:50 AM
just remove the leading or the trailing spaces/zeroes from the
itab-matnr then use the function STRLEN.
abhishek
Message was edited by: Abhishek Suppal
Message was edited by: Abhishek Suppal
‎2006 Oct 20 8:02 AM
Sorry Abhishek it seems that you didn't understand my requirement. Issue is not of trailing or leading zeros, the corrupt data contains periods (.), underscores(_) and all sorts of unwanted characters and all these material nos donot have full 18 digits. Hence the only way possible to write the code to delete them at once..and hence I had adopted the logic of computing the string length.
Anythanks a lot for responding..
Alok.
‎2006 Oct 20 7:55 AM
Hi,
if you have problem with the leading 0 before the material code, you could use this function :
CONVERSION_EXIT_MATN1_INPUT
Have fun
Fred
‎2006 Oct 20 8:01 AM
Problem is with the COUNT variable. You may use:
SHIFT count RIGHT DELETING TRAILING '0'.
SHIFT count LEFT DELETING LEADING '0'.
Apart from that, a small suggestion. From the select query and the loop immediately below that, I understand that you have already taken all the unwanted data in MAIN_TABLE. If so, you need not loop through it to delete from database table ZVDELIVERY1. Instead without looping, you can write:
DELETE zvdelivery1 FROm MAIN_TABLE.
As all the fields are same as zvdelivery table and values are taken from dbtable only. This statement will improve performance as well.
Let me know if you have any further queries.
Don't forget to mark helpful answers!
Gaurav Parmar.
‎2006 Oct 20 8:15 AM
Dear Gaurav,
First of all, thanks for responding.
The problem, I'll say once again, is not of leading or trailing zeros. Requirement is very simple..to delete all the records from the table in which matnr is not of 18 characters. Hence I had gone for STRLEN to compute the length of the contents of matnr and if they are less than 18 --> Delete that particular record.
I tried with modifying this code a little bit..and the same resulted with deletion of only one record and leaving rest of them in the table..may be just deleting the record residing in the header of my table.
Please have another look to it.
Thanks once again,
Alok.
‎2006 Oct 20 9:35 AM
Alok,
I would suggest to put a break-point after you collect the data in Main_table.
Here check the contents of main_table, if it has all the records (ones with less than 18 in lenght). If yes than the problem is with the delete loop otherwise in strlen.
Regards
Anurag
‎2006 Oct 20 8:09 AM
Hi Alok,
do like this...
constants : c_18 type c value '18'.
loop at itab into wa_itab.
count = strlen( itab-matnr ).
if count lt c_18.
move the data to maintable.
else.
delete itab.
endloop.
regards,
nagaraj
‎2006 Oct 20 8:30 AM
Hi Alok ,
i got ur query ,,
-
loop at main_table.
DELETE from zvdelivery1
WHERE MATNR = MAIN_TABLE-MATNR AND
BOX_NO = main_table-box_no.
ENDLOOP.
-
instead of this
get the main_table contents into itab where
as u say the matnr can be v*-.1234aofdmcpilo
so ur itab will be like this
matnr | box no | date
-
v*-.1234aofdmcpilo | 20 | 10122006
K#$%^&*ASDIFNIFDID | 30 | 11232006
$@%&&*43943434DFDDD| 40 | 12232006
so get the whole contents into ur itab.
now use only this
DELETE ZDELIVERY1 FROM TABLE MAIN_TABLE .
if sy-subrc eq 0 .
write:/ records deleted.
endif.
NOTE.
DONT PUT THIS(DELETE STATEMENT ) IN A LOOP .
Regards,
Vijay.
‎2006 Oct 20 10:14 AM
Hi Alok,
is the matnr and box_no are the primary keys of your table?
try deleting the records with all the primary keys.
-Anu.
‎2006 Oct 20 10:38 AM
Did you check with having a work area instead of internal table with header line? Sometimes header line is a big headache.
Loop at main_table into wa_maintable.
DELETE from zvdelivery1
WHERE MATNR = wa_MAINTABLE-MATNR AND
BOX_NO = wa_maintable-box_no.
endloop.
Try testing using this work area solution. Might help you solve the prob.
‎2006 Oct 26 5:52 AM
Dear Gaurav,
This refers to your reply to my problem.
Shall you please be kind enough to please let me know whether will I have to declare this workarea first in the declaration part, if so how. I haven't worked with workarea yet. Hence this request please.
Alok.
‎2006 Oct 26 6:01 AM
Hi,
select amatnr abox_no adat aexcise_from aexcise_to abox_size1
into corresponding fields of table itab
from zvdelivery1 as a where
plant eq '1010'.
loop at itab.
count = strlen( itab-matnr ).
if count lt 18.
delete zdelivery1 where matnr = itab-matnr.
endif.
endloop.