Dahili tablodan Excel(XLSX) dosyası oluşturma
Class : ZTR_EXCEL
Method : CREATE_XLS_FROM_ITAB
Parametreler
IT_FIELDCAT Importing Type LVC_T_FCAT
IT_SORT Importing Type LVC_T_SORT
IT_FILT Importing Type LVC_T_FILT
IS_LAYOUT Importing Type LVC_S_LAYO
I_XLSX Importing Type FLAG
CT_DATA Changing Type STANDARD TABLE
E_XSTRING Exporting Type XSTRING
Kullanımı
FORM f_send_mail_oop USING prm_depo type ty_depo .
data: lv_file_content type xstring.
DATA: lcl_ztr_excel TYPE REF TO ztr_excel.
CREATE OBJECT lcl_ztr_excel .
"call creation of xls
CALL METHOD lcl_ztr_excel->create_xls_from_itab
EXPORTING
it_fieldcat = gt_fieldcat_email
i_xlsx = `X`
IMPORTING
e_xstring = lv_file_content
CHANGING
ct_data = gt_master.
ENDFORM. " F_SEND_MAIL_OOP
method CREATE_XLS_FROM_ITAB.
data: mt_fcat type lvc_t_fcat.
data: mt_data type ref to data.
data: m_flavour type string.
data: m_version type string.
data: mo_result_data type ref to cl_salv_ex_result_data_table.
data: mo_columns type ref to cl_salv_columns_table.
data: mo_aggreg type ref to cl_salv_aggregations.
data: mo_salv_table type ref to cl_salv_table.
data: m_file_type type salv_bs_constant.
field-symbols
get reference of ct_data into mt_data.
*if we didn`t pass fieldcatalog we need to create it
if it_fieldcat[] is initial.
assign mt_data->* to
try .
cl_salv_table=>factory(
exporting
list_display = abap_false
importing
r_salv_table = mo_salv_table
changing
t_table =
catch cx_salv_msg.
endtry.
"get colums & aggregation infor to create fieldcat
mo_columns = mo_salv_table->get_columns( ).
mo_aggreg = mo_salv_table->get_aggregations( ).
mt_fcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
r_columns = mo_columns
r_aggregations = mo_aggreg ).
else.
*else we take the one we passed
mt_fcat[] = it_fieldcat[].
endif.
if cl_salv_bs_a_xml_base=>get_version( ) eq if_salv_bs_xml=>version_25 or
cl_salv_bs_a_xml_base=>get_version( ) eq if_salv_bs_xml=>version_26.
mo_result_data = cl_salv_ex_util=>factory_result_data_table(
r_data = mt_data
s_layout = is_layout
t_fieldcatalog = mt_fcat
t_sort = it_sort
t_filter = it_filt
).
case cl_salv_bs_a_xml_base=>get_version( ).
when if_salv_bs_xml=>version_25.
m_version = if_salv_bs_xml=>version_25.
when if_salv_bs_xml=>version_26.
m_version = if_salv_bs_xml=>version_26.
endcase.
"if we flag i_XLSX then we`ll create XLSX if not then MHTML excel file
if i_xlsx is not initial.
m_file_type = if_salv_bs_xml=>c_type_xlsx.
else.
m_file_type = if_salv_bs_xml=>c_type_mhtml.
endif.
m_flavour = if_salv_bs_c_tt=>c_tt_xml_flavour_export.
"transformation of data to excel
call method cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform
exporting
xml_type = m_file_type
xml_version = m_version
r_result_data = mo_result_data
xml_flavour = m_flavour
gui_type = if_salv_bs_xml=>c_gui_type_gui
importing
xml = e_xstring.
endif.
endmethod.