I am trying to search 8 tables and check if a certain value is present. I searched around a lot an I assume I have to work with field-symbols and dynamic statements. This is done in a report (executable program). So far I have my internal table, filled with 8 table names of the table that have to be searched:
BEGIN OF lt_tables_to_search_coll OCCURS 0,
name TYPE tabname,
END OF lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_01'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_02'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_03'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_04'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_05'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_06'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_07'.
APPEND lt_tables_to_search_coll.
lt_tables_to_search_coll-name = 'TAB_08'.
APPEND lt_tables_to_search_coll.
So now I suppose I make a loop to go over this table. In this loop I go into the select statement and add the found values to a previously declared table.
What I tried is:
PARAMETERS: p_id TYPE "id-type"
START-OF-SELECTION.
LOOP AT lt_tables_to_search_coll.
DATA: lv_current_table VALUE lt_tables_to_search_coll-name.
SELECT tabname AS table_id ddtext AS table_description
COUNT(*) AS nr_of_records FROM (lv_current_table)
INTO TABLE lt_where_used_data_of_coll
WHERE id = p_id AND ddlanguage = 'EN'
GROUP BY tabname ddtext.
ENDLOOP.
When I run this however I get the error that lt_tables_to_search_coll-name is not a constant. I would like to know I should implement what I am trying to do.