report z_excel.
* PART 1
* Data preparation
*
types: orders type zorders. " set any sap table
data: w_orders type orders,
t_orders type table of orders.
select * from zorders into table t_orders up to 5000 rows. " set the sap table
* PART 2
* Convert original structure to one column string table
* with the data fields, separated by TAB and CRLF at the
* end of lines.
*
data: r_des type ref to cl_abap_structdescr,
r_orders type ref to data,
t_comp type abap_component_tab,
r_exc type ref to cx_root,
t_row type table of string,
tab_separated_row type string, " @old: type soli
t_lines type table of string, " @old: type table of soli
table_as_string type string,
cast_string type string.
field-symbols: <cell> type any.
create data r_orders like line of t_orders.
r_des ?= cl_abap_typedescr=>describe_by_data_ref( r_orders ).
t_comp = r_des->get_components( ).
data: r_cell_des type ref to cl_abap_datadescr,
cell_type type string.
loop at t_orders assigning field-symbol(<order>).
loop at t_comp assigning field-symbol(<component>).
assign component <component>-name of structure <order> to <cell>.
" investigate the <cell> type
r_cell_des ?= cl_abap_typedescr=>describe_by_data( <cell> ).
cell_type = r_cell_des->type_kind. "returns letter like cell type: I, D, C...
if cell_type = 'I'.
" process the cell according the cell_type...
endif.
cast_string = <cell>.
append cast_string to t_row.
endloop.
append cl_abap_char_utilities=>cr_lf to t_row.
concatenate lines of t_row into tab_separated_row separated by cl_abap_char_utilities=>horizontal_tab.
append tab_separated_row to t_lines.
clear t_row.
endloop.