Application Development and Automation 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: 
Read only

Viewing data from Multiple Tables

Former Member
0 Likes
697

Hello all,

Is it possible to check whether all tables starting with S has got data in a single shot?

Thanks,

Regards,

Hasan

5 REPLIES 5
Read only

Former Member
0 Likes
667

Create view for viewing data from multiple table.

Read only

ThomasZloch
Active Contributor
0 Likes
667

Not possible from ABAP. If you explain more about the context, maybe a different solution is possible.

Thomas

Read only

Former Member
0 Likes
667

Hi Hasan,

In table DD02T you can find all table names.

First copy this table to an internal table, then loop over it.

Check if the first character of the table name contains the 'S'.

If so, append these to a new table.

Then, for each table you can try to read the first line, if sy-subrc = 0, the table contains data. Otherwise, it is empty.

Be aware, this might take a very long time. There are over a million tables in DD02T. And if you want to check for many tables if they have any content, this would impose a lot of effort on your database.

Best regards,

Steven

Read only

0 Likes
667
REPORT  ztest_ssp.

TYPES: BEGIN OF ty_dd02l,
         tabname TYPE tabname,
          tabclass TYPE tabclass,
          lines TYPE i,
       END OF ty_dd02l.

DATA: it_dd02l TYPE TABLE OF ty_dd02l,
      wa_dd02l TYPE ty_dd02l,
      lv_tabname TYPE tabname,
      lv_int TYPE i.

* ALV variables declaration:
DATA: lr_table     TYPE REF TO cl_salv_table,
      lr_functions TYPE REF TO cl_salv_functions,
      lr_msg       TYPE REF TO cx_salv_msg,
      lv_text      TYPE string.

FIELD-SYMBOLS: <tab_name> TYPE ty_dd02l,
               <fs> TYPE any.

SELECT-OPTIONS: so_tabnm FOR lv_tabname.
PARAMETERS: p_test TYPE xfeld AS CHECKBOX.

SELECT tabname tabclass
  FROM dd02l
  INTO TABLE it_dd02l
  WHERE tabname IN so_tabnm
  AND tabclass = 'TRANSP'.

LOOP AT it_dd02l ASSIGNING <tab_name>.
  lv_tabname = <tab_name>-tabname.
  SELECT COUNT(*)
    FROM (lv_tabname)
    INTO lv_int.

  IF lv_int = 0.
    DELETE TABLE it_dd02l FROM <tab_name>.
  ELSE.
    <tab_name>-lines = lv_int.
  ENDIF.

  CLEAR lv_int.
ENDLOOP.

TRY.
    cl_salv_table=>factory( IMPORTING r_salv_table = lr_table
                             CHANGING t_table = it_dd02l ).
  CATCH cx_salv_msg INTO lr_msg.
    lv_text = lr_msg->get_text( ).
    MESSAGE e000(zmmps) WITH lv_text.

ENDTRY.

lr_functions = lr_table->get_functions( ).
lr_functions->set_all( abap_true ).

* Next we need to display the grid, for this we use the DISPLAY method .
lr_table->display( ).
Read only

0 Likes
667

Hello Steven,

Thanks a lot for your detailed information & coding.

I will try n let you know...

Regards,

Hasan