class ZCL_EXCEL_CONVERTER_SALV_TABLE definition
public
final
create public .
*"* public components of class ZCL_EXCEL_CONVERTER_SALV_TABLE
*"* do not include other source files here!!!
public section.
interfaces ZIF_EXCEL_CONVERTER .
aliases CAN_CONVERT_OBJECT
for ZIF_EXCEL_CONVERTER~CAN_CONVERT_OBJECT .
aliases CREATE_FIELDCATALOG
for ZIF_EXCEL_CONVERTER~CREATE_FIELDCATALOG .*"* protected components of class ZCL_EXCEL_CONVERTER_SALV_TABLE
*"* do not include other source files here!!!
protected section.*"* private components of class ZCL_EXCEL_CONVERTER_SALV_TABLE
*"* do not include other source files here!!!
private section.*"* local class implementation for public class
*"* use this source file for the implementation part of
*"* local helper classes*"* use this source file for any type declarations (class
*"* definitions, interfaces or data types) you need for method
*"* implementation or private method's signature*"* use this source file for any macro definitions you need
*"* in the implementation part of the classmethod ZIF_EXCEL_CONVERTER~CAN_CONVERT_OBJECT.
data: lo_salv type ref to cl_salv_table.
try.
lo_salv ?= io_object.
catch cx_sy_move_cast_error .
raise exception type zcx_excel.
endtry.
endmethod.method ZIF_EXCEL_CONVERTER~CREATE_FIELDCATALOG.
data: lo_salv type ref to cl_salv_table.
data: lo_columns type ref to cl_salv_columns_table,
lo_column type ref to cl_salv_column_table,
lo_aggregations type ref to cl_salv_aggregations,
lo_aggregation type ref to cl_salv_aggregation,
lo_sorts type ref to cl_salv_sorts,
lo_sort type ref to cl_salv_sort,
lo_display type ref to cl_salv_display_settings,
l_agre type salv_de_aggregation,
lt_column type salv_t_column_ref,
ls_column type salv_s_column_ref,
ls_fieldcatalog type zexcel_s_converter_fcat,
ls_ref type salv_s_ddic_reference,
l_alignment type salv_de_alignment,
l_fix type sap_bool,
l_optimized type sap_bool.
field-symbols: <fs_stable> type any.
try.
can_convert_object( io_object = io_object ).
endtry.
lo_salv ?= io_object.
clear: es_layout,
et_fieldcatalog.
if lo_salv is bound.
lo_columns = lo_salv->get_columns( ).
lt_column = lo_columns->get( ) .
lo_aggregations = lo_salv->get_aggregations( ) .
lo_display = lo_salv->get_display_settings( ) .
es_layout-is_stripped = lo_display->is_striped_pattern( ) .
l_optimized = lo_columns->is_optimized( ).
loop at lt_column into ls_column.
clear ls_fieldcatalog.
if ls_column-r_column->is_technical( ) = abap_false.
try.
lo_column ?= lo_columns->get_column( columnname = ls_column-columnname ).
catch cx_salv_not_found.
raise exception type zcx_excel.
endtry.
ls_ref = ls_column-r_column->get_ddic_reference( ).
ls_fieldcatalog-tabname = ls_ref-table.
ls_fieldcatalog-fieldname = ls_ref-field.
ls_fieldcatalog-columnname = ls_column-columnname.
try.
ls_fieldcatalog-position = lo_columns->get_column_position( columnname = ls_column-columnname ).
catch cx_salv_not_found.
raise exception type zcx_excel.
endtry.
ls_fieldcatalog-inttype = ls_column-r_column->get_ddic_inttype( ).
ls_fieldcatalog-scrtext_s = ls_column-r_column->get_short_text( ) .
ls_fieldcatalog-scrtext_m = ls_column-r_column->get_medium_text( ) .
ls_fieldcatalog-scrtext_l = ls_column-r_column->get_long_text( ).
try.
lo_aggregation = lo_aggregations->get_aggregation( columnname = ls_column-columnname ) .
catch cx_salv_not_found.
clear lo_aggregation.
endtry.
if lo_aggregation is bound.
l_agre = lo_aggregation->get( ).
case l_agre.
when if_salv_c_aggregation=>total. " Total
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_sum.
when if_salv_c_aggregation=>minimum. " Minimum
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_min.
when if_salv_c_aggregation=>maximum. " Maximum
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_max.
when if_salv_c_aggregation=>average. " Mean Value
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_average.
when others.
clear ls_fieldcatalog-totals_function.
endcase.
endif.
ls_fieldcatalog-is_visible = ls_column-r_column->is_visible( ).
ls_fieldcatalog-fix_column = lo_column->is_key( ).
l_fix = lo_column->is_key_presence_required( ).
if l_optimized = '1' or l_optimized = abap_true.
ls_fieldcatalog-is_optimized = abap_true.
else.
l_optimized = ls_column-r_column->is_optimized( ).
if l_optimized = '1' or l_optimized = abap_true.
ls_fieldcatalog-is_optimized = abap_true.
endif.
endif.
l_alignment = ls_column-r_column->get_alignment( ) .
case l_alignment.
when if_salv_c_alignment=>left. " Align left
ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_left.
when if_salv_c_alignment=>right. " Align right
ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_right.
when if_salv_c_alignment=>centered. " Centered
ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_center.
when others.
clear ls_fieldcatalog-alignment.
endcase.
append ls_fieldcatalog to et_fieldcatalog.
endif.
endloop.
if l_fix is not initial.
es_layout-is_fixed = abap_true.
endif.
endif.
endmethod.method ZIF_EXCEL_CONVERTER~CAN_CONVERT_OBJECT.
data: lo_salv type ref to cl_salv_table.
try.
lo_salv ?= io_object.
catch cx_sy_move_cast_error .
raise exception type zcx_excel.
endtry.
endmethod.method ZIF_EXCEL_CONVERTER~CREATE_FIELDCATALOG.
data: lo_salv type ref to cl_salv_table.
data: lo_columns type ref to cl_salv_columns_table,
lo_column type ref to cl_salv_column_table,
lo_aggregations type ref to cl_salv_aggregations,
lo_aggregation type ref to cl_salv_aggregation,
lo_sorts type ref to cl_salv_sorts,
lo_sort type ref to cl_salv_sort,
lo_display type ref to cl_salv_display_settings,
l_agre type salv_de_aggregation,
lt_column type salv_t_column_ref,
ls_column type salv_s_column_ref,
ls_fieldcatalog type zexcel_s_converter_fcat,
ls_ref type salv_s_ddic_reference,
l_alignment type salv_de_alignment,
l_fix type sap_bool,
l_optimized type sap_bool.
field-symbols: <fs_stable> type any.
try.
can_convert_object( io_object = io_object ).
endtry.
lo_salv ?= io_object.
clear: es_layout,
et_fieldcatalog.
if lo_salv is bound.
lo_columns = lo_salv->get_columns( ).
lt_column = lo_columns->get( ) .
lo_aggregations = lo_salv->get_aggregations( ) .
lo_display = lo_salv->get_display_settings( ) .
es_layout-is_stripped = lo_display->is_striped_pattern( ) .
l_optimized = lo_columns->is_optimized( ).
loop at lt_column into ls_column.
clear ls_fieldcatalog.
if ls_column-r_column->is_technical( ) = abap_false.
try.
lo_column ?= lo_columns->get_column( columnname = ls_column-columnname ).
catch cx_salv_not_found.
raise exception type zcx_excel.
endtry.
ls_ref = ls_column-r_column->get_ddic_reference( ).
ls_fieldcatalog-tabname = ls_ref-table.
ls_fieldcatalog-fieldname = ls_ref-field.
ls_fieldcatalog-columnname = ls_column-columnname.
try.
ls_fieldcatalog-position = lo_columns->get_column_position( columnname = ls_column-columnname ).
catch cx_salv_not_found.
raise exception type zcx_excel.
endtry.
ls_fieldcatalog-inttype = ls_column-r_column->get_ddic_inttype( ).
ls_fieldcatalog-scrtext_s = ls_column-r_column->get_short_text( ) .
ls_fieldcatalog-scrtext_m = ls_column-r_column->get_medium_text( ) .
ls_fieldcatalog-scrtext_l = ls_column-r_column->get_long_text( ).
try.
lo_aggregation = lo_aggregations->get_aggregation( columnname = ls_column-columnname ) .
catch cx_salv_not_found.
clear lo_aggregation.
endtry.
if lo_aggregation is bound.
l_agre = lo_aggregation->get( ).
case l_agre.
when if_salv_c_aggregation=>total. " Total
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_sum.
when if_salv_c_aggregation=>minimum. " Minimum
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_min.
when if_salv_c_aggregation=>maximum. " Maximum
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_max.
when if_salv_c_aggregation=>average. " Mean Value
ls_fieldcatalog-totals_function = zcl_excel_table=>totals_function_average.
when others.
clear ls_fieldcatalog-totals_function.
endcase.
endif.
ls_fieldcatalog-is_visible = ls_column-r_column->is_visible( ).
ls_fieldcatalog-fix_column = lo_column->is_key( ).
l_fix = lo_column->is_key_presence_required( ).
if l_optimized = '1' or l_optimized = abap_true.
ls_fieldcatalog-is_optimized = abap_true.
else.
l_optimized = ls_column-r_column->is_optimized( ).
if l_optimized = '1' or l_optimized = abap_true.
ls_fieldcatalog-is_optimized = abap_true.
endif.
endif.
l_alignment = ls_column-r_column->get_alignment( ) .
case l_alignment.
when if_salv_c_alignment=>left. " Align left
ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_left.
when if_salv_c_alignment=>right. " Align right
ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_right.
when if_salv_c_alignment=>centered. " Centered
ls_fieldcatalog-alignment = zcl_excel_style_alignment=>c_horizontal_center.
when others.
clear ls_fieldcatalog-alignment.
endcase.
append ls_fieldcatalog to et_fieldcatalog.
endif.
endloop.
if l_fix is not initial.
es_layout-is_fixed = abap_true.
endif.
endif.
endmethod.