Code: Alles auswählen.
BUKRS BUKRS
BUDAT BUDAT
KSTAR KSTAR
NAME TXT50
OBJNR J_OBJNR
MEINH CO_MEINH
PRAMEVM MEGXXX
PRAWEVM WKGXXX
ISTMEMON MEGXXX
ISTWEMON WKGXXX
ISTMIPRAME MEGXXX
ISTMIPRAWE WKGXXX
BUDMEVM MEGXXX
BUDWEVM WKGXXX
ABWME MEGXXX
ABWWE WKGXXX
ABGRME MEGXXX
ABGRWE WKGXXX
ISTMEVM MEGXXX
ISTWEVM WKGXXX
Währungsfelder
PRAMEVM MEGXXX QUAN COSP MEINH Menge gesamt
PRAWEVM WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
ISTMEMON MEGXXX QUAN COSP MEINH Menge gesamt
ISTWEMON WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
ISTMIPRAME MEGXXX QUAN COSP MEINH Menge gesamt
ISTMIPRAWE WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
BUDMEVM MEGXXX QUAN COSP MEINH Menge gesamt
BUDWEVM WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
ABWME MEGXXX QUAN COSP MEINH Menge gesamt
ABWWE WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
ABGRME MEGXXX QUAN COSP MEINH Menge gesamt
ABGRWE WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
ISTMEVM MEGXXX QUAN COSP MEINH Menge gesamt
ISTWEVM WKGXXX CURR TKA01 WAERS Wert gesamt in Kostenrechnungskreiswährung
Code: Alles auswählen.
* Unicode-Umstellung
:
:
TYPES ty_excel TYPE zfi2excel.
TYPES:
* BEGIN OF ty_excel,
* bukrs LIKE pbukrs,
* budat LIKE pbudat,
* kstar LIKE cosp-kstar,
* name LIKE skat-txt50,
* objnr LIKE cosp-objnr,
* meinh LIKE cosp-meinh,
* pramevm LIKE cosp-meg001, "PRA Vorm.
* prawevm LIKE cosp-wkg001,
* istmemon LIKE itab-pramevm, "Saldo + PRA Mon.
* istwemon LIKE itab-prawevm,
* istmiprame LIKE itab-pramevm, "Saldo o. PRA Mon.
* istmiprawe LIKE itab-prawevm,
* budmevm LIKE itab-pramevm,
* budwevm LIKE itab-prawevm,
* abwme LIKE itab-pramevm,
* abwwe LIKE itab-prawevm, "Abw.zum Plan Wert
* abgrme LIKE itab-pramevm, "Neue Abgrenzung (für Übern.
* abgrwe LIKE itab-prawevm,
* istmevm LIKE itab-pramevm, "Saldo + PRA Vorm.
* istwevm LIKE itab-prawevm,
* END OF ty_excel,
BEGIN OF ty_file,
data(2000),
END OF ty_file.
:
:
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Form save_excel
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IT_EXCEL text
*----------------------------------------------------------------------*
FORM save_excel TABLES it_excel USING i_fullpath TYPE string.
TYPE-POOLS: abap.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_excel_writer TYPE REF TO zif_excel_writer,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
column_dimension TYPE REF TO zcl_excel_worksheet_columndime.
DATA: ls_table_settings TYPE zexcel_s_table_settings.
DATA: lv_file TYPE xstring,
lv_bytecount TYPE i,
lt_file_tab TYPE solix_tab.
DATA: lv_full_path TYPE string,
lv_workdir TYPE string,
lv_file_separator TYPE c.
DATA: lv_title TYPE zexcel_sheet_title,
lt_carr TYPE TABLE OF scarr,
row TYPE zexcel_cell_row VALUE 2,
lo_range TYPE REF TO zcl_excel_range.
DATA: lo_data_validation TYPE REF TO zcl_excel_data_validation.
DATA c_col(21) VALUE 'BCDEFGHIJKLMNOPQRSTU'.
DATA l_col TYPE zexcel_cell_column_alpha.
data i type i.
" Creates active sheet
CREATE OBJECT lo_excel.
" Get active sheet
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet->set_title( ip_title = 'Abgrenzung').
ls_table_settings-table_style = zcl_excel_table=>builtinstyle_medium2.
ls_table_settings-show_row_stripes = abap_true.
lo_worksheet->bind_table( ip_table = it_excel[]
is_table_settings = ls_table_settings ).
lo_worksheet->freeze_panes( ip_num_rows = 3 ). "freeze column headers when scrolling
* OPTIMIZE COLUMNS
DO 20 TIMES.
i = sy-index - 1.
l_col = c_col+i(1).
column_dimension = lo_worksheet->get_column_dimension( ip_column = l_col ). "make date field a bit wider
column_dimension->set_auto_size( ip_auto_size = abap_true ).
ENDDO.
* column_dimension->set_width( ip_width = 11 ).
" Write to Excel 2007
CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
lv_file = lo_excel_writer->write_file( lo_excel ).
" Convert to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_file
IMPORTING
output_length = lv_bytecount
TABLES
binary_tab = lt_file_tab.
* " This method is only available on AS ABAP > 6.40
* lt_file_tab = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_file ).
* lv_bytecount = xstrlen( lv_file ).
" Save the file
cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount
filename = i_fullpath
filetype = 'BIN'
CHANGING data_tab = lt_file_tab ).
ENDFORM. "save_excel
lo_worksheet->bind_table( ip_table = it_excel[]
is_table_settings = ls_table_settings ).
so zum Beispiel.
:
:
cl_gui_frontend_services=>file_save_dialog(
EXPORTING initial_directory = 'C:\'
default_file_name = 'Abgrenzung'
default_extension = 'XLSX'
CHANGING filename = lv_filename
path = lv_path
fullpath = lv_fullpath
user_action = lv_user_action ).
IF sy-subrc <> 0 OR lv_user_action <> cl_gui_frontend_services=>action_ok.
WRITE: / 'Verarbeitung wurde abgebrochen!!!!'.
EXIT.
ENDIF.
** Daten mittels Trennzeichen zusammenfügen und Download CSV-File
* LOOP AT it_excel INTO ls_excel.
* MOVE-CORRESPONDING ls_excel TO lv_data.
* CONCATENATE ls_excel-bukrs ls_excel-budat ls_excel-kstar
* ls_excel-name ls_excel-objnr ls_excel-meinh
* lv_data-pramevm lv_data-prawevm lv_data-istmemon
* lv_data-istwemon lv_data-istmiprame lv_data-istmiprawe
* lv_data-budmevm lv_data-budwevm lv_data-abwme
* lv_data-abwwe lv_data-abgrme lv_data-abgrwe
* lv_data-istmevm lv_data-istwevm
* INTO gs_file SEPARATED BY ';'.
* APPEND gs_file TO gt_file.
* ENDLOOP.
PERFORM save_excel TABLES it_excel USING lv_fullpath.
:
: