Application Development 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: 

How do I delete an entry in a custom table inside a program?

walkerist
Participant
0 Kudos
270

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.
3 REPLIES 3

Tomas_Buryanek
Active Contributor
213

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 🙂

-- Tomas --

shantraj
Explorer
0 Kudos
213

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.

raymond_giuseppi
Active Contributor
0 Kudos
213

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