*&---------------------------------------------------------------------*
*& Report Name : /EUTIN/SE16_LITE
*& Title : Internal only: SE16 Lite
*& Developer : EUTINM - 20190927
*& Development Class : /EUTIN/TOOLS
*& Description :
*& Display content of requested database table in various output forms.
*&
*& Source-URL:
*& https://blogs.sap.com/2019/04/24/generate-dynamic-excel-from-dynamic-internal-table/
*&
*&---------------------------------------------------------------------*
*&
*& Prerequisites:
*& ==============
*&
*& First create following four simple transformations using transaction
*& SE80, selecting a package in the navigation tree, click right mouse
*& button on the package and "Create" => "Other (1)" => "Transformation"
*&
*&---------------------------------------------------------------------*
*& 1. Transformation /EUTIN/EXCEL07_SHEET_XML
*&---------------------------------------------------------------------*
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*& 1
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*& 1
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*& 1
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&---------------------------------------------------------------------*
*& 2. Transformation /EUTIN/EXCEL07_SHRDSTRING_XML
*&---------------------------------------------------------------------*
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&---------------------------------------------------------------------*
*& 3. Transformation /EUTIN/EXCEL07_STYLESHEET_XML
*&---------------------------------------------------------------------*
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*& 1
*&
*&
*& 1
*&
*&
*& 1
*& 1
*&
*& 1
*&
*&
*& 0
*&
*&
*&
*&
*&
*& right
*&
*&
*&
*&
*&
*&
*&
*& top
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&---------------------------------------------------------------------*
*& 4. Transformation /EUTIN/EXCEL07_WORKBOOK_XML
*&---------------------------------------------------------------------*
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&
*&---------------------------------------------------------------------*
*& CHANGE HISTORY
*&---------------------------------------------------------------------*
*& Date Description
*&---------------------------------------------------------------------*
*&
*&
*&
*&
*&---------------------------------------------------------------------*
REPORT /eutin/se16_lite NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------
*--- Definition of local classes
*----------------------------------------------------------------------
*----------------------------------------------------------------------
*--- CLASS lcl_gen_table
*----------------------------------------------------------------------
CLASS lcl_gen_table DEFINITION FINAL.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PUBLIC SECTION.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TYPE-POOLS:
abap.
METHODS:
constructor
IMPORTING
iv_tabname TYPE dd02l-tabname
iv_where TYPE string,
get_table
EXPORTING
et_table TYPE STANDARD TABLE,
output.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PRIVATE SECTION.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DATA:
mr_structdescr TYPE REF TO cl_abap_structdescr,
mr_table TYPE REF TO data,
mt_fields TYPE ddfields.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDCLASS. "CLASS lcl_gen_table DEFINITION
CLASS lcl_gen_table IMPLEMENTATION.
*----------------------------------------------------------------------
*--- METHOD constructor
*----------------------------------------------------------------------
* This Methods determines the structure of the database table passed
* by IV_TABNAME as a RTTI-Descriptor (ME->GR_STRUCTDESCR) and stores a
* reference to the internal table passed (ME->GR_DATA).
*----------------------------------------------------------------------
METHOD constructor.
DATA:
lx_root TYPE REF TO cx_root,
lv_message TYPE string.
FIELD-SYMBOLS:
TYPE ANY TABLE.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TRY.
CREATE DATA mr_table TYPE STANDARD TABLE OF (iv_tabname).
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH CONSTRUCTOR #1: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
TRY.
ASSIGN mr_table->* TO .
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH CONSTRUCTOR #2: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
TRY.
IF iv_where IS INITIAL.
SELECT * FROM (iv_tabname) INTO TABLE .
ELSE.
SELECT * FROM (iv_tabname) INTO TABLE WHERE (iv_where).
ENDIF.
IF sy-subrc NE 0.
CLEAR .
RETURN.
ENDIF.
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH CONSTRUCTOR #3: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
TRY.
mr_structdescr ?= cl_abap_structdescr=>describe_by_name( iv_tabname ).
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH CONSTRUCTOR #4: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
TRY.
mr_structdescr->get_ddic_field_list( RECEIVING p_field_list = mt_fields
EXCEPTIONS not_found = 1
no_ddic_type = 2
OTHERS = 3 ).
IF sy-subrc NE 0.
MESSAGE e252(s#)
WITH 'METH CONSTRUCTOR #5:' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
'METH GET_DDIC_FIELD_LIST' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
'returned with error code' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
sy-subrc.
ENDIF.
IF mt_fields[] IS NOT INITIAL.
CLEAR mt_fields[].
ENDIF.
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH CONSTRUCTOR #6: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD. "METHOD constructor
*----------------------------------------------------------------------
*--- METHOD get_table
*----------------------------------------------------------------------
* Return filled output table
*----------------------------------------------------------------------
METHOD get_table.
DATA:
lx_root TYPE REF TO cx_root,
lv_message TYPE string.
FIELD-SYMBOLS:
TYPE STANDARD TABLE.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CLEAR et_table[].
TRY.
ASSIGN me->mr_table->* TO .
IF IS ASSIGNED.
et_table[] = .
ENDIF.
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH GET_TABLE #1: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD. "METHOD get_table
*----------------------------------------------------------------------
*--- METHOD output
*----------------------------------------------------------------------
* Write content of internal Table ME->GR_TABLE->* to standard list
* output.
*----------------------------------------------------------------------
METHOD output.
DATA:
lr_datadescr TYPE REF TO cl_abap_datadescr,
lx_root TYPE REF TO cx_root,
lv_new_row TYPE boolean,
lv_message TYPE string.
FIELD-SYMBOLS:
TYPE ANY TABLE,
TYPE LINE OF abap_compdescr_tab,
TYPE any,
TYPE any.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TRY.
ASSIGN me->mr_table->* TO .
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH OUTPUT #1: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
LOOP AT ASSIGNING .
TRY.
LOOP AT me->mr_structdescr->components ASSIGNING .
CASE sy-tabix.
WHEN 1.
MOVE abap_true TO lv_new_row.
WHEN OTHERS.
MOVE abap_false TO lv_new_row.
ENDCASE.
TRY.
lr_datadescr = me->mr_structdescr->get_component_type( -name ).
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH OUTPUT #2: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
TRY.
ASSIGN COMPONENT -name OF STRUCTURE TO CASTING TYPE HANDLE lr_datadescr.
IF sy-subrc EQ 0.
IF lv_new_row EQ abap_true.
WRITE: / .
ELSE.
WRITE: .
ENDIF.
ENDIF.
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH OUTPUT #3: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
ENDLOOP.
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH OUTPUT #4: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
ENDLOOP.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD. "METHOD output
ENDCLASS. "CLASS lcl_gen_table IMPLEMENTATION
*----------------------------------------------------------------------
*--- CLASS lcl_excel_adpater
*----------------------------------------------------------------------
CLASS lcl_excel_adpater DEFINITION FINAL.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PUBLIC SECTION.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TYPES:
BEGIN OF ts_mergelist,
to TYPE string,
from TYPE string,
END OF ts_mergelist,
* BEGIN OF ts_col_group,
* to TYPE string,
* from TYPE string,
* END OF ts_col_group,
BEGIN OF ts_drop_down_source,
sheet_name TYPE string,
col TYPE string,
row_from TYPE i,
row_to TYPE i,
END OF ts_drop_down_source,
BEGIN OF ts_drop_down_range,
col_from TYPE i,
col_to TYPE i,
row_from TYPE i,
row_to TYPE i,
END OF ts_drop_down_range,
BEGIN OF ts_error_msg,
header TYPE string,
text TYPE string,
END OF ts_error_msg,
BEGIN OF ts_drop_down_config,
source TYPE ts_drop_down_source,
range TYPE ts_drop_down_range,
restrict_values TYPE boolean,
error_text TYPE ts_error_msg,
END OF ts_drop_down_config,
* BEGIN OF ts_sheet_name,
* sheet_name TYPE string,
* END OF ts_sheet_name,
BEGIN OF ts_header_struc,
field_name TYPE string,
row_index TYPE i,
color_index TYPE i,
merge_col_cells TYPE i,
apply_filter TYPE boole_d,
fix_length TYPE boole_d,
unlocked TYPE boolean,
col_index TYPE i,
s_drop_down_config TYPE ts_drop_down_config,
END OF ts_header_struc,
BEGIN OF ts_col_row,
col_index TYPE i,
cell_data TYPE string,
editable TYPE boole_d,
color_index TYPE i,
END OF ts_col_row,
BEGIN OF ts_desc_row,
row_no TYPE i,
t_col TYPE STANDARD TABLE OF ts_col_row WITH KEY col_index INITIAL SIZE 1,
END OF ts_desc_row,
BEGIN OF ts_list_config_for_header ,
source TYPE ts_drop_down_source,
range TYPE ts_drop_down_range,
restict_values TYPE boolean,
error_text TYPE ts_error_msg,
END OF ts_list_config_for_header,
BEGIN OF ts_data_desc,
inttype TYPE inttype,
lock_col TYPE boole_d,
num_fmt TYPE string,
s_drop_down_config TYPE ts_drop_down_config,
style TYPE i,
alternate_style TYPE i,
lock_for_sheet TYPE boolean,
hidden TYPE boolean,
col_width TYPE i,
outline TYPE i,
exclude TYPE boolean,
col_pos TYPE i,
END OF ts_data_desc,
BEGIN OF ts_hyperlink_struct,
rel_id TYPE string,
cell_id TYPE string,
END OF ts_hyperlink_struct,
tt_mergelist TYPE STANDARD TABLE OF ts_mergelist WITH DEFAULT KEY,
* tt_col_group TYPE STANDARD TABLE OF ts_col_group WITH DEFAULT KEY,
* tt_sheet_name TYPE STANDARD TABLE OF ts_sheet_name WITH UNIQUE SORTED KEY sort_key COMPONENTS sheet_name INITIAL SIZE 1,
tt_header_table TYPE STANDARD TABLE OF ts_header_struc WITH DEFAULT KEY INITIAL SIZE 1,
tt_descr_table TYPE STANDARD TABLE OF ts_desc_row WITH KEY row_no INITIAL SIZE 1,
tt_list_config_for_header TYPE STANDARD TABLE OF ts_list_config_for_header WITH DEFAULT KEY,
tt_data_desc TYPE STANDARD TABLE OF ts_data_desc WITH DEFAULT KEY,
tt_hyperlink TYPE STANDARD TABLE OF ts_hyperlink_struct WITH NON-UNIQUE KEY cell_id INITIAL SIZE 1.
CONSTANTS:
co_state_hidden TYPE string VALUE 'hidden'. "pragma or pseudo comment NO_TEXT: Okay, technical value!
METHODS create_sheet
IMPORTING
!iv_sheet_name TYPE string OPTIONAL
!iv_state TYPE string OPTIONAL
!iv_disp_header TYPE boole_d DEFAULT abap_true
!iv_tech_header TYPE boole_d DEFAULT abap_true
!it_table_data TYPE STANDARD TABLE
!it_header TYPE tt_header_table OPTIONAL
!it_data_descr TYPE tt_data_desc OPTIONAL
!it_desc TYPE tt_descr_table OPTIONAL
!it_list_config_for_header TYPE tt_list_config_for_header OPTIONAL
!it_mergelist TYPE tt_mergelist OPTIONAL
!iv_alternate_count TYPE i OPTIONAL
!iv_lock_all_cells TYPE boolean DEFAULT abap_false
!iv_default_width TYPE i DEFAULT 15
!it_hyperlink TYPE tt_hyperlink OPTIONAL
!iv_protected TYPE boole_d DEFAULT abap_false
EXCEPTIONS
name_already_exist.
METHODS prepare_for_download
RETURNING
VALUE(rv_xlsx_xml) TYPE xstring
EXCEPTIONS
openxml_error.
METHODS download
IMPORTING
!iv_tab_name TYPE dd02l-tabname
!iv_excel_name TYPE string OPTIONAL
EXCEPTIONS
download_failed
download_cancelled.
* METHODS get_uploaded_sheet_names
* EXPORTING
* !et_sheets TYPE tt_sheet_name.
* METHODS update_sheet_data
* IMPORTING
* !iv_name TYPE string OPTIONAL
* !iv_xml TYPE xstring OPTIONAL
* !it_table_data TYPE STANDARD TABLE OPTIONAL
* EXPORTING
* !ev_xml TYPE xstring.
* METHODS fill_decimal_format
* IMPORTING
* !iv_dcpm TYPE usr01-dcpfm.
* METHODS get_excel_stream
* EXPORTING
* !ev_xml TYPE xstring.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PRIVATE SECTION.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TYPES:
BEGIN OF ts_drop_down_formula,
cells TYPE string,
formula TYPE string,
restrict TYPE boolean,
error_text TYPE ts_error_msg,
END OF ts_drop_down_formula,
BEGIN OF ts_sharedstring,
value TYPE string,
pos TYPE i,
END OF ts_sharedstring,
BEGIN OF ts_cell_struc,
position TYPE string,
cell TYPE string,
value TYPE string,
index TYPE i,
style TYPE i,
sharedstring TYPE string,
column_index TYPE i,
END OF ts_cell_struc,
BEGIN OF ts_hyperlink_struc,
rel_id TYPE string,
cell_id TYPE string,
END OF ts_hyperlink_struc,
BEGIN OF ts_ref_struc,
span TYPE string,
END OF ts_ref_struc,
BEGIN OF ts_merge_struc,
count TYPE i,
t_ref TYPE STANDARD TABLE OF ts_ref_struc WITH NON-UNIQUE KEY span INITIAL SIZE 1,
END OF ts_merge_struc,
BEGIN OF ts_col_struc,
min TYPE i,
max TYPE i,
bestfit TYPE i,
width TYPE i,
customwidth TYPE i,
style TYPE i,
hidden TYPE i,
outline TYPE i,
END OF ts_col_struc,
tt_drop_down_formula TYPE STANDARD TABLE OF ts_drop_down_formula WITH KEY cells,
tt_sharedstring TYPE HASHED TABLE OF ts_sharedstring WITH UNIQUE KEY value INITIAL SIZE 1,
* tt_shstr_upload TYPE STANDARD TABLE OF ts_sharedstring WITH KEY pos INITIAL SIZE 1,
tt_col_struc TYPE STANDARD TABLE OF ts_col_struc WITH NON-UNIQUE KEY min INITIAL SIZE 1.
TYPES:
BEGIN OF ts_sharedstring_struc,
t_strings TYPE tt_sharedstring,
string_count TYPE i,
string_ucount TYPE i,
END OF ts_sharedstring_struc,
* BEGIN OF ts_shstr_upload_struc,
* t_strings TYPE tt_shstr_upload,
* string_count TYPE i,
* string_ucount TYPE i,
* END OF ts_shstr_upload_struc,
BEGIN OF ts_row_struc,
spans TYPE string,
position TYPE i,
outlinelevel TYPE i,
hidden TYPE char1,
height TYPE i,
t_cells TYPE STANDARD TABLE OF ts_cell_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1,
END OF ts_row_struc.
TYPES:
BEGIN OF ts_sheet_struc,
dim TYPE string,
outlinelevel TYPE i,
summary_below TYPE string,
t_header TYPE STANDARD TABLE OF ts_row_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1,
t_desc TYPE STANDARD TABLE OF ts_row_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1,
t_rows TYPE STANDARD TABLE OF ts_row_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1,
t_cols TYPE STANDARD TABLE OF ts_col_struc WITH NON-UNIQUE KEY min INITIAL SIZE 1,
s_merge TYPE ts_merge_struc,
filter TYPE string,
t_hyperlinks TYPE STANDARD TABLE OF ts_hyperlink_struc WITH NON-UNIQUE KEY cell_id INITIAL SIZE 1,
drawing_id TYPE string,
dropdown_count TYPE i,
t_dropdown_formula TYPE tt_drop_down_formula,
protected TYPE boole_d,
END OF ts_sheet_struc.
TYPES:
BEGIN OF ts_sheets_struc,
name TYPE string,
sheetid TYPE i,
state TYPE string,
relid TYPE string,
sheet TYPE ts_sheet_struc,
END OF ts_sheets_struc,
BEGIN OF ts_style_numfmt,
id TYPE i,
code TYPE string,
END OF ts_style_numfmt,
BEGIN OF ts_style_cellxf,
index TYPE i,
numfmtid TYPE i,
fillid TYPE i,
borderid TYPE i,
is_string TYPE i,
indent TYPE i,
xfid TYPE i,
wrap TYPE i,
protectionid TYPE i,
fontid TYPE i,
key TYPE string,
END OF ts_style_cellxf,
BEGIN OF ts_style_struc,
t_numfmts TYPE STANDARD TABLE OF ts_style_numfmt WITH KEY id INITIAL SIZE 1,
t_cellxfs TYPE STANDARD TABLE OF ts_style_cellxf WITH KEY key indent xfid wrap INITIAL SIZE 1,
numfmts_count TYPE i,
cellxfs_count TYPE i,
END OF ts_style_struc,
BEGIN OF ts_meta_data,
sheetno TYPE i,
dscr_start TYPE i,
dscr_stop TYPE i,
header_start TYPE i,
header_stop TYPE i,
data_start TYPE i,
data_stop TYPE i,
END OF ts_meta_data,
tt_sheets TYPE STANDARD TABLE OF ts_sheets_struc WITH KEY name INITIAL SIZE 1,
tt_meta_data TYPE STANDARD TABLE OF ts_meta_data WITH KEY sheetno INITIAL SIZE 1,
tt_cells TYPE STANDARD TABLE OF ts_cell_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1.
CONSTANTS:
co_char TYPE char26 VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', "pragma or pseudo comment NO_TEXT: Okay, technical value!
co_sheet TYPE string VALUE 'Sheet', "pragma or pseudo comment NO_TEXT: Okay, technical value!
* co_workbook TYPE string VALUE 'sheets', "pragma or pseudo comment NO_TEXT: Okay, technical value!
* co_sheet_data TYPE string VALUE 'sheetData', "pragma or pseudo comment NO_TEXT: Okay, technical value!
* co_shared_string TYPE string VALUE 'sst', "pragma or pseudo comment NO_TEXT: Okay, technical value!
co_meta_data TYPE string VALUE '_meta_data'. "pragma or pseudo comment NO_TEXT: Okay, technical value!
DATA:
ms_style TYPE ts_style_struc,
ms_sharedstring TYPE ts_sharedstring_struc,
mt_sheets TYPE tt_sheets,
mt_meta_data TYPE tt_meta_data,
* mt_shdrstr_upload TYPE ts_shstr_upload_struc,
* mv_numfmt TYPE i VALUE 163,
mv_sheet_no TYPE i,
* mo_xlsx_doc TYPE REF TO cl_xlsx_document,
mv_alternate TYPE boolean,
mv_alternate_count TYPE i.
* mv_dcpfm TYPE usr01-dcpfm.
* METHODS get_cell_index
* IMPORTING
* !iv_cell TYPE string
* EXPORTING
* !ev_row TYPE i
* !ev_col TYPE i.
METHODS get_col_index
IMPORTING
!iv_col_index TYPE string
EXPORTING
!ev_col TYPE i.
METHODS get_width_for_cols
IMPORTING
!iv_width TYPE i DEFAULT 15
!it_header_table TYPE tt_header_table
!it_data_descr TYPE tt_data_desc OPTIONAL
EXPORTING
!et_col TYPE tt_col_struc.
* METHODS upload
* EXPORTING
* !ev_xlsx_xml TYPE xstring
* EXCEPTIONS
* file_upload_error
* user_cancel.
METHODS get_ss_position
IMPORTING
!iv_value TYPE data
RETURNING
VALUE(rv_index) TYPE i.
METHODS create_new_cell
IMPORTING
!iv_row TYPE i
!iv_col TYPE i
!iv_style TYPE i
!iv_value TYPE data OPTIONAL
!iv_is_string TYPE boole_d DEFAULT abap_false
CHANGING
!cs_cell TYPE ts_cell_struc.
METHODS get_cell_position
IMPORTING
!iv_row TYPE i
!iv_col TYPE i
RETURNING
VALUE(rv_position) TYPE string.
METHODS create_row
IMPORTING
!iv_row TYPE i
!iv_style TYPE i
!is_data TYPE data
!it_data_descr TYPE tt_data_desc OPTIONAL
!it_ddic_fld TYPE ddfields OPTIONAL
!iv_alternate_count TYPE i OPTIONAL
CHANGING
!ct_row TYPE tt_cells.
METHODS create_style_sheet.
METHODS create_header
IMPORTING
!iv_row TYPE i
!iv_ddic_struc TYPE boole_d DEFAULT abap_true
!it_header TYPE STANDARD TABLE
!iv_tech_header TYPE boole_d DEFAULT abap_true
EXPORTING
!ev_row TYPE i
CHANGING
!cs_sheet TYPE ts_sheet_struc.
METHODS create_description
IMPORTING
!iv_row TYPE i
!it_decs TYPE tt_descr_table
EXPORTING
!ev_row TYPE i
CHANGING
!cs_sheet TYPE ts_sheet_struc.
* METHODS get_data_from_xml
* IMPORTING
* !iv_xml TYPE xstring
* !iv_node TYPE string
* EXPORTING
* !et_data TYPE data.
METHODS prepare_drop_down_list
IMPORTING
!it_header TYPE tt_header_table OPTIONAL
!it_data_descr TYPE tt_data_desc
!it_list_config_for_header TYPE tt_list_config_for_header OPTIONAL
!iv_data_stop TYPE i
CHANGING
!cv_dropdown_count TYPE i
!ct_dropdown_formula TYPE tt_drop_down_formula.
* METHODS _is_num
* IMPORTING
* !iv_value TYPE string
* RETURNING
* VALUE(rv_num) TYPE boolean.
* METHODS get_col_label
* IMPORTING
* !iv_col TYPE i
* EXPORTING
* !ev_col TYPE string.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDCLASS. "CLASS lcl_excel_adpater DEFINITION
CLASS lcl_excel_adpater IMPLEMENTATION.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method CREATE_DESCRIPTION
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_ROW TYPE I
* | [--->] IT_DECS TYPE TT_DESCR_TABLE
* | [<---] EV_ROW TYPE I
* | [<-->] CS_SHEET TYPE TS_SHEET_STRUC
* +--------------------------------------------------------------------------------------
METHOD create_description.
DATA:
lv_col TYPE i,
lv_row TYPE i,
lv_span_i TYPE i,
lv_style TYPE i,
lv_span TYPE string,
ls_cell TYPE ts_cell_struc,
ls_rows TYPE ts_row_struc,
lt_cells TYPE STANDARD TABLE OF ts_cell_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1.
FIELD-SYMBOLS:
TYPE ts_desc_row,
TYPE ts_col_row.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lv_row = iv_row.
LOOP AT it_decs ASSIGNING .
ADD 1 TO lv_row.
lv_col = 1.
CLEAR: lv_span_i, ls_rows, lt_cells.
LOOP AT -t_col ASSIGNING .
IF -editable EQ abap_false.
IF -color_index EQ 1.
lv_style = 15.
ELSE.
lv_style = 1.
ENDIF.
ELSE.
IF -color_index EQ 1.
lv_style = 15.
ELSE.
lv_style = 2.
ENDIF.
ENDIF.
create_new_cell( EXPORTING iv_row = lv_row
iv_col = lv_col
iv_style = lv_style
iv_value = -cell_data
iv_is_string = abap_true
CHANGING cs_cell = ls_cell ).
INSERT ls_cell INTO TABLE lt_cells.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_DESCRIPTION #1: INSERT into LT_CELLS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ADD 1 TO lv_span_i.
ADD 1 TO lv_col.
ENDLOOP.
ls_rows-position = lv_row.
lv_span = lv_span_i.
CONCATENATE '1:' lv_span INTO ls_rows-spans.
ls_rows-t_cells = lt_cells.
INSERT ls_rows INTO TABLE cs_sheet-t_rows.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_DESCRIPTION #2: INSERT into CS_SHEET-T_ROWS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
ev_row = lv_row.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method CREATE_HEADER
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_ROW TYPE I
* | [--->] IV_DDIC_STRUC TYPE BOOLE_D (default =ABAP_TRUE)
* | [--->] IT_HEADER TYPE STANDARD TABLE
* | [--->] IV_TECH_HEADER TYPE BOOLE_D (default =ABAP_TRUE)
* | [<---] EV_ROW TYPE I
* | [<-->] CS_SHEET TYPE TS_SHEET_STRUC
* +--------------------------------------------------------------------------------------
METHOD create_header.
DATA:
lv_col TYPE i,
lv_row TYPE i,
lv_row_i TYPE i,
lv_span_i TYPE i,
lv_style TYPE i,
lv_span TYPE string,
lv_comp TYPE string,
ls_cell TYPE ts_cell_struc,
ls_rows TYPE ts_row_struc,
lt_cells TYPE STANDARD TABLE OF ts_cell_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1.
FIELD-SYMBOLS:
TYPE any,
TYPE any.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lv_row = iv_row.
IF iv_ddic_struc EQ abap_true.
CASE iv_tech_header.
WHEN abap_true.
lv_comp = 'FIELDNAME'.
WHEN OTHERS.
lv_comp = 'FIELDTEXT'. "'REPTEXT'
ENDCASE.
lv_style = 5.
ELSE.
lv_comp = 'FIELD_NAME'.
lv_style = 22.
ENDIF.
LOOP AT it_header ASSIGNING .
ADD 1 TO lv_col.
IF iv_ddic_struc NE abap_true.
ASSIGN COMPONENT 'ROW_INDEX' OF STRUCTURE TO .
IF IS ASSIGNED AND NE lv_row_i.
ls_rows-position = lv_row.
lv_span = lv_span_i.
CONCATENATE '1:' lv_span INTO ls_rows-spans.
ls_rows-t_cells = lt_cells.
INSERT ls_rows INTO TABLE cs_sheet-t_rows.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_HEADER #1: INSERT into CS_SHEET-T_ROWS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
CLEAR: lv_span_i, ls_rows, lt_cells.
ADD 1 TO lv_row.
lv_row_i = .
lv_col = 1.
ENDIF.
**--- decide style for the header based on the color index
* ASSIGN COMPONENT 'COLOR_INDEX' OF STRUCTURE TO . "pragma or pseudo comment NO_TEXT: Okay, technical value!
* ASSIGN COMPONENT 'UNLOCKED' OF STRUCTURE TO . "pragma or pseudo comment NO_TEXT: Okay, technical value!
* CASE .
* WHEN 1.
* IF EQ abap_false.
* lv_style = 22.
* ELSE.
* lv_style = 21.
* ENDIF.
* WHEN 2.
* IF EQ abap_false.
* lv_style = 4.
* ELSE.
* lv_style = 21.
* ENDIF.
* WHEN 3.
* IF EQ abap_false.
* lv_style = 9.
* ELSE.
* lv_style = 21.
* ENDIF.
* WHEN 4.
* IF EQ abap_false.
* lv_style = 11.
* ELSE.
* lv_style = 21.
* ENDIF.
* WHEN 5.
* IF EQ abap_false.
* lv_style = 13.
* ELSE.
* lv_style = 21.
* ENDIF.
* WHEN 6.
* IF EQ abap_false.
* lv_style = 7.
* ELSE.
* lv_style = 21.
* ENDIF.
* WHEN OTHERS.
* IF EQ abap_false.
* lv_style = 5.
* ELSE.
* lv_style = 21.
* ENDIF.
* ENDCASE.
ENDIF.
ASSIGN COMPONENT lv_comp OF STRUCTURE TO .
IF IS ASSIGNED.
create_new_cell( EXPORTING iv_row = lv_row
iv_col = lv_col
iv_style = lv_style
iv_value =
iv_is_string = abap_true
CHANGING cs_cell = ls_cell ).
ENDIF.
INSERT ls_cell INTO TABLE lt_cells.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_HEADER #2: INSERT into LT_CELLS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ADD 1 TO lv_span_i.
ENDLOOP.
ls_rows-position = lv_row.
lv_span = lv_span_i.
CONCATENATE '1:' lv_span INTO ls_rows-spans.
ls_rows-t_cells = lt_cells.
INSERT ls_rows INTO TABLE cs_sheet-t_rows.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_HEADER #3: INSERT into CS_SHEET-T_ROWS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ev_row = lv_row.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method CREATE_NEW_CELL
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_ROW TYPE I
* | [--->] IV_COL TYPE I
* | [--->] IV_STYLE TYPE I
* | [--->] IV_VALUE TYPE DATA(optional)
* | [--->] IV_IS_STRING TYPE BOOLE_D (default =ABAP_FALSE)
* | [<-->] CS_CELL TYPE TS_CELL_STRUC
* +--------------------------------------------------------------------------------------
METHOD create_new_cell.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cs_cell-position = get_cell_position( EXPORTING iv_row = iv_row
iv_col = iv_col ).
IF iv_is_string EQ abap_true.
cs_cell-index = get_ss_position( iv_value ).
cs_cell-sharedstring = 's'.
ELSE.
cs_cell-value = iv_value.
ENDIF.
cs_cell-style = iv_style.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method CREATE_ROW
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_ROW TYPE I
* | [--->] IV_STYLE TYPE I
* | [--->] IS_DATA TYPE DATA
* | [--->] IT_DATA_DESCR TYPE TT_DATA_DESC(optional)
* | [--->] IT_DDIC_FLD TYPE DDFIELDS(optional)
* | [--->] IV_ALTERNATE_COUNT TYPE I(optional)
* | [<-->] CT_ROW TYPE TT_CELLS
* +--------------------------------------------------------------------------------------
METHOD create_row.
DATA:
ls_cell LIKE LINE OF ct_row,
lv_col TYPE i,
lv_col_pos TYPE i,
lt_rows TYPE tt_cells.
FIELD-SYMBOLS:
TYPE any,
TYPE any,
TYPE c,
TYPE ts_data_desc.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IF mv_alternate = abap_false.
IF mv_alternate_count EQ 0.
mv_alternate = abap_true.
ENDIF.
ELSE.
IF mv_alternate_count EQ 0.
mv_alternate = abap_false.
ENDIF.
ENDIF.
IF iv_alternate_count NE 0.
ADD 1 TO mv_alternate_count.
mv_alternate_count = mv_alternate_count MOD iv_alternate_count.
ENDIF.
lv_col = 1.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE is_data TO .
IF sy-subrc NE 0.
EXIT.
ENDIF.
CLEAR ls_cell.
ls_cell-style = iv_style.
IF it_ddic_fld IS NOT INITIAL.
READ TABLE it_ddic_fld ASSIGNING INDEX sy-index.
IF IS ASSIGNED.
ASSIGN COMPONENT 'INTTYPE' OF STRUCTURE TO .
IF IS ASSIGNED AND EQ 'C'.
ls_cell-index = get_ss_position( iv_value = ).
ls_cell-sharedstring = 's'.
ENDIF.
ENDIF.
ELSEIF it_data_descr IS NOT INITIAL.
READ TABLE it_data_descr ASSIGNING INDEX sy-index.
IF sy-subrc IS INITIAL AND -inttype EQ 'C'.
ls_cell-index = get_ss_position( iv_value = ).
ls_cell-sharedstring = 's'.
ENDIF.
ENDIF.
CLEAR lv_col_pos.
READ TABLE it_data_descr ASSIGNING INDEX sy-index.
IF IS ASSIGNED.
IF -exclude EQ abap_true.
UNASSIGN .
CONTINUE.
ENDIF.
IF -lock_col EQ abap_true.
IF -style NE 0.
IF -alternate_style IS NOT INITIAL.
IF mv_alternate EQ abap_true.
ls_cell-style = -style.
ELSE.
ls_cell-style = -alternate_style.
ENDIF.
ENDIF.
ELSE.
ls_cell-style = 0.
ENDIF.
ENDIF.
* IF -inttype EQ cl_abap_typedescr=>typekind_int
* OR -inttype EQ cl_abap_typedescr=>typekind_int2
* OR -inttype EQ cl_abap_typedescr=>typekind_int8.
* ENDIF.
IF -col_pos IS NOT INITIAL.
lv_col_pos = -col_pos.
ENDIF.
UNASSIGN .
ENDIF.
IF ls_cell-index IS INITIAL.
ls_cell-value = .
ENDIF.
IF lv_col_pos IS NOT INITIAL.
ls_cell-position = get_cell_position(
iv_row = iv_row
iv_col = lv_col_pos ).
ls_cell-column_index = lv_col_pos.
INSERT ls_cell INTO TABLE lt_rows.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_ROW #1: INSERT into LT_ROWS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ELSE.
ls_cell-position = get_cell_position( iv_row = iv_row
iv_col = lv_col ).
INSERT ls_cell INTO TABLE ct_row.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_ROW #2: INSERT into CT_ROW failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDIF.
lv_col = lv_col + 1.
ENDDO.
IF lt_rows IS NOT INITIAL.
SORT lt_rows BY column_index ASCENDING.
APPEND LINES OF lt_rows TO ct_row.
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Public Method CREATE_SHEET
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_SHEET_NAME TYPE STRING(optional)
* | [--->] IV_STATE TYPE STRING(optional)
* | [--->] IV_DISP_HEADER TYPE BOOLE_D (default =ABAP_TRUE)
* | [--->] IV_TECH_HEADER TYPE BOOLE_D (default =ABAP_TRUE)
* | [--->] IT_TABLE_DATA TYPE STANDARD TABLE
* | [--->] IT_HEADER TYPE TT_HEADER_TABLE(optional)
* | [--->] IT_DATA_DESCR TYPE TT_DATA_DESC(optional)
* | [--->] IT_DESC TYPE TT_DESCR_TABLE(optional)
* | [--->] IT_LIST_CONFIG_FOR_HEADER TYPE TT_LIST_CONFIG_FOR_HEADER(optional)
* | [--->] IT_MERGELIST TYPE TT_MERGELIST(optional)
* | [--->] IV_ALTERNATE_COUNT TYPE I(optional)
* | [--->] IV_LOCK_ALL_CELLS TYPE BOOLEAN (default =ABAP_FALSE)
* | [--->] IV_DEFAULT_WIDTH TYPE I (default =15)
* | [--->] IT_HYPERLINK TYPE TT_HYPERLINK(optional)
* | [--->] IV_PROTECTED TYPE BOOLE_D (default =ABAP_FALSE)
* | [EXC!] NAME_ALREADY_EXIST
* +--------------------------------------------------------------------------------------
METHOD create_sheet.
DATA:
lv_row TYPE i,
lv_ddic TYPE boole_d,
ls_sheet TYPE ts_sheets_struc,
ls_mergespan TYPE ts_ref_struc,
lt_field_list TYPE ddfields,
lt_header TYPE tt_header_table,
lr_header TYPE REF TO ts_header_struc,
lr_typedescr TYPE REF TO cl_abap_typedescr,
lr_structdescr TYPE REF TO cl_abap_structdescr,
lt_comp TYPE abap_compdescr_tab,
ls_data_descr LIKE LINE OF it_data_descr,
ls_rows TYPE ts_row_struc,
lv_prev_index TYPE i VALUE -1,
lv_col_index TYPE i,
lt_cells TYPE STANDARD TABLE OF ts_cell_struc WITH NON-UNIQUE KEY position INITIAL SIZE 1,
lv_span_i TYPE i,
lv_span TYPE string,
lv_dimension TYPE i,
ls_meta_data TYPE ts_meta_data.
FIELD-SYMBOLS:
TYPE ts_col_struc,
TYPE any,
TYPE any,
TYPE ANY TABLE,
LIKE LINE OF lt_comp,
LIKE LINE OF lt_field_list,
LIKE LINE OF it_mergelist.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
READ TABLE it_table_data ASSIGNING INDEX 1.
IF IS ASSIGNED.
lr_typedescr = cl_abap_tabledescr=>describe_by_data( p_data = ).
MOVE lr_typedescr ?TO lr_structdescr.
lr_structdescr->get_ddic_field_list( EXPORTING p_langu = syst-langu
p_including_substructres = abap_false
RECEIVING p_field_list = lt_field_list[]
EXCEPTIONS not_found = 1
no_ddic_type = 2
OTHERS = 3 ).
IF sy-subrc NE 0 OR lt_field_list[] IS INITIAL.
lt_comp[] = lr_structdescr->components[].
LOOP AT lt_comp ASSIGNING .
INSERT INITIAL LINE INTO TABLE lt_field_list ASSIGNING .
IF sy-subrc NE 0 OR IS NOT ASSIGNED.
MESSAGE 'METH CREATE_SHEET #1: INSERT INITIAL LINE into LT_FIELD_LIST failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
-fieldname = -name.
-inttype = -type_kind.
ENDLOOP.
ENDIF.
ENDIF.
ADD 1 TO mv_sheet_no.
ls_sheet-sheetid = mv_sheet_no.
IF iv_sheet_name IS INITIAL.
ls_sheet-name = mv_sheet_no.
CONCATENATE co_sheet ls_sheet-name INTO ls_sheet-name.
ELSE.
READ TABLE mt_sheets TRANSPORTING NO FIELDS WITH KEY name = iv_sheet_name.
IF sy-subrc IS NOT INITIAL.
ls_sheet-name = iv_sheet_name.
ELSE.
RAISE name_already_exist.
ENDIF.
ENDIF.
ls_meta_data-sheetno = ls_sheet-sheetid.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE TO .
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
ADD 1 TO lv_span_i.
ENDDO.
get_width_for_cols( EXPORTING iv_width = iv_default_width
it_header_table = it_header
it_data_descr = it_data_descr
IMPORTING et_col = ls_sheet-sheet-t_cols ).
ls_sheet-sheet-t_hyperlinks = it_hyperlink.
lv_span = lv_span_i.
CONCATENATE '1:' lv_span INTO lv_span.
IF it_desc IS NOT INITIAL.
ls_meta_data-dscr_start = lv_row + 1.
create_description( EXPORTING iv_row = lv_row
it_decs = it_desc
IMPORTING ev_row = lv_row
CHANGING cs_sheet = ls_sheet-sheet ).
ls_meta_data-dscr_stop = lv_row.
ENDIF.
IF iv_disp_header EQ abap_true.
IF it_header IS INITIAL.
ASSIGN lt_field_list TO .
lv_ddic = abap_true.
ELSE.
lt_header = it_header.
SORT lt_header STABLE BY row_index.
ASSIGN lt_header TO .
lv_ddic = abap_false.
ENDIF.
ADD 1 TO lv_row.
ls_meta_data-header_start = lv_row.
create_header( EXPORTING iv_row = lv_row
iv_ddic_struc = lv_ddic
it_header =
iv_tech_header = iv_tech_header
IMPORTING ev_row = lv_row
CHANGING cs_sheet = ls_sheet-sheet ).
ls_meta_data-header_stop = lv_row.
ENDIF.
ls_meta_data-data_start = lv_row + 1.
LOOP AT it_table_data ASSIGNING .
ADD 1 TO lv_row.
CLEAR: ls_rows, lt_cells.
create_row( EXPORTING iv_row = lv_row
iv_style = 0
is_data =
it_data_descr = it_data_descr
it_ddic_fld = lt_field_list
iv_alternate_count = iv_alternate_count
CHANGING ct_row = lt_cells ).
ls_rows-position = lv_row.
ls_rows-spans = lv_span.
ls_rows-t_cells = lt_cells.
INSERT ls_rows INTO TABLE ls_sheet-sheet-t_rows.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_SHEET #2: INSERT into LS_SHEET-SHEET-T_ROWS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
ls_meta_data-data_stop = lv_row.
INSERT ls_meta_data INTO TABLE mt_meta_data.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_SHEET #3: INSERT into MT_META_DATA failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
DESCRIBE TABLE ls_sheet-sheet-t_rows LINES lv_dimension.
ls_sheet-sheet-dim = get_cell_position( iv_row = lv_dimension
iv_col = lv_span_i ).
CONCATENATE 'A1:' ls_sheet-sheet-dim INTO ls_sheet-sheet-dim.
ls_sheet-state = iv_state.
LOOP AT ls_sheet-sheet-t_cols ASSIGNING .
IF iv_lock_all_cells EQ abap_true.
-style = 18.
ENDIF.
READ TABLE it_data_descr INTO ls_data_descr INDEX sy-tabix.
IF sy-subrc EQ 0.
IF ls_data_descr-lock_for_sheet EQ abap_true.
-style = 22.
ENDIF.
IF ls_data_descr-hidden EQ abap_true.
-hidden = 1.
ELSE.
-hidden = 0.
ENDIF.
IF ls_data_descr-style IS NOT INITIAL.
-style = ls_data_descr-style.
ENDIF.
ENDIF.
IF ls_data_descr-outline EQ 1.
-outline = 0. "1.
ELSE.
-outline = 0.
ENDIF.
ENDLOOP.
LOOP AT lt_header REFERENCE INTO lr_header.
IF lv_prev_index NE lr_header->row_index.
lv_prev_index = lr_header->row_index.
lv_col_index = 1.
ELSE.
lv_col_index = lv_col_index + 1.
ENDIF.
lr_header->col_index = lv_col_index.
ENDLOOP.
prepare_drop_down_list( EXPORTING it_header = lt_header
it_data_descr = it_data_descr
it_list_config_for_header = it_list_config_for_header
iv_data_stop = ls_meta_data-data_stop
CHANGING cv_dropdown_count = ls_sheet-sheet-dropdown_count
ct_dropdown_formula = ls_sheet-sheet-t_dropdown_formula ).
CLEAR ls_sheet-sheet-s_merge.
DESCRIBE TABLE it_mergelist LINES ls_sheet-sheet-s_merge-count.
LOOP AT it_mergelist ASSIGNING .
CONCATENATE -from ':' -to INTO ls_mergespan-span.
INSERT ls_mergespan INTO TABLE ls_sheet-sheet-s_merge-t_ref.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_ROW #4: INSERT into LS_SHEET-SHEET-S_MERGE-T_REF failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
IF iv_protected EQ abap_true.
ls_sheet-sheet-protected = abap_true.
ENDIF.
INSERT ls_sheet INTO TABLE mt_sheets.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_SHEET #5: INSERT into MT_SHEETS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method CREATE_STYLE_SHEET
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------
METHOD create_style_sheet.
DATA:
ls_cell_fx TYPE ts_style_cellxf,
lt_cell_fx TYPE STANDARD TABLE OF ts_style_cellxf WITH KEY key indent xfid wrap INITIAL SIZE 1.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*--- style for columns unlock all cells---0
CLEAR ls_cell_fx.
ls_cell_fx-index = 0.
ls_cell_fx-wrap = 1.
ls_cell_fx-protectionid = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #1: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for description, locked----1
CLEAR ls_cell_fx.
ls_cell_fx-index = 1.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 5.
ls_cell_fx-borderid = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #2: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for description, unlocked----2
CLEAR ls_cell_fx.
ls_cell_fx-index = 2.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 5.
ls_cell_fx-borderid = 1.
ls_cell_fx-protectionid = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #3: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 1 without border----3
CLEAR ls_cell_fx.
ls_cell_fx-index = 3.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 6.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #4: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 1 with border----4
CLEAR ls_cell_fx.
ls_cell_fx-index = 4.
ls_cell_fx-numfmtid = 49.
ls_cell_fx-wrap = 1.
ls_cell_fx-borderid = 1.
ls_cell_fx-fillid = 6.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #5: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 2----5
CLEAR ls_cell_fx.
ls_cell_fx-index = 5.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 2.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #6: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 2 without boarder----6
CLEAR ls_cell_fx.
ls_cell_fx-index = 6.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 2.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #7: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for data, unlocked cell----7
CLEAR ls_cell_fx.
ls_cell_fx-index = 7.
ls_cell_fx-wrap = 1.
ls_cell_fx-borderid = 1.
ls_cell_fx-protectionid = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #8: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for data, locked cell----8
CLEAR ls_cell_fx.
ls_cell_fx-index = 8.
ls_cell_fx-numfmtid = 49.
ls_cell_fx-wrap = 0.
ls_cell_fx-protectionid = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #9: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 3----9
CLEAR ls_cell_fx.
ls_cell_fx-index = 9.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 8.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #10: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 3 without boarder----10
CLEAR ls_cell_fx.
ls_cell_fx-index = 10.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 8.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #11: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 4 ------------11
CLEAR ls_cell_fx.
ls_cell_fx-index = 11.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 7.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #12: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 4 without boarder----12
CLEAR ls_cell_fx.
ls_cell_fx-index = 12.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 7.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #13: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 5 ------------13
CLEAR ls_cell_fx.
ls_cell_fx-index = 13.
ls_cell_fx-xfid = 2.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 9.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #14: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for header, color 5 without boarder----14
CLEAR ls_cell_fx.
ls_cell_fx-index = 14.
ls_cell_fx-xfid = 2.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 9.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #15: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style for description - 15
CLEAR ls_cell_fx.
ls_cell_fx-index = 15.
ls_cell_fx-xfid = 3.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 10.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #16: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style - 16
CLEAR ls_cell_fx.
ls_cell_fx-index = 16.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 11.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #17: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style - 17 :white locked background
CLEAR ls_cell_fx.
ls_cell_fx-index = 17.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 12.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #18: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style - 18
CLEAR ls_cell_fx.
ls_cell_fx-index = 18.
ls_cell_fx-wrap = 1.
ls_cell_fx-protectionid = 0.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #19: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style - 19
CLEAR ls_cell_fx.
ls_cell_fx-index = 19.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 13.
ls_cell_fx-borderid = 1.
ls_cell_fx-protectionid = 0.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #20: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style - 20
CLEAR ls_cell_fx.
ls_cell_fx-index = 20.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 14.
ls_cell_fx-borderid = 1.
ls_cell_fx-protectionid = 0.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #21: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style - 21 :white unlocked background
CLEAR ls_cell_fx.
ls_cell_fx-index = 21.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 12.
ls_cell_fx-borderid = 1.
ls_cell_fx-protectionid = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #22: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style 22 for header, color 1 with border----3
CLEAR ls_cell_fx.
ls_cell_fx-index = 22.
* ls_cell_fx-wrap = 0.
ls_cell_fx-fillid = 0.
ls_cell_fx-borderid = 1.
ls_cell_fx-fontid = 2.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #23: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style 23 for header, color 1 with border----3
CLEAR ls_cell_fx.
ls_cell_fx-index = 15.
ls_cell_fx-xfid = 1.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 10.
ls_cell_fx-borderid = 1.
ls_cell_fx-is_string = 1.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #24: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
*--- style 24 for header, color 1 with border----3
CLEAR ls_cell_fx.
ls_cell_fx-index = 24.
ls_cell_fx-numfmtid = 49.
ls_cell_fx-wrap = 1.
ls_cell_fx-fillid = 13.
ls_cell_fx-borderid = 1.
ls_cell_fx-protectionid = 0.
INSERT ls_cell_fx INTO TABLE lt_cell_fx.
IF sy-subrc NE 0.
MESSAGE 'METH CREATE_STYLE_SHEET #25: INSERT into LT_CELL_FX failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ms_style-cellxfs_count = ls_cell_fx-index + 1.
ms_style-t_cellxfs = lt_cell_fx.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Public Method DOWNLOAD
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_TAB_NAME TYPE DD02L-TABNAME
* | [--->] IV_EXCEL_NAME TYPE STRING(optional)
* | [EXC!] DOWNLOAD_FAILED
* | [EXC!] DOWNLOAD_CANCELLED
* +--------------------------------------------------------------------------------------
METHOD download.
DATA:
lv_length TYPE i,
lv_title TYPE string,
lv_filename TYPE string,
lv_xml_stream TYPE xml_rawdata,
lv_loc_fn TYPE string,
lv_loc_dir TYPE string,
lv_user_action TYPE i,
lv_xml TYPE xstring,
lv_excel_name TYPE string.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IF iv_excel_name IS SUPPLIED.
lv_excel_name = iv_excel_name.
ELSE.
CONCATENATE sy-sysid sy-mandt iv_tab_name sy-datum sy-uzeit
INTO lv_excel_name SEPARATED BY '_'.
CONCATENATE lv_excel_name '.xlsx' "pragma or pseudo comment NO_TEXT: Okay, technical value!
INTO lv_excel_name.
ENDIF.
lv_title = 'Export to Micro$oft Excel 2007 and higher'. "pragma or pseudo comment NO_TEXT: Okay, technical value!
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = lv_title
default_extension = 'xlsx' "pragma or pseudo comment NO_TEXT: Okay, technical value!
default_file_name = lv_excel_name
file_filter = 'Excel (*.xlsx)|*.xlsx|' "pragma or pseudo comment NO_TEXT: Okay, technical value!
CHANGING
filename = lv_loc_fn
path = lv_loc_dir
fullpath = lv_loc_dir
user_action = lv_user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE i252(s#) DISPLAY LIKE 'E'
WITH 'METH DOWNLOAD #1:' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
'METH FILE_SAVE_DIALOG' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
'returned with error code' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
sy-subrc.
RAISE download_failed.
ENDIF.
IF lv_user_action EQ cl_gui_frontend_services=>action_cancel.
MESSAGE 'Canceled by user' TYPE 'I'. "pragma or pseudo comment NO_TEXT: Okay, technical message!
RAISE download_cancelled.
ENDIF.
CONCATENATE lv_loc_dir lv_loc_fn INTO lv_filename.
lv_xml = prepare_for_download( ).
IF NOT lv_filename IS INITIAL.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xml
IMPORTING
output_length = lv_length
TABLES
binary_tab = lv_xml_stream.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lv_length
filetype = 'BIN' "pragma or pseudo comment NO_TEXT: Okay, technical value!
filename = lv_filename
CHANGING
data_tab = lv_xml_stream
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
IF sy-subrc NE 0.
MESSAGE i252(s#) DISPLAY LIKE 'E'
WITH 'METH DOWNLOAD #2:' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
'METH GUI_DOWNLOAD' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
'returned with error code' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
sy-subrc.
RAISE download_failed.
ENDIF.
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Public Method FILL_DECIMAL_FORMAT
** +-------------------------------------------------------------------------------------------------+
** | [--->] IV_DCPM TYPE USR01-DCPFM
** +--------------------------------------------------------------------------------------
* METHOD fill_decimal_format.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* "Fill the decimal format from user settings.
* mv_dcpfm = iv_dcpm.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Private Method GET_CELL_INDEX
** +-------------------------------------------------------------------------------------------------+
** | [--->] IV_CELL TYPE STRING
** | [<---] EV_ROW TYPE I
** | [<---] EV_COL TYPE I
** +--------------------------------------------------------------------------------------
* METHOD get_cell_index.
*
* DATA:
* lv_tabix_cell_index TYPE i,
* lv_diff TYPE i,
* lv_char TYPE char1,
* lv_len TYPE i,
* lv_col_index TYPE string.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* lv_len = strlen( iv_cell ).
* WHILE lv_char CO co_char OR lv_char IS INITIAL.
* lv_tabix_cell_index = lv_tabix_cell_index + 1.
* lv_char = iv_cell+lv_tabix_cell_index(1).
* ENDWHILE.
* lv_diff = lv_len - lv_tabix_cell_index.
* lv_col_index = iv_cell(lv_tabix_cell_index).
* ev_row = iv_cell+lv_tabix_cell_index(lv_diff).
* IF ev_col IS REQUESTED.
* CALL METHOD get_col_index
* EXPORTING
* iv_col_index = lv_col_index
* IMPORTING
* ev_col = ev_col.
* ENDIF.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method GET_CELL_POSITION
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_ROW TYPE I
* | [--->] IV_COL TYPE I
* | [<-()] RV_POSITION TYPE STRING
* +--------------------------------------------------------------------------------------
METHOD get_cell_position.
DATA:
l_part1 TYPE string,
l_part2 TYPE string,
l_part3 TYPE string,
l_mod TYPE i,
l_div TYPE i.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
l_mod = ( iv_col - 1 ) MOD 26.
l_div = ( iv_col - 1 ) DIV 26.
l_part1 = co_char+l_mod(1).
l_part3 = |{ iv_row }|.
IF l_div > 0.
l_div = l_div - 1.
l_part2 = co_char+l_div(1).
CONCATENATE l_part2 l_part1 l_part3 INTO rv_position.
ELSE.
CONCATENATE l_part1 l_part3 INTO rv_position.
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method GET_COL_INDEX
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_COL_INDEX TYPE STRING
* | [<---] EV_COL TYPE I
* +--------------------------------------------------------------------------------------
METHOD get_col_index.
DATA:
lv_char TYPE char1,
lv_len TYPE i,
lv_exp TYPE i,
lv_len_minus_1 TYPE i,
lv_partial_index1 TYPE i,
lv_partial_index2 TYPE i,
lv_number TYPE i,
result_tab TYPE match_result_tab,
lv_col_index_substr TYPE string.
FIELD-SYMBOLS:
LIKE LINE OF result_tab.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
lv_len = strlen( iv_col_index ).
lv_char = iv_col_index(1).
FIND FIRST OCCURRENCE OF lv_char IN co_char RESULTS result_tab.
READ TABLE result_tab ASSIGNING INDEX 1.
lv_number = -offset.
lv_number = lv_number + 1.
IF lv_len EQ 1.
* ev_col = ( ( 26 ** ( lv_len - 1 ) ) * lv_number ).
lv_exp = lv_len - 1.
ev_col = ( ipow( base = 26 exp = lv_exp ) * lv_number ).
ELSE.
lv_len_minus_1 = lv_len - 1.
lv_col_index_substr = iv_col_index+1(lv_len_minus_1).
CALL METHOD get_col_index
EXPORTING
iv_col_index = lv_col_index_substr
IMPORTING
ev_col = lv_partial_index2.
* lv_partial_index1 = ( ( 26 ** ( lv_len - 1 ) ) * lv_number ) + lv_partial_index2.
lv_exp = lv_len - 1.
lv_partial_index1 = ( ipow( base = 26 exp = lv_exp ) * lv_number ) + lv_partial_index2.
ev_col = lv_partial_index1.
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Private Method GET_COL_LABEL
** +-------------------------------------------------------------------------------------------------+
** | [--->] IV_COL TYPE I
** | [<---] EV_COL TYPE STRING
** +--------------------------------------------------------------------------------------
* METHOD get_col_label.
*
* CONSTANTS:
* lv_alp TYPE string VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
*
* DATA:
* lv_col TYPE i,
* lv_max TYPE i,
* lv_res TYPE p DECIMALS 5,
* lv_rem TYPE i,
* lv_l TYPE c LENGTH 1,
* lv_str TYPE string.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* lv_col = lv_max = iv_col.
* DO.
* lv_res = lv_col / 26.
* lv_rem = lv_col MOD 26.
* lv_res = floor( lv_res ).
* IF lv_rem EQ 0.
* CONCATENATE 'Z' lv_str INTO lv_str.
* ELSE.
* lv_l = substring( val = lv_alp off = lv_rem - 1 len = 1 ).
* CONCATENATE lv_l lv_str INTO lv_str.
* ENDIF.
* IF lv_res EQ 0 OR lv_max LE 26.
* EXIT.
* ENDIF.
* lv_col = lv_res.
* ENDDO.
* ev_col = lv_str.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Private Method GET_DATA_FROM_XML
** +-------------------------------------------------------------------------------------------------+
** | [--->] IV_XML TYPE XSTRING
** | [--->] IV_NODE TYPE STRING
** | [<---] ET_DATA TYPE DATA
** +--------------------------------------------------------------------------------------
* METHOD get_data_from_xml.
*
* DATA:
* lo_ixml_factory TYPE REF TO if_ixml,
* lo_stream_factory TYPE REF TO if_ixml_stream_factory,
* lo_istream TYPE REF TO if_ixml_istream,
* lo_idocument TYPE REF TO if_ixml_document,
* lo_iparser TYPE REF TO if_ixml_parser,
* lo_node_collection TYPE REF TO if_ixml_node_collection,
* lo_node_iterator TYPE REF TO if_ixml_node_iterator,
* lo_node TYPE REF TO if_ixml_node,
* lo_attr TYPE REF TO if_ixml_named_node_map,
* lv_no_of_entries TYPE i,
* lr_subnode TYPE REF TO if_ixml_node,
* lr_attr_node TYPE REF TO if_ixml_node,
* lr_node_list TYPE REF TO if_ixml_node_list,
* lr_node_list_iterator TYPE REF TO if_ixml_node_iterator,
* lv_no_of_col TYPE i,
* lr_col_node TYPE REF TO if_ixml_node,
* lr_col_list TYPE REF TO if_ixml_node_list,
* lr_col_list_iterator TYPE REF TO if_ixml_node_iterator,
* lr_cx_sy_con_no_number TYPE REF TO cx_sy_conversion_no_number,
* lv_message TYPE string,
* ls_sheet TYPE ts_sheets_struc,
* lt_row TYPE STANDARD TABLE OF ts_row_struc INITIAL SIZE 1,
* lt_cell TYPE STANDARD TABLE OF ts_cell_struc INITIAL SIZE 1.
*
* FIELD-SYMBOLS:
* TYPE ts_row_struc,
* TYPE ts_cell_struc.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* lo_ixml_factory = cl_ixml=>create( ).
* lo_stream_factory = lo_ixml_factory->create_stream_factory( ).
* lo_istream = lo_stream_factory->create_istream_xstring( iv_xml ).
* lo_idocument = lo_ixml_factory->create_document( ).
* lo_iparser = lo_ixml_factory->create_parser( stream_factory = lo_stream_factory
* istream = lo_istream
* document = lo_idocument ).
* lo_iparser->parse( ).
* lo_node_collection = lo_idocument->get_elements_by_tag_name( name = iv_node ).
* lo_node_iterator = lo_node_collection->create_iterator( ).
* lo_node = lo_node_iterator->get_next( ).
* lr_node_list = lo_node->get_children( ).
* lv_no_of_entries = lr_node_list->get_length( ).
* lr_node_list_iterator = lr_node_list->create_iterator( ).
* DO lv_no_of_entries TIMES.
* CASE iv_node.
* WHEN co_sheet_data.
* lr_subnode = lr_node_list_iterator->get_next( ).
* lr_col_list = lr_subnode->get_children( ).
* lv_no_of_col = lr_col_list->get_length( ).
* lr_col_list_iterator = lr_col_list->create_iterator( ).
* INSERT INITIAL LINE INTO TABLE lt_row ASSIGNING .
* IF sy-subrc NE 0 OR IS NOT ASSIGNED.
* MESSAGE 'METH GET_DATA_FROM_XML #1: INSERT INITIAL LINE into LT_ROW failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDIF.
* -position = sy-index.
* CLEAR lt_cell.
* DO lv_no_of_col TIMES.
* lr_col_node = lr_col_list_iterator->get_next( ).
* lo_attr = lr_col_node->get_attributes( ).
* INSERT INITIAL LINE INTO TABLE lt_cell ASSIGNING .
* IF sy-subrc NE 0 OR IS NOT ASSIGNED.
* MESSAGE 'METH GET_DATA_FROM_XML #2: INSERT INITIAL LINE into LT_CELL failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDIF.
* lr_attr_node = lo_attr->get_named_item( name = 't' ).
* IF lr_attr_node IS INITIAL.
* -value = lr_col_node->get_value( ).
* ELSE.
* TRY.
* -index = lr_col_node->get_value( ) + 1.
* CLEAR lr_attr_node.
* CATCH cx_sy_conversion_no_number INTO lr_cx_sy_con_no_number. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
* lv_message = lr_cx_sy_con_no_number->if_message~get_text( ).
**--- error tolerant mode: do not cause catchable runtime errors!
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH CONSTRUCTOR #1: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDTRY.
* ENDIF.
* lr_attr_node = lo_attr->get_named_item( name = 'r' ).
* -cell = lr_attr_node->get_value( ).
* ENDDO.
* -t_cells = lt_cell.
** WHEN co_shared_string.
** lr_subnode = lr_node_list_iterator->get_next( ).
** ls_sh_str-value = lr_subnode->get_value( ).
** ls_sh_str-pos = sy-index.
** INSERT ls_sh_str INTO TABLE mt_shdrstr_upload-t_strings.
** IF sy-subrc NE 0.
** MESSAGE 'METH GET_DATA_FROM_XML #3: INSERT into MT_SHDRSTR_UPLOAD-T_STRINGS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
** ENDIF.
* WHEN co_workbook.
* lr_subnode = lr_node_list_iterator->get_next( ).
* lo_attr = lr_subnode->get_attributes( ).
* lr_attr_node = lo_attr->get_named_item( name = 'name' ). "pragma or pseudo comment NO_TEXT: Okay, technical value!
* ls_sheet-name = lr_attr_node->get_value( ).
* lr_attr_node = lo_attr->get_named_item( name = 'sheetId' ). "pragma or pseudo comment NO_TEXT: Okay, technical value!
* ls_sheet-sheetid = lr_attr_node->get_value( ).
* lr_attr_node = lo_attr->get_named_item( name = 'id' namespace = 'r' ). "pragma or pseudo comment NO_TEXT: Okay, technical value!
* ls_sheet-relid = lr_attr_node->get_value( ).
* INSERT ls_sheet INTO TABLE mt_sheets.
* IF sy-subrc NE 0.
* MESSAGE 'METH GET_DATA_FROM_XML #4: INSERT into MT_SHEETS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDIF.
* ENDCASE.
* ENDDO.
* IF lt_row IS NOT INITIAL.
* et_data = lt_row.
* ENDIF.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Public Method GET_EXCEL_STREAM
** +-------------------------------------------------------------------------------------------------+
** | [<---] EV_XML TYPE XSTRING
** +--------------------------------------------------------------------------------------
* METHOD get_excel_stream.
*
* DATA:
* lr_cx_openxml_format TYPE REF TO cx_openxml_format,
* lr_cx_openxml_not_found TYPE REF TO cx_openxml_not_found,
* lr_cx_openxml_not_allowed TYPE REF TO cx_openxml_not_allowed,
* lr_cx_root TYPE REF TO cx_root,
* lv_message TYPE string.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* TRY.
* ev_xml = mo_xlsx_doc->get_package_data( ).
* CATCH cx_openxml_format INTO lr_cx_openxml_format.
* lv_message = lr_cx_openxml_format->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH GET_EXCEL_STREAM #1: Exception CX_OPENXML_FORMAT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* CATCH cx_openxml_not_found INTO lr_cx_openxml_not_found.
* lv_message = lr_cx_openxml_not_found->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH GET_EXCEL_STREAM #2: Exception CX_OPENXML_NOT_FOUND was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* CATCH cx_openxml_not_allowed INTO lr_cx_openxml_not_allowed.
* lv_message = lr_cx_openxml_not_allowed->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH GET_EXCEL_STREAM #3: Exception CX_OPENXML_NOT_ALLOWED was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* CATCH cx_root INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
**--- error tolerant mode: do not cause catchable runtime errors!
* lv_message = lr_cx_root->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH GET_EXCEL_STREAM #4: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDTRY.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method GET_SS_POSITION
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_VALUE TYPE DATA
* | [<-()] RV_INDEX TYPE I
* +--------------------------------------------------------------------------------------
METHOD get_ss_position.
DATA:
ls_sh_str TYPE ts_sharedstring.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
READ TABLE ms_sharedstring-t_strings INTO ls_sh_str WITH TABLE KEY value = iv_value.
IF sy-subrc IS NOT INITIAL.
ADD 1 TO ms_sharedstring-string_ucount.
ls_sh_str-value = iv_value.
ls_sh_str-pos = ms_sharedstring-string_ucount.
INSERT ls_sh_str INTO TABLE ms_sharedstring-t_strings.
IF sy-subrc NE 0.
MESSAGE 'METH GET_SS_POSITION #1: INSERT into MT_SHAREDSTRING-T_STRINGS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDIF.
ADD 1 TO ms_sharedstring-string_count.
rv_index = ls_sh_str-pos - 1.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Public Method GET_UPLOADED_SHEET_NAMES
** +-------------------------------------------------------------------------------------------------+
** | [<---] ET_SHEETS TYPE TT_SHEET_NAME
** +--------------------------------------------------------------------------------------
* METHOD get_uploaded_sheet_names.
*
* FIELD-SYMBOLS:
* TYPE ts_sheets_struc,
* TYPE ts_sheet_name.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* LOOP AT mt_sheets ASSIGNING WHERE name NE co_meta_data.
* INSERT INITIAL LINE INTO TABLE et_sheets ASSIGNING .
* IF sy-subrc NE 0 OR IS NOT ASSIGNED.
* MESSAGE 'METH GET_UPLOADED_SHEET_NAMES #1: INSERT INITIAL LINE into ET_SHEETS failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDIF.
* -sheet_name = -name.
* ENDLOOP.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method GET_WIDTH_FOR_COLS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_WIDTH TYPE I (default =15)
* | [--->] IT_HEADER_TABLE TYPE TT_HEADER_TABLE
* | [--->] IT_DATA_DESCR TYPE TT_DATA_DESC(optional)
* | [<---] ET_COL TYPE TT_COL_STRUC
* +--------------------------------------------------------------------------------------
METHOD get_width_for_cols.
TYPES:
BEGIN OF ts_col_length,
length TYPE int4,
fix_length TYPE boole_d,
END OF ts_col_length,
tt_col_length TYPE STANDARD TABLE OF ts_col_length WITH DEFAULT KEY.
DATA:
ls_col LIKE LINE OF et_col,
lv_counter TYPE i,
lt_col_length TYPE tt_col_length,
ls_col_length TYPE ts_col_length,
lv_header_len TYPE i,
lv_lines_prev TYPE i,
lv_lines_next TYPE i,
lv_len_prev TYPE i,
lv_len_next TYPE i,
lv_len_max TYPE i,
lv_lines_max TYPE i,
lv_col_index TYPE i,
lv_last_index TYPE i,
lt_header_prev TYPE tt_header_table,
ls_header_prev LIKE LINE OF lt_header_prev,
lt_header_next TYPE tt_header_table,
ls_header_next LIKE LINE OF lt_header_next,
ls_data_descr LIKE LINE OF it_data_descr.
FIELD-SYMBOLS:
LIKE LINE OF lt_col_length,
LIKE LINE OF it_header_table.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DESCRIBE TABLE it_header_table LINES lv_header_len.
READ TABLE it_header_table ASSIGNING INDEX 1.
IF sy-subrc EQ 0.
lv_col_index = -row_index.
UNASSIGN .
ENDIF.
READ TABLE it_header_table ASSIGNING INDEX lv_header_len.
IF sy-subrc EQ 0.
lv_last_index = -row_index.
UNASSIGN .
ENDIF.
IF it_header_table IS INITIAL.
ls_col-customwidth = 1.
ls_col-bestfit = 1.
ls_col-width = iv_width.
ls_col-min = 1.
ls_col-max = 16384.
ls_col-style = 0.
INSERT ls_col INTO TABLE et_col.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #1: INSERT into ET_COL failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
RETURN.
ENDIF.
WHILE lt_header_prev IS INITIAL.
LOOP AT it_header_table ASSIGNING
WHERE row_index EQ lv_col_index.
INSERT INTO TABLE lt_header_prev.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #2: INSERT into LT_HEADER_PREV failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
ENDWHILE.
IF lv_col_index EQ lv_last_index.
DESCRIBE TABLE lt_header_prev LINES lv_lines_prev.
DO lv_lines_prev TIMES.
ADD 1 TO lv_counter.
READ TABLE lt_header_prev INDEX lv_counter INTO ls_header_prev.
IF sy-subrc EQ 0.
READ TABLE it_header_table ASSIGNING INDEX lv_counter.
IF sy-subrc EQ 0.
ls_col_length-fix_length = -fix_length.
UNASSIGN .
ENDIF.
READ TABLE it_data_descr INTO ls_data_descr INDEX lv_counter.
IF sy-subrc EQ 0.
IF ls_data_descr-col_width IS NOT INITIAL.
lv_len_prev = ls_data_descr-col_width.
ELSE.
lv_len_prev = strlen( ls_header_prev-field_name ).
ENDIF.
ENDIF.
ls_col_length-length = lv_len_prev.
INSERT ls_col_length INTO TABLE lt_col_length.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #3: INSERT into LT_COL_LENGTH failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDIF.
ENDDO.
ENDIF.
WHILE lv_col_index LT lv_last_index.
ADD 1 TO lv_col_index.
WHILE lt_header_next IS INITIAL.
LOOP AT it_header_table ASSIGNING
WHERE row_index EQ lv_col_index.
INSERT INTO TABLE lt_header_next.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #4: INSERT into LT_HEADER_NEXT failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
ENDWHILE.
DESCRIBE TABLE lt_header_prev LINES lv_lines_prev.
DESCRIBE TABLE lt_header_next LINES lv_lines_next.
IF lv_lines_prev GT lv_lines_next.
lv_lines_max = lv_lines_prev.
ELSE.
lv_lines_max = lv_lines_next.
ENDIF.
DO lv_lines_max TIMES.
ADD 1 TO lv_counter.
IF lv_lines_prev GT lv_counter AND lv_lines_next GT lv_counter.
READ TABLE lt_header_prev INDEX lv_counter INTO ls_header_prev.
READ TABLE lt_header_next INDEX lv_counter INTO ls_header_next.
lv_len_prev = strlen( ls_header_prev-field_name ).
lv_len_next = strlen( ls_header_next-field_name ).
IF lv_len_prev GT lv_len_next.
lv_len_max = lv_len_prev.
ELSE.
lv_len_max = lv_len_next.
ENDIF.
ELSEIF lv_lines_prev GT lv_counter AND lv_lines_next LE lv_counter.
lv_len_prev = strlen( ls_header_prev-field_name ).
lv_len_max = lv_len_prev.
ELSEIF lv_lines_prev LE lv_counter AND lv_lines_next GT lv_counter.
lv_len_next = strlen( ls_header_next-field_name ).
lv_len_max = lv_len_next.
ENDIF.
READ TABLE lt_col_length ASSIGNING INDEX lv_counter.
IF sy-subrc EQ 0.
IF -length LT lv_len_max.
-length = lv_len_max.
ENDIF.
ELSE.
CLEAR ls_col_length.
ls_col_length-length = lv_len_max.
INSERT ls_col_length INTO TABLE lt_col_length.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #5: INSERT into LT_COL_LENGTH failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDIF.
ENDDO.
CLEAR: lv_counter, lt_header_prev.
lt_header_prev = lt_header_next.
CLEAR lt_header_next.
ENDWHILE.
LOOP AT lt_col_length INTO ls_col_length.
ls_col-customwidth = 1.
ls_col-bestfit = 1.
READ TABLE lt_col_length INTO ls_col_length INDEX sy-tabix.
IF ls_col_length-length LT iv_width AND ls_col_length-fix_length EQ abap_false.
ls_col_length-length = iv_width.
ENDIF.
ls_col-width = ls_col_length-length.
ls_col-min = sy-tabix.
ls_col-max = sy-tabix.
ls_col-style = 0.
INSERT ls_col INTO TABLE et_col.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #6: INSERT into ET_COL failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
ls_col-customwidth = 1.
ls_col-bestfit = 1.
ls_col-width = iv_width.
ls_col-min = sy-tabix + 1.
ls_col-max = 16384.
ls_col-style = 0.
INSERT ls_col INTO TABLE et_col.
IF sy-subrc NE 0.
MESSAGE 'METH GET_WIDTH_FOR_COLS #7: INSERT into ET_COL failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Private Method PREPARE_DROP_DOWN_LIST
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_HEADER TYPE TT_HEADER_TABLE(optional)
* | [--->] IT_DATA_DESCR TYPE TT_DATA_DESC
* | [--->] IT_LIST_CONFIG_FOR_HEADER TYPE TT_LIST_CONFIG_FOR_HEADER(optional)
* | [--->] IV_DATA_STOP TYPE I
* | [<-->] CV_DROPDOWN_COUNT TYPE I
* | [<-->] CT_DROPDOWN_FORMULA TYPE TT_DROP_DOWN_FORMULA
* +--------------------------------------------------------------------------------------
METHOD prepare_drop_down_list.
DATA:
lv_cell_from TYPE string,
lv_cell_to TYPE string,
lv_row_from TYPE string,
lv_row_to TYPE string,
lv_row TYPE i,
lv_col TYPE i,
lv_correction TYPE boolean,
ls_list_config_for_header LIKE LINE OF it_list_config_for_header,
ls_drop_down_formula LIKE LINE OF ct_dropdown_formula,
ls_data_desc LIKE LINE OF it_data_descr.
FIELD-SYMBOLS:
LIKE LINE OF it_header.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
READ TABLE it_header ASSIGNING INDEX 1.
IF sy-subrc EQ 0.
IF -row_index EQ 0.
lv_correction = abap_true.
ELSE.
lv_correction = abap_false.
ENDIF.
ENDIF.
LOOP AT it_header ASSIGNING
WHERE s_drop_down_config IS NOT INITIAL.
lv_row_from = -s_drop_down_config-source-row_from.
CONCATENATE '$' -s_drop_down_config-source-col '$' lv_row_from
INTO lv_cell_from.
CONDENSE lv_cell_from.
lv_row_to = -s_drop_down_config-source-row_to.
CONCATENATE '$' -s_drop_down_config-source-col '$' lv_row_to
INTO lv_cell_to.
CONDENSE lv_cell_to.
CONCATENATE -s_drop_down_config-source-sheet_name '!' lv_cell_from ':' lv_cell_to
INTO ls_drop_down_formula-formula.
CONDENSE ls_drop_down_formula-formula.
CLEAR: lv_cell_from, lv_cell_to.
IF lv_correction EQ abap_true.
lv_row = -row_index + 1.
get_cell_position( EXPORTING iv_row = lv_row
iv_col = -col_index
RECEIVING rv_position = lv_cell_from ).
CLEAR lv_row.
ELSE.
get_cell_position( EXPORTING iv_row = -row_index
iv_col = -col_index
RECEIVING rv_position = lv_cell_from ).
ENDIF.
CONCATENATE lv_cell_from ':' lv_cell_from INTO ls_drop_down_formula-cells.
CONDENSE ls_drop_down_formula-cells.
IF -s_drop_down_config-restrict_values EQ 'X'.
ls_drop_down_formula-restrict = '1'.
IF -s_drop_down_config-error_text IS NOT INITIAL.
ls_drop_down_formula-error_text-header = -s_drop_down_config-error_text-header.
ls_drop_down_formula-error_text-text = -s_drop_down_config-error_text-text.
ENDIF.
ELSE.
ls_drop_down_formula-restrict = '0'.
ENDIF.
INSERT ls_drop_down_formula INTO TABLE ct_dropdown_formula.
IF sy-subrc NE 0.
MESSAGE 'METH PREPARE_DROP_DOWN_LIST #1: INSERT into CT_DROPDOWN_FORMULA failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
LOOP AT it_data_descr INTO ls_data_desc.
lv_col = lv_col + 1.
IF ls_data_desc-s_drop_down_config IS NOT INITIAL.
cv_dropdown_count = cv_dropdown_count + 1.
IF ls_data_desc-s_drop_down_config-source-row_from IS INITIAL
OR ls_data_desc-s_drop_down_config-source-row_to IS INITIAL.
CONCATENATE ls_data_desc-s_drop_down_config-source-sheet_name '!$' ls_data_desc-s_drop_down_config-source-col ':$' ls_data_desc-s_drop_down_config-source-col
INTO ls_drop_down_formula-formula.
CONDENSE ls_drop_down_formula-formula.
ELSE.
lv_row_from = ls_data_desc-s_drop_down_config-source-row_from.
CONCATENATE '$' ls_data_desc-s_drop_down_config-source-col '$' lv_row_from
INTO lv_cell_from.
CONDENSE lv_cell_from.
lv_row_to = ls_data_desc-s_drop_down_config-source-row_to.
CONCATENATE '$' ls_data_desc-s_drop_down_config-source-col '$' lv_row_to
INTO lv_cell_to.
CONDENSE lv_cell_to.
CONCATENATE ls_data_desc-s_drop_down_config-source-sheet_name '!' lv_cell_from ':' lv_cell_to
INTO ls_drop_down_formula-formula.
CONDENSE ls_drop_down_formula-formula.
ENDIF.
IF ls_data_desc-s_drop_down_config-range-row_from IS INITIAL.
ls_data_desc-s_drop_down_config-range-row_from = iv_data_stop + 1.
ENDIF.
IF ls_data_desc-s_drop_down_config-range-row_to IS INITIAL.
ls_data_desc-s_drop_down_config-range-row_to = 1048576.
ENDIF.
CLEAR: lv_cell_from, lv_cell_to.
get_cell_position( EXPORTING iv_row = ls_data_desc-s_drop_down_config-range-row_from
iv_col = lv_col
RECEIVING rv_position = lv_cell_from ).
get_cell_position( EXPORTING iv_row = ls_data_desc-s_drop_down_config-range-row_to
iv_col = lv_col
RECEIVING rv_position = lv_cell_to ).
CONCATENATE lv_cell_from ':' lv_cell_to INTO ls_drop_down_formula-cells.
CONDENSE ls_drop_down_formula-cells.
IF ls_data_desc-s_drop_down_config-restrict_values EQ 'X'.
ls_drop_down_formula-restrict = '1'.
IF ls_data_desc-s_drop_down_config-error_text IS NOT INITIAL.
ls_drop_down_formula-error_text-header = ls_data_desc-s_drop_down_config-error_text-header.
ls_drop_down_formula-error_text-text = ls_data_desc-s_drop_down_config-error_text-text.
ENDIF.
ELSE.
ls_drop_down_formula-restrict = '0'.
ENDIF.
INSERT ls_drop_down_formula INTO TABLE ct_dropdown_formula.
IF sy-subrc NE 0.
MESSAGE 'METH PREPARE_DROP_DOWN_LIST #2: INSERT into CT_DROPDOWN_FORMULA failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT it_list_config_for_header INTO ls_list_config_for_header.
cv_dropdown_count = cv_dropdown_count + 1.
IF ls_list_config_for_header-source-row_from IS INITIAL
OR ls_list_config_for_header-source-row_to IS INITIAL.
CONCATENATE ls_list_config_for_header-source-sheet_name '!$' ls_list_config_for_header-source-col ':$' ls_list_config_for_header-source-col
INTO ls_drop_down_formula-formula.
CONDENSE ls_drop_down_formula-formula.
ELSE.
lv_row_from = ls_list_config_for_header-source-row_from.
CONCATENATE '$' ls_list_config_for_header-source-col '$' lv_row_from
INTO lv_cell_from.
lv_row_to = ls_list_config_for_header-source-row_to.
CONCATENATE '$' ls_list_config_for_header-source-col '$' lv_row_to
INTO lv_cell_to.
CONDENSE : lv_cell_from , lv_cell_to.
CONCATENATE ls_list_config_for_header-source-sheet_name '!' lv_cell_from ':' lv_cell_to
INTO ls_drop_down_formula-formula.
CONDENSE ls_drop_down_formula-formula.
ENDIF.
IF ls_list_config_for_header-range-col_from IS INITIAL.
ls_list_config_for_header-range-col_from = 1.
ENDIF.
IF ls_list_config_for_header-range-row_from IS INITIAL.
ls_list_config_for_header-range-row_from = 1.
ENDIF.
IF ls_list_config_for_header-range-row_to IS INITIAL.
ls_list_config_for_header-range-row_to = ls_list_config_for_header-range-row_from.
ENDIF.
get_cell_position( EXPORTING iv_row = ls_list_config_for_header-range-row_from
iv_col = ls_list_config_for_header-range-col_from
RECEIVING rv_position = lv_cell_from ).
CLEAR lv_row_to.
lv_row_to = ls_list_config_for_header-range-row_to.
IF ls_list_config_for_header-range-col_to IS INITIAL.
CLEAR lv_cell_to.
CONCATENATE 'XFD' lv_row_to INTO lv_cell_to.
ELSE.
get_cell_position( EXPORTING iv_row = ls_data_desc-s_drop_down_config-range-row_to
iv_col = ls_list_config_for_header-range-col_to
RECEIVING rv_position = lv_cell_to ).
ENDIF.
CONCATENATE lv_cell_from ':' lv_cell_to INTO ls_drop_down_formula-cells.
CONDENSE ls_drop_down_formula-cells.
IF ls_list_config_for_header-restict_values EQ 'X'.
ls_drop_down_formula-restrict = '1'.
IF ls_list_config_for_header-error_text IS NOT INITIAL.
ls_drop_down_formula-error_text-header = ls_data_desc-s_drop_down_config-error_text-header.
ls_drop_down_formula-error_text-text = ls_data_desc-s_drop_down_config-error_text-text.
ELSE.
CLEAR ls_list_config_for_header.
ENDIF.
ELSE.
ls_drop_down_formula-restrict = '0'.
ENDIF.
INSERT ls_drop_down_formula INTO TABLE ct_dropdown_formula.
IF sy-subrc NE 0.
MESSAGE 'METH PREPARE_DROP_DOWN_LIST #3: INSERT into CT_DROPDOWN_FORMULA failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDIF.
ENDLOOP.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
* ---------------------------------------------------------------------------------------+
* | Instance Public Method PREPARE_FOR_DOWNLOAD
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_XLSX_XML TYPE XSTRING
* | [EXC!] OPENXML_ERROR
* +--------------------------------------------------------------------------------------
METHOD prepare_for_download.
DATA:
l_xlsx_doc TYPE REF TO cl_xlsx_document,
l_workbookpart TYPE REF TO cl_xlsx_workbookpart,
l_worksheetparts TYPE REF TO cl_openxml_partcollection,
l_worksheetpart TYPE REF TO cl_xlsx_worksheetpart,
l_stylespart TYPE REF TO cl_xlsx_stylespart,
l_sharedstringspart TYPE REF TO cl_xlsx_sharedstringspart,
lr_cx_openxml_format TYPE REF TO cx_openxml_format,
lr_cx_openxml_not_found TYPE REF TO cx_openxml_not_found,
lr_cx_openxml_not_allowed TYPE REF TO cx_openxml_not_allowed,
lr_cx_root TYPE REF TO cx_root,
lv_message TYPE string,
l_sheetxml TYPE xstring,
l_shared_xml TYPE xstring,
l_styles_xml TYPE xstring,
l_workbook_xml TYPE xstring.
FIELD-SYMBOLS:
TYPE ts_sheets_struc.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
create_sheet( EXPORTING iv_sheet_name = co_meta_data
iv_state = co_state_hidden " 0:visible, 1:Hidden
iv_disp_header = abap_false
it_table_data = mt_meta_data ).
TRY.
l_xlsx_doc = cl_xlsx_document=>create_document( ).
l_workbookpart = l_xlsx_doc->get_workbookpart( ).
l_worksheetparts = l_workbookpart->get_worksheetparts( ).
SORT mt_sheets STABLE BY state ASCENDING.
LOOP AT mt_sheets ASSIGNING .
l_worksheetpart ?= l_worksheetparts->get_part( iv_index = sy-tabix - 1 ).
IF l_worksheetpart IS INITIAL.
l_worksheetpart = l_workbookpart->add_worksheetpart( ).
ENDIF.
-relid = l_workbookpart->get_id_for_part( l_worksheetpart ).
CALL TRANSFORMATION zme_excel07_sheet_xml SOURCE param = -sheet
RESULT XML l_sheetxml.
l_worksheetpart->feed_data( iv_data = l_sheetxml ).
ENDLOOP.
create_style_sheet( ).
CALL TRANSFORMATION zme_excel07_stylesheet_xml SOURCE param = ms_style
RESULT XML l_styles_xml.
l_stylespart = l_workbookpart->add_stylespart( ).
l_stylespart->feed_data( iv_data = l_styles_xml ).
CALL TRANSFORMATION zme_excel07_shrdstring_xml SOURCE param = ms_sharedstring
RESULT XML l_shared_xml.
l_sharedstringspart = l_workbookpart->add_sharedstringspart( ).
l_sharedstringspart->feed_data( iv_data = l_shared_xml ).
CALL TRANSFORMATION zme_excel07_workbook_xml SOURCE param = mt_sheets
RESULT XML l_workbook_xml.
l_workbookpart->feed_data( iv_data = l_workbook_xml ).
rv_xlsx_xml = l_xlsx_doc->get_package_data( ).
CATCH cx_openxml_format INTO lr_cx_openxml_format.
lv_message = lr_cx_openxml_format->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH PREPARE_FOR_DOWNLOAD #1: Exception CX_OPENXML_FORMAT was caught' TYPE 'I' DISPLAY LIKE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
RAISE openxml_error.
CATCH cx_openxml_not_found INTO lr_cx_openxml_not_found.
lv_message = lr_cx_openxml_not_found->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH PREPARE_FOR_DOWNLOAD #2: Exception CX_OPENXML_NOT_FOUND was caught' TYPE 'I' DISPLAY LIKE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
RAISE openxml_error.
CATCH cx_openxml_not_allowed INTO lr_cx_openxml_not_allowed.
lv_message = lr_cx_openxml_not_allowed->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH PREPARE_FOR_DOWNLOAD #3: Exception CX_OPENXML_NOT_ALLOWED was caught' TYPE 'I' DISPLAY LIKE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
RAISE openxml_error.
CATCH cx_root INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lr_cx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'METH PREPARE_FOR_DOWNLOAD #4: Exception CX_ROOT was caught' TYPE 'I' DISPLAY LIKE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
RAISE openxml_error.
ENDTRY.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Public Method UPDATE_SHEET_DATA
** +-------------------------------------------------------------------------------------------------+
** | [--->] IV_NAME TYPE STRING(optional)
** | [--->] IV_XML TYPE XSTRING(optional)
** | [--->] IT_TABLE_DATA TYPE STANDARD TABLE(optional)
** | [<---] EV_XML TYPE XSTRING
** +--------------------------------------------------------------------------------------
* METHOD update_sheet_data.
*
* TYPES:
* BEGIN OF ts_new_node,
* node_r TYPE string,
* val TYPE string,
* END OF ts_new_node.
*
* DATA:
* lr_cx_openxml_format TYPE REF TO cx_openxml_format,
* lr_cx_openxml_not_found TYPE REF TO cx_openxml_not_found,
* lr_cx_openxml_not_allowed TYPE REF TO cx_openxml_not_allowed,
* lr_cx_root TYPE REF TO cx_root,
* lv_message TYPE string,
* lo_ixml_factory TYPE REF TO if_ixml,
* lo_stream_factory TYPE REF TO if_ixml_stream_factory,
* lo_istream TYPE REF TO if_ixml_istream,
* lo_idocument TYPE REF TO if_ixml_document,
* lo_iparser TYPE REF TO if_ixml_parser,
* lo_node_collection TYPE REF TO if_ixml_node_collection,
* lo_node_iterator TYPE REF TO if_ixml_node_iterator,
* lo_node TYPE REF TO if_ixml_node,
* lo_attr TYPE REF TO if_ixml_named_node_map,
* lr_subnode TYPE REF TO if_ixml_node,
* lr_attr_node TYPE REF TO if_ixml_node,
* lr_node_list TYPE REF TO if_ixml_node_list,
* lr_node_list_iterator TYPE REF TO if_ixml_node_iterator,
* lr_col_node TYPE REF TO if_ixml_node,
* lr_val_node TYPE REF TO if_ixml_node,
* lr_col_list TYPE REF TO if_ixml_node_list,
* lr_col_list_iterator TYPE REF TO if_ixml_node_iterator,
* lv_skip TYPE boolean,
* lv_excel_col TYPE i,
* lv_row TYPE string,
* lv_col TYPE string,
* lv_temp TYPE string,
* lv_num TYPE boolean,
* lt_new_node TYPE STANDARD TABLE OF ts_new_node,
* ls_new_node TYPE ts_new_node,
* lr_attr TYPE REF TO if_ixml_node,
* lr_new_node TYPE REF TO if_ixml_node,
* lr_clone_node TYPE REF TO if_ixml_node,
* lv_current_val TYPE string,
* lr_is_string TYPE REF TO if_ixml_node,
* l_workbookpart TYPE REF TO cl_xlsx_workbookpart,
* l_worksheetpart TYPE REF TO cl_xlsx_worksheetpart,
* l_sheet_xml TYPE xstring,
* l_xml TYPE REF TO cl_xml_document.
*
* FIELD-SYMBOLS:
* TYPE any,
* TYPE any,
* LIKE LINE OF mt_sheets.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* lo_ixml_factory = cl_ixml=>create( ).
* lo_stream_factory = lo_ixml_factory->create_stream_factory( ).
* lo_istream = lo_stream_factory->create_istream_xstring( iv_xml ).
* lo_idocument = lo_ixml_factory->create_document( ).
* lo_iparser = lo_ixml_factory->create_parser( stream_factory = lo_stream_factory
* istream = lo_istream
* document = lo_idocument ).
* lo_iparser->parse( ).
* lo_node_collection = lo_idocument->get_elements_by_tag_name( name = co_sheet_data ).
* lo_node_iterator = lo_node_collection->create_iterator( ).
* lo_node = lo_node_iterator->get_next( ).
* lr_node_list = lo_node->get_children( ).
* lr_node_list_iterator = lr_node_list->create_iterator( ).
*
* LOOP AT it_table_data ASSIGNING .
* lr_subnode = lr_node_list_iterator->get_next( ).
* lr_col_list = lr_subnode->get_children( ).
* lr_col_list_iterator = lr_col_list->create_iterator( ).
* lo_attr = lr_subnode->get_attributes( ).
* lr_attr_node = lo_attr->get_named_item( name = 'r' ).
* lv_row = lr_attr_node->get_value( ).
* DO.
* ASSIGN COMPONENT sy-index OF STRUCTURE TO .
* IF sy-subrc IS NOT INITIAL.
* EXIT.
* ENDIF.
* IF lv_skip EQ abap_false.
* lr_col_node = lr_col_list_iterator->get_next( ).
* IF lr_col_node IS INITIAL.
* IF IS INITIAL.
* EXIT.
* ENDIF.
* ls_new_node-val = .
* lv_num = _is_num( iv_value = ls_new_node-val ).
* IF lv_num NE abap_true.
* EXIT.
* ENDIF.
* get_col_label( EXPORTING iv_col = sy-index
* IMPORTING ev_col = lv_temp ).
* CONCATENATE lv_temp lv_row INTO lv_temp.
* CONDENSE lv_temp NO-GAPS.
* ls_new_node-node_r = lv_temp.
* INSERT ls_new_node INTO TABLE lt_new_node.
* IF sy-subrc NE 0.
* MESSAGE 'METH UPDATE_SHEET_DATA #1: INSERT into LT_NEW_NODE failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDIF.
* CONTINUE. " we need to create a new node here
* ENDIF.
* lo_attr = lr_col_node->get_attributes( ).
* lr_attr_node = lo_attr->get_named_item( name = 'r' ).
* lv_temp = lr_attr_node->get_value( ).
* SPLIT lv_temp AT lv_row INTO lv_col lv_temp.
* get_col_index( EXPORTING iv_col_index = lv_col
* IMPORTING ev_col = lv_excel_col ).
* ENDIF.
* lv_temp = .
* IF lv_excel_col GT sy-index.
* lv_skip = abap_true.
* IF lv_temp IS NOT INITIAL.
* ls_new_node-val = lv_temp.
* get_col_label( EXPORTING iv_col = sy-index
* IMPORTING ev_col = lv_temp ).
* CONCATENATE lv_temp lv_row INTO lv_temp.
* CONDENSE lv_temp NO-GAPS.
* ls_new_node-node_r = lv_temp.
* INSERT ls_new_node INTO TABLE lt_new_node.
* IF sy-subrc NE 0.
* MESSAGE 'METH UPDATE_SHEET_DATA #2: INSERT into LT_NEW_NODE failed' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDIF.
* ENDIF.
* CONTINUE.
* ENDIF.
* lv_skip = abap_false.
* lv_current_val = lr_col_node->get_value( ).
* IF lr_clone_node IS INITIAL AND lv_current_val IS NOT INITIAL.
* lr_clone_node = lr_col_node->clone( ).
* ENDIF.
* IF lv_temp IS NOT INITIAL.
* lv_num = _is_num( iv_value = lv_temp ).
* IF lv_num NE abap_false.
* lr_is_string = lo_attr->get_named_item_ns( name = 't' ).
* IF lr_is_string IS NOT INITIAL.
* CONTINUE.
* ENDIF.
* CHECK lv_current_val NE lv_temp.
* lr_val_node = lr_col_node->get_first_child( ).
* IF lr_val_node IS NOT INITIAL.
* lr_val_node->set_value( value = lv_temp ).
* ELSE.
* lo_idocument->create_simple_element( name = 'v'
* parent = lr_col_node
* value = lv_temp ).
* ENDIF.
* ENDIF.
* ENDIF.
* ENDDO.
* LOOP AT lt_new_node INTO ls_new_node.
* lr_new_node = lr_clone_node->clone( ).
* lo_attr = lr_new_node->get_attributes( ).
* lo_attr->remove_named_item( name = 't' ).
* lr_attr = lo_attr->get_named_item_ns( name = 'r' ).
* lr_attr->set_value( value = ls_new_node-node_r ).
* lr_val_node = lr_new_node->get_first_child( ).
* lr_val_node->set_value( value = ls_new_node-val ).
* lr_subnode->append_child( new_child = lr_new_node ).
* ENDLOOP.
* CLEAR lt_new_node.
* ENDLOOP.
*
* TRY.
* CREATE OBJECT l_xml.
* l_xml->create_with_dom( document = lo_idocument ).
* l_xml->render_2_xstring( IMPORTING stream = l_sheet_xml ).
* l_workbookpart = mo_xlsx_doc->get_workbookpart( ).
* READ TABLE mt_sheets ASSIGNING WITH KEY name = iv_name.
* IF sy-subrc IS INITIAL.
* l_worksheetpart ?= l_workbookpart->get_part_by_id( -relid ).
* l_worksheetpart->feed_data( iv_data = l_sheet_xml ).
* IF ev_xml IS REQUESTED.
* ev_xml = mo_xlsx_doc->get_package_data( ).
* ENDIF.
* ENDIF.
* CATCH cx_openxml_format INTO lr_cx_openxml_format.
* lv_message = lr_cx_openxml_format->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH UPDATE_SHEET_DATA #1: Exception CX_OPENXML_FORMAT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* CATCH cx_openxml_not_found INTO lr_cx_openxml_not_found.
* lv_message = lr_cx_openxml_not_found->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH UPDATE_SHEET_DATA #2: Exception CX_OPENXML_FORMAT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* CATCH cx_openxml_not_allowed INTO lr_cx_openxml_not_allowed.
* lv_message = lr_cx_openxml_not_allowed->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH UPDATE_SHEET_DATA #3: Exception CX_OPENXML_FORMAT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* CATCH cx_root INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
**--- error tolerant mode: do not cause catchable runtime errors!
* lv_message = lr_cx_root->if_message~get_text( ).
* IF lv_message IS NOT INITIAL.
* MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
* ENDIF.
* MESSAGE 'METH UPDATE_SHEET_DATA #4: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* ENDTRY.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Private Method UPLOAD
** +-------------------------------------------------------------------------------------------------+
** | [<---] EV_XLSX_XML TYPE XSTRING
** | [EXC!] FILE_UPLOAD_ERROR
** | [EXC!] USER_CANCEL
** +--------------------------------------------------------------------------------------
* METHOD upload.
*
* DATA:
* lv_rc TYPE i,
* lv_user_action TYPE i,
* lv_filelength TYPE i,
* lv_title TYPE string,
* lv_filepath TYPE string,
* ls_file TYPE file_table,
* lt_file TYPE filetable,
* lt_file_content TYPE STANDARD TABLE OF solisti1.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* lv_title = 'Export to Excel 2007 and higher'. "pragma or pseudo comment NO_TEXT: Okay, technical value!
* CALL METHOD cl_gui_frontend_services=>file_open_dialog
* EXPORTING
* window_title = lv_title
* default_extension = 'xlsx' "pragma or pseudo comment NO_TEXT: Okay, technical value!
* file_filter = 'Excel (*.XLSX)|*.XLSX|' "pragma or pseudo comment NO_TEXT: Okay, technical value!
* CHANGING
* file_table = lt_file
* rc = lv_rc
* user_action = lv_user_action
* EXCEPTIONS
* file_open_dialog_failed = 1
* cntl_error = 2
* error_no_gui = 3
* not_supported_by_gui = 4
* OTHERS = 5.
* IF sy-subrc NE 0 OR lv_rc EQ -1.
* MESSAGE 'Error during frontend communication' TYPE 'I' DISPLAY LIKE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* RETURN.
* ENDIF.
* IF lv_user_action = cl_gui_frontend_services=>action_cancel.
* MESSAGE 'Canceled by user' TYPE 'S'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* RAISE user_cancel.
* ENDIF.
* READ TABLE lt_file INTO ls_file INDEX 1.
* lv_filepath = ls_file-filename.
* CALL METHOD cl_gui_frontend_services=>gui_upload
* EXPORTING
* filename = lv_filepath
* filetype = 'BIN'
* IMPORTING
* filelength = lv_filelength
* CHANGING
* data_tab = lt_file_content
* EXCEPTIONS
* file_open_error = 1
* file_read_error = 2
* no_batch = 3
* gui_refuse_filetransfer = 4
* invalid_type = 5
* no_authority = 6
* unknown_error = 7
* bad_data_format = 8
* header_not_allowed = 9
* separator_not_allowed = 10
* header_too_long = 11
* unknown_dp_error = 12
* access_denied = 13
* dp_out_of_memory = 14
* disk_full = 15
* dp_timeout = 16
* not_supported_by_gui = 17
* error_no_gui = 18
* OTHERS = 19.
* IF sy-subrc NE 0.
* MESSAGE i252(s#) DISPLAY LIKE 'E'
* WITH 'METH UPLOAD:' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* 'CL_GUI_FRONTEND=>GUI_DOWNLOAD' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* 'returned with error code' "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* sy-subrc.
* RAISE file_upload_error.
* ENDIF.
* IF lt_file_content IS NOT INITIAL.
* CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
* EXPORTING
* input_length = lv_filelength
* IMPORTING
* buffer = ev_xlsx_xml
* TABLES
* binary_tab = lt_file_content.
* ENDIF.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
** ---------------------------------------------------------------------------------------+
** | Instance Private Method _IS_NUM
** +-------------------------------------------------------------------------------------------------+
** | [--->] IV_VALUE TYPE STRING
** | [<-()] RV_NUM TYPE BOOLEAN
** +--------------------------------------------------------------------------------------
* METHOD _is_num.
*
* CONSTANTS:
* lc_n TYPE string VALUE ' 0123456789. '.
*
* DATA:
* lr_cx_root TYPE REF TO cx_root,
* lv_msg TYPE string.
*
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* TRY.
* IF iv_value CO lc_n.
* rv_num = abap_true.
* ELSE.
* rv_num = abap_false.
* ENDIF.
* CATCH cx_sy_conversion_no_number INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
**--- error tolerant mode: do not cause catchable runtime errors!
* lv_msg = lr_cx_root->if_message~get_text( ).
* IF lv_msg IS NOT INITIAL.
* MESSAGE lv_msg TYPE 'I' DISPLAY LIKE 'E'.
* WRITE: / lv_msg.
* ENDIF.
* WRITE: / 'METH _IS_NUM: Exception CX_SY_CONVERSION_NO_NUMBER was caught'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* rv_num = abap_false.
* CATCH cx_sy_conversion_overflow INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
**--- error tolerant mode: do not cause catchable runtime errors!
* lv_msg = lr_cx_root->if_message~get_text( ).
* IF lv_msg IS NOT INITIAL.
* MESSAGE lv_msg TYPE 'I' DISPLAY LIKE 'E'.
* WRITE: / lv_msg.
* ENDIF.
* WRITE: / 'METH _IS_NUM: Exception CX_SY_CONVERSION_OVERFLOW was caught'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* rv_num = abap_false.
* CATCH cx_root INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
**--- error tolerant mode: do not cause catchable runtime errors!
* lv_msg = lr_cx_root->if_message~get_text( ).
* IF lv_msg IS NOT INITIAL.
* MESSAGE lv_msg TYPE 'I' DISPLAY LIKE 'E'.
* WRITE: / lv_msg.
* ENDIF.
* WRITE: / 'METH _IS_NUM: Exception CX_ROOT was caught'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
* rv_num = abap_false.
* ENDTRY.
** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* ENDMETHOD.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDCLASS. "CLASS lcl_excel_adpater IMPLEMENTATION.
*----------------------------------------------------------------------
*--- Global data declarations
*----------------------------------------------------------------------
TYPES:
BEGIN OF ts_line,
line TYPE x LENGTH 255,
END OF ts_line,
tt_line TYPE STANDARD TABLE OF ts_line WITH DEFAULT KEY.
CONSTANTS:
con_title TYPE sytitle VALUE 'SE16 Lite', "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical text!
con_tab TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab.
*----------------------------------------------------------------------
*--- Selection screen 1000
*----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE sel.
PARAMETERS:
p_table TYPE tabname OBLIGATORY DEFAULT 'T000', "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION
p_where TYPE string. "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION
SELECTION-SCREEN END OF BLOCK sel.
SELECTION-SCREEN BEGIN OF BLOCK opt WITH FRAME TITLE opt.
PARAMETERS:
p_write RADIOBUTTON GROUP out DEFAULT 'X', "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION!
p_zip RADIOBUTTON GROUP out, "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION!
p_alv1 RADIOBUTTON GROUP out, "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION!
p_alv2 RADIOBUTTON GROUP out, "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION!
p_excel1 RADIOBUTTON GROUP out, "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION!
p_excel2 RADIOBUTTON GROUP out. "pragma or pseudo comment SEL_WRONG: Okay, set in event INITIALIZATION!
SELECTION-SCREEN END OF BLOCK opt.
*----------------------------------------------------------------------
*--- event initialization
*----------------------------------------------------------------------
INITIALIZATION.
PERFORM init.
*----------------------------------------------------------------------
*--- event start-of-selections
*----------------------------------------------------------------------
START-OF-SELECTION.
PERFORM main.
*&---------------------------------------------------------------------*
*& Form INIT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM init.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*--- define texts for selection screen 1000
sy-title = con_title.
sel = 'Selections'.
opt = 'Options'.
%_p_table_%_app_%-text = 'Table Name'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_where_%_app_%-text = 'WHERE Clause'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_write_%_app_%-text = 'ABAP List Processing'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_zip_%_app_%-text = 'ZIP File (Flat ASCII)'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_alv1_%_app_%-text = 'ALV Display (Text)'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_alv2_%_app_%-text = 'ALV Display (Field Name)'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_excel1_%_app_%-text = 'Excel Download (Text)'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
%_p_excel2_%_app_%-text = 'Excel Download (Field Name)'. "pragma or pseudo comment NO_TEXT and SEL_WRONG: Okay, technical value!
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM main.
DATA:
lr_gen_table TYPE REF TO lcl_gen_table,
lr_excel TYPE REF TO lcl_excel_adpater,
lr_table TYPE REF TO data,
lr_cx_root TYPE REF TO cx_root,
lv_sheet_name TYPE string,
lt_excel_header TYPE lcl_excel_adpater=>tt_header_table,
lv_technical_header TYPE abap_bool,
lv_message TYPE c LENGTH 272.
FIELD-SYMBOLS:
TYPE STANDARD TABLE.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TRY.
*--- fill with your data and provide it to the excel adapter classs
CREATE OBJECT lr_gen_table
EXPORTING
iv_tabname = p_table
iv_where = p_where.
CREATE DATA lr_table TYPE STANDARD TABLE OF (p_table).
ASSIGN lr_table->* TO .
lr_gen_table->get_table( IMPORTING et_table = ).
IF IS INITIAL.
CONCATENATE `Content of Table ` p_table ': Nothing selected' "pragma or pseudo comment NO_TEXT: Okay, technical text!
INTO lv_message.
MESSAGE lv_message TYPE 'S'.
RETURN.
ENDIF.
*--- output, if we got something...
CASE 'X'.
WHEN p_excel1 OR p_excel2.
*--- create Excel sheet with dynamic data ...
CREATE OBJECT lr_excel.
CASE abap_true.
WHEN p_excel1.
lv_technical_header = abap_false.
WHEN p_excel2.
lv_technical_header = abap_true.
WHEN OTHERS.
lv_technical_header = abap_true.
ENDCASE.
lr_excel->create_sheet( EXPORTING iv_sheet_name = lv_sheet_name
it_header = lt_excel_header
iv_disp_header = abap_true
iv_tech_header = lv_technical_header
it_table_data = ).
*--- ... and download excel file
lr_excel->download( EXPORTING iv_tab_name = p_table
EXCEPTIONS download_failed = 1
download_cancelled = 2
OTHERS = 3 ).
IF sy-subrc NE 0.
RETURN.
ENDIF.
WHEN p_alv1 OR p_alv2.
*--- display in ALV grid
CASE abap_true.
WHEN p_alv1.
lv_technical_header = abap_false.
WHEN p_alv2.
lv_technical_header = abap_true.
WHEN OTHERS.
lv_technical_header = abap_true.
ENDCASE.
PERFORM display_alv USING p_table lv_technical_header .
WHEN p_zip.
PERFORM write_zip_file USING p_table .
WHEN p_write.
lr_gen_table->output( ).
WHEN OTHERS.
MESSAGE 'Unknown output selection' TYPE 'S' DISPLAY LIKE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
RETURN.
ENDCASE.
CATCH cx_root INTO lr_cx_root. "pragma or pseudo comment CATCH_ALL: Okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
lv_message = lr_cx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'FORM MAIN: Exception CX_ROOT was caught' TYPE 'E'. "pragma or pseudo comment NO_TEXT: Okay, technical error message!
ENDTRY.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IV_TABNAME text
* -->IV_TECHNICAL text
* -->IT_ANY_TABLE[] text
*----------------------------------------------------------------------*
FORM display_alv USING iv_tabname TYPE dd02l-tabname
iv_technical TYPE abap_bool
it_any_table TYPE ANY TABLE.
DATA:
lr_alv_table TYPE REF TO cl_salv_table,
lr_functions_list TYPE REF TO cl_salv_functions_list,
lr_columns_table TYPE REF TO cl_salv_columns_table,
lr_column_table TYPE REF TO cl_salv_column_table,
lr_display_settings TYPE REF TO cl_salv_display_settings,
lr_header_info TYPE REF TO cl_salv_form_header_info,
lx_salv_msg TYPE REF TO cx_salv_msg,
lx_salv_not_found TYPE REF TO cx_salv_not_found,
lx_salv_data_error TYPE REF TO cx_salv_data_error,
lx_salv_existing TYPE REF TO cx_salv_existing,
lx_root TYPE REF TO cx_root,
lt_dfies TYPE STANDARD TABLE OF dfies WITH DEFAULT KEY,
lv_error TYPE string,
lv_short_text TYPE scrtext_s,
lv_medium_text TYPE scrtext_m,
lv_long_text TYPE scrtext_l,
lv_counts TYPE i,
lv_header_count TYPE c LENGTH 20,
lv_header_text TYPE string,
lv_list_header TYPE lvc_title.
FIELD-SYMBOLS:
LIKE LINE OF lt_dfies.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CONCATENATE 'Content of Table' iv_tabname "pragma or pseudo comment NO_TEXT: Okay, technical text!
INTO lv_header_text SEPARATED BY space.
IF it_any_table[] IS INITIAL.
CONCATENATE lv_header_text `: Nothing selected` "pragma or pseudo comment NO_TEXT: Okay, technical text!
INTO lv_header_text.
MESSAGE lv_header_text TYPE 'S'.
RETURN.
ENDIF.
TRY.
*--- create ALV table
cl_salv_table=>factory( IMPORTING r_salv_table = lr_alv_table
CHANGING t_table = it_any_table[] ).
*--- activate all standard functions
lr_functions_list = lr_alv_table->get_functions( ).
lr_functions_list->set_all( if_salv_c_bool_sap=>true ).
*--- set optimized column size
lr_columns_table = lr_alv_table->get_columns( ).
lr_columns_table->set_optimize( if_salv_c_bool_sap=>true ).
*--- set technical field name as column header
CLEAR lt_dfies[].
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = iv_tabname
* FIELDNAME = ' '
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* GROUP_NAMES = ' '
* UCLEN =
* DO_NOT_WRITE = ' '
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
dfies_tab = lt_dfies[]
* FIXED_VALUES =
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc EQ 0 AND lt_dfies[] IS NOT INITIAL.
LOOP AT lt_dfies ASSIGNING .
lr_column_table ?= lr_columns_table->get_column( -fieldname ).
CASE iv_technical.
WHEN abap_true.
lv_short_text = -fieldname.
lv_medium_text = -fieldname.
lv_long_text = -fieldname.
WHEN OTHERS.
IF -scrtext_s IS NOT INITIAL.
lv_short_text = -scrtext_s.
ELSE.
lv_short_text = -fieldname.
ENDIF.
IF -scrtext_m IS NOT INITIAL.
lv_medium_text = -scrtext_m.
ELSE.
lv_medium_text = -fieldname.
ENDIF.
IF -scrtext_l IS NOT INITIAL.
lv_long_text = -scrtext_l.
ELSE.
lv_long_text = -fieldname.
ENDIF.
ENDCASE.
lr_column_table->set_short_text( lv_short_text ).
lr_column_table->set_medium_text( lv_medium_text ).
lr_column_table->set_long_text( lv_long_text ).
IF -position EQ '0000' AND -datatype EQ 'CLNT'. "pragma or pseudo comment NO_TEXT: Okay, technical value!
*--- enable output of field client/mandt
lr_column_table->set_technical( if_salv_c_bool_sap=>false ).
ENDIF.
ENDLOOP.
ENDIF.
*--- set zebra layout
lr_display_settings = lr_alv_table->get_display_settings( ).
lr_display_settings->set_striped_pattern( if_salv_c_bool_sap=>true ).
*--- set title
lv_list_header = lv_header_text.
lr_display_settings->set_list_header( lv_list_header ).
*--- set header and display number of displayed entries
DESCRIBE TABLE it_any_table LINES lv_counts.
WRITE lv_counts TO lv_header_count LEFT-JUSTIFIED.
CONCATENATE 'Number of entries:' lv_header_count "pragma or pseudo comment NO_TEXT: Okay, technical text!
INTO lv_header_text SEPARATED BY space.
CREATE OBJECT lr_header_info
EXPORTING
text = lv_header_text.
lr_alv_table->set_top_of_list( EXPORTING value = lr_header_info ).
*--- display table
lr_alv_table->display( ).
*--- error handling
CATCH cx_salv_msg INTO lx_salv_msg.
CLEAR lv_error.
lv_error = lx_salv_msg->if_message~get_text( ).
MESSAGE lv_error TYPE 'E'.
CATCH cx_salv_not_found INTO lx_salv_not_found.
CLEAR lv_error.
lv_error = lx_salv_not_found->if_message~get_text( ).
MESSAGE lv_error TYPE 'E'.
CATCH cx_salv_data_error INTO lx_salv_data_error.
CLEAR lv_error.
lv_error = lx_salv_data_error->if_message~get_text( ).
MESSAGE lv_error TYPE 'E'.
CATCH cx_salv_existing INTO lx_salv_existing.
CLEAR lv_error.
lv_error = lx_salv_existing->if_message~get_text( ).
MESSAGE lv_error TYPE 'E'.
CATCH cx_root INTO lx_root. "pragma or pseudo comment CATCH_ALL: okay, one to catch them all!
*--- error tolerant mode: do not cause catchable runtime errors!
CLEAR lv_error.
lv_error = lx_root->if_message~get_text( ).
MESSAGE lv_error TYPE 'E'.
ENDTRY.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDFORM.
*&---------------------------------------------------------------------*
*& Form WRITE_ZIP_FILE
*&---------------------------------------------------------------------*
*& SAP has provided the class CL_ABAP_ZIP for reading and writing
*& zip files which we are going to utilize to generate zip file.
*& Following is the sequence of process involved to generate a zip
*& file.
*&
*& Steps:
*& 1. Fetch data into internal tables (already provided)
*& 2. Convert internal table into string
*& 3. Convert string to xstring
*& 4. Create object for CL_ABAP_ZIP
*& 5. Use add method to add new files to the zip archive
*& 6. Now, save method returns the final zip file in xstring
*& 7. Convert the xstring to internal (binary) table
*& 8. Download it using GUI_DOWNLOAD to write binary file
*&---------------------------------------------------------------------*
*& --> IV_TABNAME
*& --> IT_OUTPUT[]
*&---------------------------------------------------------------------*
FORM write_zip_file USING iv_tabname TYPE dd02l-tabname
it_output TYPE STANDARD TABLE.
DATA:
lr_abap_zip TYPE REF TO cl_abap_zip,
lx_root TYPE REF TO cx_root,
lt_dfies TYPE STANDARD TABLE OF dfies WITH DEFAULT KEY,
lt_output TYPE tt_line,
lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_string TYPE string,
lv_xstring TYPE xstring,
lv_length_f TYPE i,
lv_length_x TYPE i,
lv_xstr_zip TYPE xstring,
lv_value TYPE c LENGTH 2048,
lv_message TYPE string.
FIELD-SYMBOLS:
TYPE any,
TYPE any,
LIKE LINE OF lt_dfies.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IF iv_tabname IS INITIAL OR it_output[] IS INITIAL.
RETURN.
ENDIF.
CLEAR:
lt_dfies[], lt_output[].
*--- step 2. Convert internal table into string
*--- get structure of the provided table
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = iv_tabname
* FIELDNAME = ' '
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* GROUP_NAMES = ' '
* UCLEN =
* DO_NOT_WRITE = ' '
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
dfies_tab = lt_dfies[]
* FIXED_VALUES =
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
CASE sy-subrc.
WHEN 1.
MESSAGE 'FM DDIF_FIELDINFO_GET returned with exception NOT_FOUND' TYPE 'I' DISPLAY LIKE 'E'.
WHEN 2.
MESSAGE 'FM DDIF_FIELDINFO_GET returned with exception INTERNAL_ERROR' TYPE 'I' DISPLAY LIKE 'E'.
WHEN OTHERS.
MESSAGE 'FM DDIF_FIELDINFO_GET returned with exception OTHERS' TYPE 'I' DISPLAY LIKE 'E'.
ENDCASE.
RETURN.
ENDIF.
SORT lt_dfies ASCENDING BY position.
*--- create header line containing the technical field names
CLEAR: lv_string, lv_value.
LOOP AT lt_dfies ASSIGNING .
IF sy-tabix EQ 1.
lv_string = -fieldname.
ELSE.
CONCATENATE lv_string -fieldname
INTO lv_string SEPARATED BY con_tab.
ENDIF.
ENDLOOP.
*--- convert the content of the internal table as well
LOOP AT it_output ASSIGNING .
LOOP AT lt_dfies ASSIGNING .
CLEAR lv_value.
UNASSIGN .
ASSIGN COMPONENT -fieldname OF STRUCTURE TO .
IF IS ASSIGNED.
WRITE TO lv_value LEFT-JUSTIFIED NO-GROUPING.
ENDIF.
CONCATENATE lv_string lv_value
INTO lv_string SEPARATED BY con_tab.
ENDLOOP.
ENDLOOP.
*--- step 3. Convert string to xstring
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_string
* MIMETYPE = ' '
* ENCODING =
IMPORTING
buffer = lv_xstring
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc NE 0.
CASE sy-subrc.
WHEN 1.
MESSAGE 'FM SCMS_STRING_TO_XSTRING returned with exception FAILED' TYPE 'I' DISPLAY LIKE 'E'.
WHEN OTHERS.
MESSAGE 'FM SCMS_STRING_TO_XSTRING returned with exception OTHERS' TYPE 'I' DISPLAY LIKE 'E'.
ENDCASE.
RETURN.
ENDIF.
*--- step 4. Create object for CL_ABAP_ZIP
TRY.
CREATE OBJECT lr_abap_zip.
IF lr_abap_zip IS NOT BOUND.
MESSAGE 'CREATE OBJECT CL_ABAP_ZIP failed' TYPE 'I' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
*--- step 5. Use add method to add new files to the zip archive
CLEAR: lv_filename, lv_path, lv_fullpath.
CONCATENATE sy-sysid sy-mandt iv_tabname sy-datum sy-uzeit '.txt'
INTO lv_filename SEPARATED BY '_'.
lr_abap_zip->add( EXPORTING name = lv_filename
content = lv_xstring ).
* compress_level = 6 ).
CLEAR lv_xstring. "release allocated memory
*--- step 6. Now, save method returns the final zip file in xstring
CALL METHOD lr_abap_zip->save
RECEIVING
zip = lv_xstr_zip.
CATCH cx_root INTO lx_root.
lv_message = lx_root->if_message~get_text( ).
IF lv_message IS NOT INITIAL.
MESSAGE lv_message TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
MESSAGE 'ZIP file could not be created' TYPE 'I' DISPLAY LIKE 'E'.
RETURN.
ENDTRY.
*--- step 7. Convert the xstring to internal (binary) table
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstr_zip
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = lv_length_x
TABLES
binary_tab = lt_output[].
CLEAR lv_xstr_zip. "release allocated memory
*--- step 8. Download it using GUI_DOWNLOAD to write binary file
lv_value = lv_filename.
lv_length_f = strlen( lv_value ).
SUBTRACT 3 FROM lv_length_f.
lv_value+lv_length_f = 'zip'.
lv_filename = lv_value.
CLEAR lv_length_f.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Save ZIP FIle'
default_extension = 'zip'
default_file_name = lv_filename
* with_encoding =
file_filter = 'ZIP File (*.zip)|*.zip'
* initial_directory =
* prompt_on_overwrite = 'X'
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
* user_action =
* file_encoding =
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
invalid_default_file_name = 4
OTHERS = 5.
IF sy-subrc NE 0.
CASE sy-subrc.
WHEN 1.
MESSAGE 'METH CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG returned with exception CNTL_ERROR' TYPE 'I' DISPLAY LIKE 'E'.
WHEN 2.
MESSAGE 'METH CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG returned with exception ERROR_NO_GUI' TYPE 'I' DISPLAY LIKE 'E'.
WHEN 3.
MESSAGE 'METH CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG returned with exception NOT_SUPPORTED_BY_GUI' TYPE 'I' DISPLAY LIKE 'E'.
WHEN 4.
MESSAGE 'METH CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG returned with exception INVALID_DEFAULT_FILE_NAME' TYPE 'I' DISPLAY LIKE 'E'.
WHEN OTHERS.
MESSAGE 'METH CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG returned with exception OTHERS' TYPE 'I' DISPLAY LIKE 'E'.
ENDCASE.
RETURN.
ENDIF.
IF lv_fullpath IS INITIAL.
RETURN.
ENDIF.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lv_length_x
filename = lv_fullpath
filetype = 'BIN'
* append = SPACE
* write_field_separator = SPACE
* header = '00'
* trunc_trailing_blanks = SPACE
* write_lf = 'X'
* col_select = SPACE
* col_select_mask = SPACE
* dat_mode = SPACE
confirm_overwrite = abap_true
* no_auth_check = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* write_bom = SPACE
* trunc_trailing_blanks_eol = 'X'
* wk1_n_format = SPACE
* wk1_n_size = SPACE
* wk1_t_format = SPACE
* wk1_t_size = SPACE
* show_transfer_status = 'X'
* fieldnames =
* write_lf_after_last_line = 'X'
* virus_scan_profile = '/SCET/GUI_DOWNLOAD'
IMPORTING
filelength = lv_length_f
CHANGING
data_tab = lt_output[]
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
IF sy-subrc NE 0.
MESSAGE 'METH CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD returned with exception code' TYPE 'I' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
IF lv_length_f NE lv_length_x.
MESSAGE `Huston! We've got a problem! The file name does not match!` TYPE 'S' DISPLAY LIKE 'W'.
ENDIF.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENDFORM.
*--- The End!