Let's say you took the following parameters as input.
DATA: table_name TYPE string VALUE 'MARA',
column_id TYPE string VALUE 'MATNR',
column_name TYPE string VALUE 'MTART',
name_value TYPE string VALUE 'HALB'.
First, dynamically create a table of the type you will select into.
DATA: results TYPE REF TO data,
tablety TYPE string.
FIELD-SYMBOLS <results> TYPE STANDARD TABLE.
tablety = table_name && '-' && column_id.
CREATE DATA results TYPE TABLE OF (tablety).
ASSIGN results->* TO <results>.
Then use a dynamic query to fill the table.
DATA: condition TYPE string.
condition = column_name && ` = name_value`.
SELECT (column_id) FROM (table_name)
INTO TABLE results
WHERE (condition).
Pass back the generically-typed reference to the calling program.