04-14-2009 11:19 AM
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.
04-14-2009 11:41 AM
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
04-14-2009 11:24 AM
hi there.... you need not have header line.... infact you need not select anything into a header....
simply use :
select single * from <table name > where <conditions>.
if even a single value is returned, then subrc will be 0, which can be checked easily. if the subrc is not zero, no value was returned and you can easily make out which table is empty. Moreover it will improve the performance also as only one record will be fetched instead of the entire table contents.
hope this helps....
cheers,
Prem Sharma
04-14-2009 11:30 AM
This is not running because I can assing dinamically value to <table name>. Can you write your abap code?
04-14-2009 11:39 AM
Hi,
Try the below code.
DATA dref TYPE REF TO data.
loop at i_table.
tabname = i_table-table.
CREATE DATA dref TYPE (tabname).
ASSIGN dref->* TO <fs_comp>.
SELECT SINGLE * into <fs_comp>
FROM (tabname).
if sy-subrc = 0.
* Exist registers.
endif.
endloop.
Regards,
Sesh
04-14-2009 11:41 AM
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