Coding To Delete Record from Z-Table

How to write abap codes to delete from Z table?

Try with FM SE16N_INTERFACE 

I_TAB = Name of the table(MARA)
I_EDIT = 'X'
I_SAPEDIT = 'X'

Tables
IT_SELFIELDS
pass the value of the fields in table and then append that to IT_SELFIELDS
Field MATNR
S I
OP EQ
LOW value 

or  you can use 
delete db from table itab.
Here itab should be a internal table and contain the data to be deleted.

or

delete from db where condition.

update db from table itab. 

Check this program its for update and delete the records from a table

*&---------------------------------------------------------------------*
*& Report  ZTEST6                                                      *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZTEST6      NO STANDARD PAGE HEADING MESSAGE-ID SAPLWOSA.

*=======================================================================
* Variables
*=======================================================================
DATA DESCR_STRUCT_REF TYPE REF TO CL_ABAP_STRUCTDESCR.
DATA WA_FCAT TYPE LVC_S_FCAT.
DATA IT_FIELDCATALOG TYPE LVC_T_FCAT.
DATA DATAREF TYPE REF TO DATA.

DATA: ONE  LIKE PCFILE-DRIVE,
      TWO  LIKE PCFILE-PATH,
      LONG TYPE I,
      FLAG TYPE C,
      FILEPATH(128) TYPE C,
      FILE_TAB TYPE STRING,
      TABNAME LIKE DD02L-TABNAME.

*=======================================================================
* Field-Symbols.
*=======================================================================
FIELD-SYMBOLS:
              <ROW> TYPE ANY TABLE,
              <TABLE> TYPE STANDARD TABLE,
              <COMPONENT> TYPE ABAP_COMPDESCR,
              <FS>  TYPE ANY.

*=======================================================================
* Selection screen
*=======================================================================
SELECTION-SCREEN BEGIN OF BLOCK DATA WITH FRAME TITLE TEXT-T01.
PARAMETERS:
    TABNAM(128) TYPE C,
    FUNCTION(1) TYPE C OBLIGATORY,
    LISTNAME LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK DATA.

*=======================================================================
* At Selection screen
*=======================================================================
AT SELECTION-SCREEN ON VALUE-REQUEST FOR LISTNAME.
  PERFORM GET_FILENAME CHANGING LISTNAME.

*=======================================================================
* Start-of-selection
*=======================================================================
START-OF-SELECTION.
  CLEAR FLAG.
  PERFORM LOAD_DATA USING TABNAM.
  PERFORM VERIFY_TABLE USING TABNAM CHANGING FLAG.
  IF FLAG NE 'X'.
    IF FUNCTION EQ 'D'.
      PERFORM CREATE_TABLE USING TABNAM.
      PERFORM DOWNLOAD_TABLE USING TABNAM.
    ELSE.
     IF FUNCTION EQ 'U'.
      PERFORM CREATE_TABLE USING TABNAM.
      PERFORM UPLOAD_TABLE USING TABNAM.
    ENDIF.
*  ELSE.
    MESSAGE S000 WITH 'The proposed table doesn''t exist.'.
  ENDIF.
    ENDIF.

*---------------------------------------------------------------------*
*       FORM GET_FILENAME                                             *
*---------------------------------------------------------------------*
*       Name of the directory.
*---------------------------------------------------------------------*
FORM GET_FILENAME CHANGING LISTNAME.

  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            DEF_FILENAME     = LISTNAME
            DEF_PATH         = 'C:\downloads\list'
            MASK             = ',*.*,*.*. '
            MODE             = 'S'
            TITLE            = 'Save as'
       IMPORTING
            FILENAME         = LISTNAME
       EXCEPTIONS
            INV_WINSYS       = 1
            NO_BATCH         = 2
            SELECTION_CANCEL = 3
            SELECTION_ERROR  = 4
            OTHERS           = 5.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM LOAD_DATA                                                *
*---------------------------------------------------------------------*
*       Specifies the path and table name
*---------------------------------------------------------------------*
FORM LOAD_DATA USING MY_TAB.

  DATA: W_FILE LIKE PCFILE-PATH.
  W_FILE = LISTNAME.
  CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
       EXPORTING
            COMPLETE_FILENAME = W_FILE
       IMPORTING
            DRIVE             = ONE
            PATH              = TWO
       EXCEPTIONS
            INVALID_DRIVE     = 1
            INVALID_EXTENSION = 2
            INVALID_NAME      = 3
            INVALID_PATH      = 4
            OTHERS            = 5.
  CONCATENATE ONE ':' TWO INTO FILEPATH.
  CONCATENATE FILEPATH MY_TAB '.txt' INTO FILE_TAB.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM DOWNLOAD_TABLE                                           *
*---------------------------------------------------------------------*
*       Downloads the table data.
*---------------------------------------------------------------------*
FORM DOWNLOAD_TABLE USING MY_TAB.

  SELECT *
  INTO TABLE <ROW>
  FROM (MY_TAB).

  ASSIGN <ROW> TO <TABLE>.

  CALL FUNCTION 'GUI_DOWNLOAD'
       EXPORTING
            FILENAME                = FILE_TAB
            FILETYPE                = 'ASC'
       TABLES
            DATA_TAB                = <TABLE>
       EXCEPTIONS
            FILE_WRITE_ERROR        = 1
            NO_BATCH                = 2
            GUI_REFUSE_FILETRANSFER = 3
            INVALID_TYPE            = 4
            NO_AUTHORITY            = 5
            UNKNOWN_ERROR           = 6.

  IF SY-SUBRC EQ 0.
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              TITEL = 'Successful Download'
              TXT1  = 'All the data from the table'
              TXT2  = 'was correctly downloaded.'.
  ELSE.
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              TITEL = 'Download Error!'
              TXT1  = 'The data of the table'
              TXT2  = 'couldn''t be downloaded.'.
  ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM UPLOAD_TABLE                                           *
*---------------------------------------------------------------------*
*       Table Upload.
*---------------------------------------------------------------------*
FORM UPLOAD_TABLE USING MY_TAB.

  ASSIGN <ROW> TO <TABLE>.

  CALL FUNCTION 'GUI_UPLOAD'
       EXPORTING
            FILENAME                = FILE_TAB
            FILETYPE                = 'ASC'
       IMPORTING
            FILELENGTH              = LONG
       TABLES
            DATA_TAB                = <TABLE>
       EXCEPTIONS
            FILE_OPEN_ERROR         = 1
            FILE_READ_ERROR         = 2
            NO_BATCH                = 3
            GUI_REFUSE_FILETRANSFER = 4
            INVALID_TYPE            = 5
            NO_AUTHORITY            = 6
            UNKNOWN_ERROR           = 7.

  MODIFY (MY_TAB) FROM TABLE <TABLE>.

  IF SY-SUBRC EQ 0.
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              TITEL = 'Successful Upload'
              TXT1  = 'All the data from the table'
              TXT2  = 'was correctly uploaded.'.
  ELSE.
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              TITEL = 'Upload Error!'
              TXT1  = 'The data of the table'
              TXT2  = 'couldn''t be uploaded.'.
  ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM CREATE_TABLE                                             *
*---------------------------------------------------------------------*
*       Creates a dynamic internal table.
*---------------------------------------------------------------------*
FORM CREATE_TABLE USING MY_TAB.
  CREATE DATA DATAREF TYPE (MY_TAB).

  ASSIGN DATAREF->* TO <FS>.

  DESCR_STRUCT_REF ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <FS> ).

  LOOP AT DESCR_STRUCT_REF->COMPONENTS ASSIGNING <COMPONENT>.
    WA_FCAT-FIELDNAME     = <COMPONENT>-NAME.
    WA_FCAT-REF_TABLE     = MY_TAB.
    WA_FCAT-REF_FIELD     = <COMPONENT>-NAME.
    APPEND WA_FCAT TO IT_FIELDCATALOG.
  ENDLOOP.

  CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
     EXPORTING
       IT_FIELDCATALOG           = IT_FIELDCATALOG
     IMPORTING
       EP_TABLE                  = DATAREF
     EXCEPTIONS
       GENERATE_SUBPOOL_DIR_FULL = 1
       OTHERS                    = 2.

  ASSIGN DATAREF->* TO <ROW>.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  VERIFY_TABLE
*&---------------------------------------------------------------------*
*       The table must exist!
*----------------------------------------------------------------------*
FORM VERIFY_TABLE USING TABNAM CHANGING FLAG.
  SELECT SINGLE TABNAME
  INTO (TABNAME)
  FROM DD02L
  WHERE TABNAME EQ TABNAM.

  IF SY-SUBRC NE 0.
    FLAG = 'X'.
  ENDIF.
ENDFORM.

ABAP Tips

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.