Dynamic table type declaration

Codrin Strîmbei picture Codrin Strîmbei · Aug 23, 2017 · Viewed 7k times · Source

I need to write a FM where I will receive the data type of an element as a string parameter and I would like to declare it like:

DATA: lt_test TYPE TABLE OF (iv_data_type).

where the iv_data type whould be the received type.

Answer

Skalozub picture Skalozub · Aug 23, 2017

You should create your internal table dynamically:

DATA lt_test type ref to data.
FIELD-SYMBOLS: <lts_test> type standard table.
CREATE DATA lt_test type (iv_data_type).
ASSIGN lt_test->* to <lts_test>.


CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
  EXPORTING
    I_TAB_RAW_DATA             = lt_raw_data
  TABLES
    I_TAB_CONVERTED_DATA       =  <lts_table>
  EXCEPTIONS
    CONVERSION_FAILED          = 1
    OTHERS                     = 2.