METHOD download_file. DATA: lv_control TYPE REF TO i_oi_container_control, lv_container TYPE REF TO cl_gui_custom_container, lv_document TYPE REF TO i_oi_document_proxy, lv_spreadsheet TYPE REF TO i_oi_spreadsheet, lv_error TYPE REF TO i_oi_error, lv_structdescr TYPE REF TO cl_abap_structdescr, lv_elemdescr TYPE REF TO cl_abap_elemdescr, lv_outputs TYPE STANDARD TABLE OF typ_output, lv_output TYPE typ_output, lv_components TYPE abap_component_tab, lv_component TYPE abap_componentdescr, lv_fields TYPE soi_fields_table, lv_field TYPE rfc_fields, lv_offset TYPE ioff, lv_rows TYPE i, lv_file(1000). TRY. *Create instance control CALL METHOD c_oi_container_control_creator=>get_container_control IMPORTING control = lv_control error = lv_error. *Create container CREATE OBJECT lv_container EXPORTING container_name = 'CONTAINER'. *Call init_control CALL METHOD lv_control->init_control EXPORTING r3_application_name = 'AR supplier items' inplace_enabled = abap_true parent = lv_container. *Create document object CALL METHOD lv_control->get_document_proxy EXPORTING document_type = 'Excel.Sheet' IMPORTING document_proxy = lv_document error = lv_error. *Open input file CONCATENATE 'FILE://' pt_upd INTO lv_file. CALL METHOD lv_document->open_document EXPORTING document_url = lv_file open_readonly = abap_true open_inplace = abap_true IMPORTING error = lv_error. *Duplicate the input file CONCATENATE 'FILE://' pt_dwd INTO lv_file. CALL METHOD lv_document->save_copy_as EXPORTING file_name = lv_file no_flush = abap_false IMPORTING error = lv_error. *Close input file CALL METHOD lv_document->close_document EXPORTING do_save = abap_false no_flush = abap_false IMPORTING error = lv_error. CALL METHOD lv_document->release_document EXPORTING no_flush = abap_false IMPORTING error = lv_error. *Open download file CALL METHOD lv_document->open_document EXPORTING document_url = lv_file open_inplace = abap_true IMPORTING error = lv_error. *Get spreadsheet CALL METHOD lv_document->get_spreadsheet_interface EXPORTING no_flush = abap_true IMPORTING sheet_interface = lv_spreadsheet. SORT lv_items BY cust_po sequence. LOOP AT lv_items INTO lv_item. MOVE-CORRESPONDING lv_item TO lv_output. APPEND lv_output TO lv_outputs. ENDLOOP. *Populate fields table for method INSERT_ONE_TABLE CALL FUNCTION 'DP_GET_FIELDS_FROM_TABLE' TABLES data = lv_outputs fields = lv_fields EXCEPTIONS dp_invalid_table = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *Create Range for entering data *Set cursor position DESCRIBE TABLE lv_outputs LINES lv_rows. CALL METHOD lv_spreadsheet->insert_range_dim EXPORTING name = 'RANGE1' top = 4 left = 1 columns = 30 rows = lv_rows IMPORTING error = lv_error. *Clear range data CALL METHOD lv_spreadsheet->clear_range EXPORTING name = 'RANGE1' IMPORTING error = lv_error. CALL METHOD lv_spreadsheet->insert_one_table EXPORTING data_table = lv_outputs fields_table = lv_fields rangename = 'RANGE1' wholetable = abap_true IMPORTING error = lv_error. *Save file CALL METHOD lv_document->save_as EXPORTING file_name = lv_file IMPORTING error = lv_error. *Close download file CALL METHOD lv_document->close_document EXPORTING do_save = abap_true no_flush = abap_false IMPORTING error = lv_error. CALL METHOD lv_document->release_document EXPORTING no_flush = abap_false IMPORTING error = lv_error. FREE lv_document. CATCH cx_root. ENDTRY. ENDMETHOD