‎2010 Mar 16 10:54 AM
Hello Experts,
I am wondering why my delete statement does not work. I want to delete records in my database
table which is not found in my internal table. Below is my code:
SORT ts_selcriteria BY zattrrulid zattrseq zattrssq.
LOOP AT is_ztxx_pt9126 ASSIGNING <fs_ztxx_pt9126>.
*" Check if records was deleted in selection
*" table. If yes, then delete this in table ZTXX_PT9126
READ TABLE ts_selcriteria
ASSIGNING <fs_selcriteria>
WITH KEY zattrrulid = <fs_ztxx_pt9126>-zattrrulid
zattrseq = <fs_ztxx_pt9126>-zattrseq
zattrssq = <fs_ztxx_pt9126>-zattrssq
BINARY SEARCH.
IF sy-subrc ne 0.
DELETE ztxx_pt9126 FROM <fs_ztxx_pt9126>.
ENDIF.
ENDLOOP.
‎2010 Mar 16 10:58 AM
Have you tried not using field symbol, but normal work area instead?
‎2010 Mar 16 10:58 AM
Have you tried not using field symbol, but normal work area instead?
‎2010 Mar 16 11:04 AM
Yes, I also tried using work area but to no avail. Below is my updated code:
e_ztxx_pt9126 = <fs_ztxx_pt9126>.
DELETE ztxx_pt9126 FROM e_ztxx_pt9126.
‎2010 Mar 16 11:17 AM
Is your table and work area type as table/line of Z DB table? If the strcutre is diffent then this might be the issue. Try giving key of entry you want to delete instead of giving work area.
DELETE ztxx_pt9126 FROM where field = e_ztxx_pt9126-field
and field2 = e_ztxx_pt9126-field2
...
Regards
Marcin
‎2010 Mar 16 11:32 AM
e_ztxx_pt9126 = <fs_ztxx_pt9126>.
DELETE ztxx_pt9126 FROM e_ztxx_pt9126.
in this your work area should be of same type as ztxx_pt9126.
and also use COMMIT WORK after delete stmt.
‎2010 Mar 16 11:03 AM
Make sure the key fields match the DB-table exactly (cannot be derived from your post)
Make sure the entry is lockable.
Do a COMMIT WORK if the delete statement was successful and a ROLLBACK WORK if it was not. Check SY-SUBRC after the delete statement.
With kind regards,
Roel van den Berge
‎2010 Mar 16 11:35 AM
LOOP AT is_ztxx_pt9126 ASSIGNING <fs_ztxx_pt9126>.This is a database table? If it is, this statement didn't work. You loop at internal tables. So, you'd need to import the database into an internal table first....or
loop at the internal table.
select the corresponding, matching data from your db table.
if found, then do the delete on the db table.
end the loop.
‎2010 Mar 16 12:41 PM
>
> This is a database table? If it is, this statement didn't work. You loop at internal tables. So, you'd need to import the database into an internal table first....or
Wow !!! And why do we need to select before deleting ?
‎2010 Mar 16 12:53 PM
Hi,
First of all, please check check first the code I posted before you comment. Anyway, I tried everything and still it doesnt work. I tried deleting from worka area, field symbol, etc and putting commit work but still the record is still not deleted.
‎2010 Mar 16 1:22 PM
types : begin of ty_jtab,
f1(10) type c,
end of ty_jtab.
data : jtab type standard table of ty_jtab with header line,
itab type standard table of ty_jtab with header line.
data : wa_jtab type ty_jtab,
wa_itab type ty_jtab.
*populate itab for say db
itab-f1 = '1000'. append itab.
itab-f1 = '2000'. append itab.
itab-f1 = '3000'. append itab.
*populate jtab
jtab-f1 = '1000'. append jtab.
jtab-f1 = '4000'. append jtab.
jtab-f1 = '8000'. append jtab.
jtab-f1 = '9000'. append jtab.
sort itab by f1.
sort jtab by f1.
clear: itab, wa_itab.
loop at itab into wa_itab.
read table jtab into wa_jtab with key f1 = wa_itab-f1
binary search.
if sy-subrc ne 0.
delete itab from wa_itab.
if sy-subrc ne 0.
write :/ 'fail', wa_itab-f1.
endif.
endif.
endloop.
*o/p is two times fail which shows the assumption.
br,
vijay
‎2010 Mar 16 1:19 PM
Why do you say it doesn't work? How do you know the record is not deleted? I don't see any checking of sy-subrc after the delete.
Rob
‎2010 Mar 16 1:31 PM
field-symbols : <fsi> type ty_jtab,
<fsj> type ty_jtab.
loop at itab assigning <fsi>.
read table jtab assigning <fsj> with key f1 = <fsi>-f1
binary search.
if sy-subrc ne 0.
delete itab from <fsi>.
if sy-subrc ne 0.
write :/ 'fail', <fsi>-f1.
endif.
endif.
endloop.
replaced with the fiedsymbols and its showing the same o/p as expected .debugging for sy-subrc after delete may lead to some help. The only thing that can go wrong is if there is any mismatch with the work area or any more key field is not included in wa can lead fail in the delete statement.
br,
Vijay
‎2010 Mar 16 1:38 PM
>
> DELETE ztxx_pt9126 FROM <fs_ztxx_pt9126>.
>
This is not the correct syntax for deleting rows from a database table. Or do you really want to delete a complete cluster?
‎2010 Mar 23 2:48 AM
Hi Aris (VirayLab),
I thought your senior in ABAP. Have you forgotten that pressing F1 to check for correct syntax to delete in a database table would have solved your issue instantly. Or best would have been asking your teammates (BJ or Analyn) or colleagues (Ice, Pao or Rodel).
You see, your problem was so much BASIC ABAP and you took some time posting message/question in SDN. Is this the reason why you refrain from providing timely email updates (because you are waiting for somebody from SDN to solve your issue)?
Also next time, please never ever share company specific/protected programs/coding/objects. Im sure you know that this is illegal.
Cheers,
Bully