0

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Codrin Strîmbei
  • 125
  • 7
  • 22

2 Answers2

5

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.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Skalozub
  • 539
  • 7
  • 26
  • 2
    Thank you. This is solving the problem but I have to declare the lt_test as a table to assign it to the field symbol. create data lt_test type table of (iv_data_type). – Codrin Strîmbei Aug 23 '17 at 12:21
1

you can try the following

DATA : lo_struct_des    TYPE REF TO cl_abap_structdescr,
           lo_result_struct TYPE REF TO cl_abap_structdescr.

DATA: lo_new_tab    TYPE REF TO cl_abap_tabledescr .

DATA: lt_struct_tab TYPE abap_component_tab.

DATA: tab  TYPE REF TO data,
      line TYPE REF TO data.

FIELD-SYMBOLS: <fs_data> TYPE ANY TABLE,
               <fs_line> TYPE any.

lo_struct_des ?=  cl_abap_typedescr=>describe_by_name( 'your_Structure_name_here' ).
lt_struct_tab = lo_struct_des->get_components( ) .

lo_result_struct = cl_abap_structdescr=>create( p_components = lt_struct_tab ) .


lo_new_tab = cl_abap_tabledescr=>create( p_line_type  = lo_result_struct
                                         p_table_kind = cl_abap_tabledescr=>tablekind_std
                                         p_unique     = abap_false ).

CREATE DATA tab TYPE HANDLE lo_new_tab.

CREATE DATA line TYPE HANDLE lo_result_struct .

ASSIGN tab->* TO <fs_data>.
ASSIGN line->* TO <fs_line> .
Michael Meyer
  • 2,179
  • 3
  • 24
  • 33