Hello guys,

Maybe thats a repost, but i couldn’t find something like this or maybe it’s too easy for most of you.

My problem was while develping a report, I had to fill several tables. So i needed a report to reset my Z-tables (delete all entries). It’s an easy lession if you use just one table in a report or clear all your table with hardcoding. But i wanted to create a programm which i can use for every project and every Z-Table.

Please beware to use this on your own risk. Deleteing data from a table is always sensitiv issue, so don’t use this one if you dont know what you exacly doing.

There is a parameter where you can enter the name of the table which you want so empty and two radiobuttons. The radio buttons are for  showing the data which should be deleted and for the deleteing itself.

I’ll tried to add a lot of commands, but i you have questions fell free to ask.

DATA: ref_tab TYPE REF TO DATA.                         “Generic data referenc
DATA: lv_char TYPE C.                                   “First letter to test if you want to delte a Z Table
DATA: l_tabname TYPE dd02ltabname VALUE ‘z_testtable’. “Name of the Z Table
DATA: lv_lines TYPE I.                                  “line count
DATA: gr_table TYPE REF TO cl_salv_table.               “For preview, so you can see waht you want to delte

FIELD-SYMBOLS: <fs> TYPE TABLE.                         “Fieldsymbole, which will get assigned late with the type of the entered table.

PARAMETERS: p_dbname TYPE string DEFAULT ‘z_testtable’. “Name of the table you want to delete
PARAMETERS: rb_test TYPE flag RADIOBUTTON GROUP grp1 DEFAULT ‘X’. “testrun
PARAMETERS: rb_del TYPE flag RADIOBUTTON GROUP grp1.              “Every Entry in this table will be !!!DELETED!!!

try.
     CREATE DATA ref_tab TYPE TABLE OF (p_dbname).   “Create the table with the type of the entered table
   catch CX_SY_CREATE_DATA_ERROR.                    “Table name was not found.
     Message ‘Not able to find structur’ type ‘E’.
   CLEANUP.
endtry.
ASSIGN ref_tab->* TO <fs>.                    “Asssigne structure

SELECT * FROM (p_dbname) INTO TABLE <fs>.     “Select data

WRITE p_dbname TO lv_char.                    “Write the first letter to the Character field
TRANSLATE  lv_char TO UPPER CASE.             “Transalte to upper case, so you can thest if it is a ZTable

“Now doning some checks before you are able to delete. You can insert and authorizations object, but that will go to far…
IF rb_del = ‘X’.
   IF syuname <> ‘HANI’.                      “<– Oay this is my Username, you have to repalce it with your own
     MESSAGE ‘Sorry, seems to be a programm your a not allowed to use!’ TYPE ‘E’.
     LEAVE PROGRAM.
   ENDIF.

   IF lv_char <> ‘Z’.                            “<– Now ill check if you deleteing a ZTable. You dont HAVE TO delete sap tables within this report.
     MESSAGE ‘Naaahhh, we will not delete sap tables, only z tables.’ TYPE ‘E’.
     LEAVE PROGRAM.
   ENDIF.

   DESCRIBE TABLE  <fs> LINES lv_lines.        “Count how many lines you will deltete

“&– Edit 16.02
   DELETE FROM (p_dbname).        “delete

“&– End Edit
   WRITE: ‘Table: ‘, p_dbname , ‘ – ‘, lv_lines , ‘ Entries been delteted’. “Screen output.

elseif rb_test = ‘X’.                         “Data will be show which should be deltete, copied from a sap-BC XY report
   CALL METHOD cl_salv_table=>factory
     IMPORTING
       r_salv_table = gr_table
     CHANGING
       t_table      = <fs>.
   gr_table->display( ).
endif.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Nikolay Evstigneev

    Hi!

    After skipping the report text I was wondered why you are using parameters for the table name. It means you’ll have to run the report for every table to delete the data. You can do it in SE14 without the need of creating any Z code.

    The only usage for this report I see is making some wrapper for it to run for a number of tables you choose.

    (0) 
  2. Tomas Buryanek

    I would not recommend creating this kind of program. If you need delete records you can use standard ways.

    And it is possible to delete table content without creating internal table and without selecting all data:

    DELETE FROM (p_dbname).

    (0) 

Leave a Reply