*&---------------------------------------------------------------------* *& Report /EUTIN/DEMO_EXCEL *&---------------------------------------------------------------------* *& *& Content of the simple transformatio /EUTIN/ITAB_XML_EXCEL: *& *& *& *& *& *& *& *& *& *& *& EUTIN *& EUTIN *& 2019-09-29T17:32:00Z *& *& 11.8132 *& *& *& *& 12660 *& 19980 *& 480 *& 120 *& False *& False *& *& *& *& *& *& *& *& *& *& *& *& *& *& *& Material No *& *& *& Material Desc *& *& *& *& *& *& *& *& *& *& *& *& *& *& *& *& *&
*& *& *& *& *& *& 3 *& 4 *& 1 *& *& *& False *& False *& *& *&
*& *& *& False *& False *& *& *& *& *& *& False *& False *& *& *&
*& *&
* *&
*&---------------------------------------------------------------------* REPORT /eutin/demo_excel. TYPES: BEGIN OF ts_mara, matnr TYPE matnr, maktx TYPE char30, END OF ts_mara. START-OF-SELECTION. PERFORM main. *&---------------------------------------------------------------------* *& Form MAIN *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* FORM main. DATA: lx_root TYPE REF TO cx_root, lt_mara TYPE STANDARD TABLE OF ts_mara WITH DEFAULT KEY, lt_xml TYPE STANDARD TABLE OF string WITH DEFAULT KEY, ls_mara LIKE LINE OF lt_mara, lv_xmlstr TYPE string, lv_title TYPE string, lv_fullpath TYPE string, lv_path TYPE string, lv_user_action TYPE i, lv_default_extension TYPE string, lv_default_file_name TYPE string, lv_file_filter TYPE string, lv_filename TYPE string, lv_initialpath TYPE string, lv_message TYPE string. CLEAR: lt_mara[], lt_xml[], ls_mara. *--- create demo data ls_mara-matnr = 'TEST1'. ls_mara-maktx = 'Test description'. INSERT ls_mara INTO TABLE lt_mara. IF sy-subrc NE 0. MESSAGE 'INSERT into LT_MARA failed' TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDIF. ls_mara-matnr = 'TEST2'. ls_mara-maktx = 'Test description 2'. INSERT ls_mara INTO TABLE lt_mara. IF sy-subrc NE 0. MESSAGE 'INSERT into LT_MARA failed' TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDIF. *--- convert into XML structure usable for Microsoft Excel TRY. CLEAR lv_xmlstr. CALL TRANSFORMATION /eutin/itab_xml_excel SOURCE table = lt_mara[] RESULT XML lv_xmlstr. IF lv_xmlstr IS INITIAL. RETURN. ENDIF. 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 'XML transformation failed' TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDTRY. *--- prepare download INSERT lv_xmlstr INTO TABLE lt_xml. IF sy-subrc NE 0. MESSAGE 'INSERT into LT_XML failed' TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDIF. *--- get file name lv_default_extension = '.xls'. lv_file_filter = 'XLS files (*.xls)|*.xls'. CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING default_extension = lv_default_extension default_file_name = lv_default_file_name file_filter = lv_file_filter initial_directory = lv_initialpath CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_user_action EXCEPTIONS cntl_error = 1 error_no_gui = 2 OTHERS = 3. IF sy-subrc EQ 0 AND lv_fullpath IS NOT INITIAL. *--- download file CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = lv_fullpath filetype = 'ASC' TABLES data_tab = lt_xml[] EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 OTHERS = 5. IF sy-subrc NE 0. MESSAGE 'Download failed' TYPE 'I' DISPLAY LIKE 'E'. RETURN. ENDIF. ENDIF. ENDFORM. *--- The End!