report ZTST.
types:
begin of ts_output,
id type i,
tab type string,
descr type string,
data type ref to data,
end of ts_output,
tt_output type table of ts_output
.
data:
gv_tabname type tabname,
gt_output type tt_output,
gv_result_html type string.
select-options:
so_tabnm for gv_tabname no intervals
.
start-of-selection.
perform f_get_data
using so_tabnm[]
changing gt_output
.
perform f_format_table_html
using gt_output "it_tab
changing gv_result_html "cv_html
.
gv_result_html = |<meta charset="utf-8"><body>{ gv_result_html }</body>|.
data:
lt_export type table of string.
append gv_result_html to lt_export.
call method cl_gui_frontend_services=>gui_download
exporting
* bin_filesize =
filename = 'C:\Temp\Demo.html'
filetype = 'ASC'
codepage = '1504'
write_bom = ''
changing
data_tab = lt_export
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.
**********************************************************************
form f_get_data
using i_tabname type any table
changing ct_output type tt_output
.
data:
lo_result type ref to cl_sql_result_set,
lo_tab_handler type ref to cl_abap_tabledescr,
lo_res type ref to data,
lv_sql type string
.
field-symbols:
<lfs_tabname_range> type any,
<lfs_tabname> type any
.
loop at i_tabname
assigning <lfs_tabname_range>.
assign component 'LOW'
of structure <lfs_tabname_range>
to <lfs_tabname>
.
lv_sql = |select * from "{ <lfs_tabname> }"|.
lo_result = cl_sql_connection=>get_connection(
)->create_statement(
)->execute_query(
lv_sql
).
lo_tab_handler = cl_abap_tabledescr=>get(
p_line_type = cast cl_abap_datadescr(
cl_abap_structdescr=>describe_by_data_ref(
lo_result->get_struct_ref(
lo_result->get_metadata( )
)
)
)
)
.
create data lo_res type handle lo_tab_handler.
lo_result->set_param_table(
lo_res
).
lo_result->next_package( ).
lo_result->close( ).
append value #(
id = sy-tabix
tab = <lfs_tabname>
descr = |Содержимое таблицы { <lfs_tabname> }|
data = lo_res
) to ct_output.
endloop.
endform.
**********************************************************************
**********************************************************************
form f_format_table_html
using it_tab type any table
changing cv_html type string
.
data:
lt_fields type cl_abap_structdescr=>component_table,
lv_class_name type string
.
data:
lv_cell_val type string,
lv_row_val type string
.
field-symbols:
<lfs_field> like line of lt_fields,
<lfs_table_row> type any,
<lfs_data> type any,
<lfs_data_as_tab> type any table
.
lt_fields = cast cl_abap_structdescr(
cast cl_abap_tabledescr(
cl_abap_tabledescr=>describe_by_data(
it_tab
)
)->get_table_line_type( )
)->get_components(
).
cv_html = '<table border="1px">'.
loop at it_tab
assigning <lfs_table_row>.
lv_row_val = '<tr>'.
loop at lt_fields
assigning <lfs_field>.
assign component <lfs_field>-name
of structure <lfs_table_row>
to <lfs_data>
.
if <lfs_field>-name = 'DATA'.
assign <lfs_data>->* to <lfs_data_as_tab>.
perform f_format_table_html
using <lfs_data_as_tab>
changing lv_cell_val
.
lv_cell_val = |<details><summary>Table data</summary>|
&& |<p>{ lv_cell_val }</p></details>|.
else.
lv_cell_val = <lfs_data>.
endif.
lv_row_val = lv_row_val
&& |<td>{ lv_cell_val }</td>|.
endloop.
lv_row_val = |{ lv_row_val }</tr>|.
cv_html = cv_html
&& cl_abap_char_utilities=>newline
&& lv_row_val
.
endloop.
cv_html = |{ cv_html }</table>|.
* cl_demo_output=>display_html( cv_html ).
endform.
**********************************************************************
Комментариев нет:
Отправить комментарий