Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

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 dd02l-tabname 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 sy-uname <> '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.

2 Comments