2023 Mar 02 8:02 AM
Hello, instead of delete the entries in IT_CUSTOM_TAB, I also want to do is if an entry is deleted in IT_CUSTOM_TAB it should also be deleted in the ZCUSTOM_TAB. Is it possible?
SELECT vbeln
posnr
matnr
orqty
FROM zcustom_tab
INTO TABLE it_custom_tab
FOR ALL ENTRIES IN t_vbap
WHERE vbeln = t_vbap-vbeln
AND matnr = t_vbap-matnr
AND posnr = t_vbap-posnr.
LOOP AT t_vbap ASSIGNING FIELD-SYMBOL(<lfs_t_vbap>).
IF it_custom_tab IS NOT INITIAL.
CHECK line_exists( it_custom_tab[ vbeln = <lfs_t_vbap>-vbeln
posnr = <lfs_t_vbap>-posnr ] ).
DELETE it_custom_tab
WHERE vbeln = <lfs_t_vbap>-vbeln
AND posnr = <lfs_t_vbap>-posnr .
ENDIF.
ENDLOOP.
2023 Mar 02 8:31 AM
Yes it is possible to delete entries from database table.
Here is ABAP documentation for DELETE dtab.
But be always careful with modifying database entries. Please read and study about commits, locks (ENQUEUE also) etc. before you start with DB changes 🙂
2023 Mar 03 5:56 AM
Use delete functionality after the loop.
SELECT vbeln
posnr
matnr
orqty
FROM zcustom_tab
INTO TABLE it_custom_tab
FOR ALL ENTRIES IN t_vbap
WHERE vbeln = t_vbap-vbeln
AND matnr = t_vbap-matnr
AND posnr = t_vbap-posnr.
LOOP AT it_custom_tab ASSIGNING FIELD-SYMBOL(<lfs_it_custom_tab>).
CHECK vbeln = <lfs_t_vbap>-vbeln and
posnr = <lfs_t_vbap>-posnr.
Clear: <lfs_t_vbap>-vbeln, <lfs_t_vbap>-posnr
ENDLOOP.
DELETE it_custom_tab
WHERE vbeln is initial AND
posnr is inital.
Modify ZCustom_tab from table it_custom_tab.
2023 Mar 03 7:03 AM
If you want to delete records of the specific table that also exist in standard table, you don't need to fill an (two) internal table(s) and process it (them). Write a DELETE statement with a subquery to check existence in the standard table