Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Read tables dynamically

Hi,

We need to read several tables to determine if they are empty. We have create a program that read all tables from a text file. But <ft_comp> is not assigned with header structure to read table.

DATA: BEGIN OF i_table OCCURS 500,

table(30),

END OF i_table.

DATA: tabname(30).

FIELD-SYMBOLS <fs_comp> type any.

PARAMETERS p_file(128).

START-OF-SELECTION.

  • Obtains file with tables

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p_file

filetype = 'DAT'

TABLES

data_tab = i_table

EXCEPTIONS

conversion_error = 01

file_open_error = 02.

  • Read all tables

loop at i_table.

tabname = i_table-table.

assign (tabname) to <fs_comp>.

SELECT SINGLE * into <fs_comp>

FROM (tabname).

if sy-subrc = 0.

  • Exist registers.

endif.

endloop.

Former Member
replied

Hi, try this (your code adapted):

.DATA: BEGIN OF i_table OCCURS 500,
table(30),
END OF i_table.
DATA: tabname(30).
*FIELD-SYMBOLS <fs_comp> type any.

PARAMETERS p_file(128).

START-OF-SELECTION.

* Obtains file with tables
  CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      filename         = p_file
      filetype         = 'DAT'
    TABLES
      data_tab         = i_table
    EXCEPTIONS
      conversion_error = 01
      file_open_error  = 02.

* Read all tables
  LOOP AT i_table.

    tabname = i_table-table.

*assign (tabname) to <fs_comp>.
    SELECT COUNT( * ) FROM (tabname).
    IF sy-dbcnt > 0.
      WRITE:/ tabname, sy-dbcnt.
* Exist registers.
    ENDIF.

  ENDLOOP.

.

This should works.

Andrea

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question