*&---------------------------------------------------------------------* *& Report Z_TOOLBOX_2_WORD *& *&---------------------------------------------------------------------* *& Frame programme for calling the Toolbox-XML-to-Word-XML *& XSLT stylesheet. The programme is written with SAP NetWeaver 2004s. *& *& Copyright (C) 2006 Jan Krohn *& *& This program is free software; you can redistribute it and/or *& modify it under the terms of the GNU General Public License as *& published by the Free Software Foundation; version 2 of the *& License. *& *& This program is distributed in the hope that it will be useful, *& but WITHOUT ANY WARRANTY; without even the implied warranty of *& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *& GNU General Public License for more details. *& *& You should have received a copy of the GNU General Public License *& along with this program; if not, write to the Free Software *& Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *& MA 02110-1301 USA. *& *& Contact: Jan Krohn, Haidstraße 54, 63741 Aschaffenburg, Germany *& webmaster@vic-fontaine.com; phone: 0049-6021-1304099-0 *&---------------------------------------------------------------------* REPORT z_toolbox_2_word. *======================================================================* * SELECTION SCREEN * *======================================================================* * 'Please choose source and destination file names' SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001. PARAMETERS: pv_fin TYPE filename, pv_fout TYPE filename. SELECTION-SCREEN END OF BLOCK a. *======================================================================* * MAIN PROGRAMME * *======================================================================* START-OF-SELECTION. DATA: ls_fin TYPE string, ls_fout TYPE string, lt_data_tab_in TYPE STANDARD TABLE OF x255, lt_data_tab_out TYPE STANDARD TABLE OF x255, lv_lraw TYPE x255, ls_errtext TYPE string, lv_err TYPE REF TO cx_transformation_error, ls_xml_in TYPE xstring, ls_xml_out TYPE xstring, lv_xlen TYPE i, lv_count TYPE i, lv_off TYPE i, lv_mod TYPE i. * Both file names must not be initial CHECK pv_fin IS NOT INITIAL AND pv_fout IS NOT INITIAL. ls_fin = pv_fin. ls_fout = pv_fout. * Open file from client PC CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = ls_fin filetype = 'BIN' CHANGING data_tab = lt_data_tab_in 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. * Check for errors IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno. ENDIF. * Write XML from table to string CLEAR ls_xml_in. LOOP AT lt_data_tab_in INTO lv_lraw. CONCATENATE ls_xml_in lv_lraw INTO ls_xml_in IN BYTE MODE. ENDLOOP. "lt_data_tab_in * Perform XSLT TRY. CALL TRANSFORMATION z_make_wml PARAMETERS title = 'Adele - English' subtitle = 'Dictionary' author = 'GILLBT' language = 'EN' " EN for English, FR for French... utf8_font = 'Arial Unicode MS' SOURCE XML ls_xml_in RESULT XML ls_xml_out. CATCH cx_transformation_error INTO lv_err. ls_errtext = lv_err->get_text( ). MESSAGE ls_errtext TYPE 'E'. ENDTRY. * Write XML from string to table REFRESH lt_data_tab_out. CLEAR lv_off. lv_xlen = XSTRLEN( ls_xml_out ). lv_count = lv_xlen DIV 255. DO lv_count TIMES. lv_lraw = ls_xml_out+lv_off(255). lv_off = lv_off + 255. APPEND lv_lraw TO lt_data_tab_out. ENDDO. lv_mod = lv_xlen MOD 255. IF lv_mod > 0. lv_lraw = ls_xml_out+lv_off(lv_mod). APPEND lv_lraw TO lt_data_tab_out. ENDIF. * Write file to client PC CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING bin_filesize = lv_xlen filename = ls_fout filetype = 'BIN' confirm_overwrite = 'X' CHANGING data_tab = lt_data_tab_out 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. * Check for errors IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno. ENDIF. *======================================================================* * VALUE REQUESTS FOR SELECTION SCREEN * *======================================================================* * When the source file is requested AT SELECTION-SCREEN ON VALUE-REQUEST FOR pv_fin. DATA: lt_filetable TYPE filetable, lv_rc TYPE i, lv_ua TYPE i. *Dialogue box: open file CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING window_title = 'Toolbox XML file to be loaded' default_extension = 'xml' file_filter = cl_gui_frontend_services=>filetype_xml initial_directory = 'C:\' CHANGING file_table = lt_filetable rc = lv_rc user_action = lv_ua EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. * Check for errors IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno. ENDIF. CHECK lv_rc = 1 AND lv_ua = cl_gui_frontend_services=>action_ok AND lt_filetable IS NOT INITIAL. * Assign selected file to parameter READ TABLE lt_filetable INTO pv_fin INDEX 1. * When the destination file is requested AT SELECTION-SCREEN ON VALUE-REQUEST FOR pv_fout. DATA: ls_filename TYPE string, ls_path TYPE string, ls_fullpath TYPE string, lv_ua TYPE i. * Dialogue box: save file CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING window_title = 'WordXML file to be saved' default_extension = 'xml' file_filter = cl_gui_frontend_services=>filetype_xml initial_directory = 'C:\' CHANGING filename = ls_filename path = ls_path fullpath = ls_fullpath user_action = lv_ua EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. * Check for errors IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno. ENDIF. CHECK lv_ua = cl_gui_frontend_services=>action_ok AND ls_fullpath IS NOT INITIAL. * Assign selected file to parameter pv_fout = ls_fullpath.