ABAP program – Read table size
Hi Community,
in my recent project I faced a situation when I needed to check how many tables of Offers’ related data are used in SAP CAR system.
I had an idea that it would be useful to search for all tables with *OFR* selection inside DD02L table where all SAP tables are listed.
This would not be enough though, since there might be tables activated but not really used – meaning with 0 records inside. Which brought me into an idea that having a list of all tables (with needed selection) as well as number of records inside those tables would help me understand which tables are used and which one should I focused on.
I would like to present you the code I have written so that you can reuse it when needed. In my code I am using one selection option for search and one parameter for a minimum number of entries that we want to search for.
In SE38 transaction create a program with your name and use the code below.
I hope it will help you.
*&---------------------------------------------------------------------*
*& Report ZTABLESIZE
*&---------------------------------------------------------------------*
REPORT ZTABLESIZE.
*&---------------------------------------------------------------------*
* get time stamp information for future comparison *
*&---------------------------------------------------------------------*
DATA:
time like sy-uzeit,
date like sy-datum.
time = sy-uzeit.
date = sy-datum.
write :/ date, time.
write :/ .
*&-----------------------------------------------------------------------*
* get list of tables with number of entries based on search parameter *
* and minimum number of table entries *
*&-----------------------------------------------------------------------*
tables: dd02l.
SELECT-OPTIONS filter for dd02l-tabname.
Parameters:
min_size type i.
Types:
BEGIN OF ty_tabname,
tabname TYPE TABNAME,
tabrows type i,
end of ty_tabname.
data: tabname type STANDARD TABLE OF ty_tabname.
FIELD-SYMBOLS:
<wa> Type ty_tabname.
select
tabname
from dd02l into CORRESPONDING FIELDS OF table tabname
where tabname in filter
group by
tabname.
sort tabname by tabname.
CALL FUNCTION 'EM_GET_NUMBER_OF_ENTRIES'
tables
it_tables = tabname.
loop at tabname ASSIGNING <wa>.
if <wa>-tabrows >= min_size.
write:/ <wa>-tabname, <wa>-tabrows.
endif.
endloop.
The TABLES statement is obsolete and should not be used.
It would be nice if you indented your code properly to increase readability.
<wa> seems a poor choice of variable naming.