Define two PARAMETERs, one for a name of a database table and one for a WHERE-Condition.
Use the CREATE DATA statement to create an appropriate internal table as a destination for a SELECT on the database table.
Use the OpenSQL SELECT together with Dynamic Token Specification for the FROM and WHERE clause.
At the end, take the form WRITE_TABLE from „Exercise: Generic Internal Table List Writer“ to write the result of the SELECT to the ABAP list.
REPORT zsolar.
PARAMETERS: p_table TYPE dd02l-tabname,
p_condi TYPE string.
DATA dref TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE.
START-OF-SELECTION.
CREATE DATA dref TYPE TABLE OF (p_table).
ASSIGN dref->* TO <fs>.
SELECT * FROM (p_table) INTO TABLE <fs> WHERE (p_condi).
IF <fs> IS ASSIGNED.
PERFORM frm_write_table USING <fs>.
ENDIF.
*&---------------------------------------------------------------------*
*& Form frm_write_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_write_table USING itab TYPE ANY TABLE.
FIELD-SYMBOLS: <fs> TYPE ANY,
<foo> TYPE ANY.
LOOP AT itab ASSIGNING <fs>.
DO.
UNASSIGN <foo>.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <foo>.
IF <foo> IS ASSIGNED.
WRITE: <foo>, '|'.
ELSE.
EXIT.
ENDIF.
ENDDO.
NEW-LINE.
ENDLOOP.
ENDFORM. "frm_write_table